Blog

All Blog Posts  |  Next Post  |  Previous Post

TMS Software Delphi  Components TMS Software Delphi  Components Advanced PDF actions in Delphi

Tuesday, March 25, 2025

TMS Software Delphi  Components

TMS VCL UI Pack has a lot of powerful components, both visual and non-visual. One of them is the TAdvPDFLib component. TAdvPDFLib is capable of generating PDF files in a Delphi VCL application. This blog covers more in depth code snippets to add navigation to your PDF document. To get started with TAdvPDFLib, read through this blog post first.


Go-To a specific page

go-to action changes the view to a specified destination (page, location, and magnification factor). With TAdvPDFLib we can add actions with the following code. The code will add a clickable link that can be used to navigate to a different page, and make sure the page is completely visible in the reader.

  1. uses  
  2.   AdvGraphicsTypes, Types;  
  3.   
  4. procedure TForm1.GeneratePDF;  
  5. begin  
  6.   AdvPDFLib1.BeginDocument('MyPDF.pdf');  
  7.   try  
  8.     AdvPDFLib1.NewPage;  
  9.   
  10.     AdvPDFLib1.Graphics.AddGoTo('Link''1 /Fit', RectF(5050150150));  
  11.   
  12.     AdvPDFLib1.NewPage;  
  13.   
  14.     AdvPDFLib1.Graphics.Fill.Color := gcYellowgreen;  
  15.     AdvPDFLib1.Graphics.Stroke.Color := gcGreen;  
  16.     AdvPDFLib1.Graphics.Stroke.Width := 4;  
  17.     AdvPDFLib1.Graphics.DrawRectangle(RectF(100100300300));  
  18.   
  19.   finally  
  20.     AdvPDFLib1.EndDocument(True);  
  21.   end;  
  22. end;  


TMS Software Delphi  Components


Go-To a specific rectangle

Let's say you have a part of the PDF that is requiring attention. It's possible to navigate to a specific rectangle in your page. To do this, use the following code.

  1. var  
  2.   l, r, t, b: Integer;  
  3. begin  
  4.   AdvPDFLib1.BeginDocument('MyPDF.pdf');  
  5.   try  
  6.     AdvPDFLib1.NewPage;  
  7.   
  8.     l := 100;  
  9.     t := 100;  
  10.     r := 300;  
  11.     b := 300;  
  12.   
  13.     AdvPDFLib1.Graphics.AddGoTo('Link'1'/FitR ' + l.ToString + ' ' + (AdvPDFLib1.PageHeight - t).ToString + ' ' +  
  14.       r.ToString + ' ' + (AdvPDFLib1.PageHeight - b).ToString, RectF(5050150150));  
  15.   
  16.     AdvPDFLib1.NewPage;  
  17.   
  18.     AdvPDFLib1.Graphics.Fill.Color := gcYellowgreen;  
  19.     AdvPDFLib1.Graphics.Stroke.Color := gcGreen;  
  20.     AdvPDFLib1.Graphics.Stroke.Width := 4;  
  21.     AdvPDFLib1.Graphics.DrawRectangle(RectF(l, t, r, b));  
  22.   
  23.   finally  
  24.     AdvPDFLib1.EndDocument(True);  
  25.   end;  
  26. end;  
Please note that the `AddGoTo` parameter list includes an overload that allows you to specify a page index as an integer and an options parameter as a string. Since PDF output uses a different coordinate system, we need to perform some calculations before passing the rectangle to the options parameter.

Go-To an URL

Go-To actions not only navigate within the document, it's also possible to include URLs in the PDF document. To do so, use the following code

  1. AdvPDFLib1.BeginDocument('MyPDF.pdf');  
  2. try  
  3.   AdvPDFLib1.NewPage;  
  4.   AdvPDFLib1.Graphics.AddURL('Link''https://www.tmssoftware.com', RectF(5050150150));  
  5. finally  
  6.   AdvPDFLib1.EndDocument(True);  
  7. end;  


Conclusion

TAdvPDFLib provides powerful functionality for working with PDFs in Delphi VCL applications. With features like the ability to add navigation actions such as go-to links, specific rectangles, and URLs, you can create interactive PDF documents. More info about actions and the possible optional parameters can be found here: https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf



Pieter Scheldeman




TMS Software Delphi  Components

This blog post has not received any comments yet.



Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post