PDF document in a report – using of new TfrxPDFView object

PDF document in a report – using of new TfrxPDFView object

First of all, FastReport VCL is a report generator. Based on this conclusion, we can assume that previewing or embedding documents of other formats into a report is excessive. But according to requests from our customers, we can see the opposite point of view. Many of our customers are solving tasks with the integration of new and old systems. Such an old system may contain already prepared documents that need to connect to the news reports. In other words – embed and view documents of third-party formats into a report adding new pages or fields to it.

For such tasks in FastReport VCL 2021.3, we have added the new report object - TfrxPDFView. This object uses the Open-source library Pdfium and is designed to view PDF documents in a report. You can build this library from the source code or use one ready-to-use from FastReport VCL installation package (frx_pdfium.dll and frx_pdfium_64.dll in Bin folder). After the manual build, you need to rename the library to frx_pdfium.dll for 32-bit system and to frx_pdfium_64.dll for 64-bit system. For the manual build, you need Visual Studio and Google depot_tools. More information can be found here and here.

As was written above you don’t need to build Pdfium, you can use prepared libraries from the FastReport VCL installation package, but if your company has a security limitation and requires building all code on your side use links from above.

The TfrxPDFView can draw documents both on one and several report pages. Using the ability of the report engine to split objects. Let’s check more closely how to use this object and what ability it provides.

After clear installation latest FastReport VCL 2021.3 version this component should appear on Delphi’s components palate in FastReport VCL section.

Adding TfrxPDFObject in the Embarcadero RAD Studio development environment

Just place the TfrxPDFObject on the application form, to use the TfrxPDFView at Run-time. If you started with a new project also add the TfrxReport component to a Form and with a double click on it call the report designer.

The report Designer

Then click on the PDF Object in the report designer objects panel and create a new object on the band in the report. Just like any other FastReport VCL object.

PDFView Object creation

The object was created. After that, the object editor should appear which allows loading a PDF document.

TfrxPDFView allows printing multi-page documents. Special for this TfrxPDFView has new properties.

DetailStretchMode property is responsible for displaying the content inside the container of the object and can be one of the following values:

The example of using DetailStretchMode property

Printing of multi-page PDF document

FastReport VCL allows printing PDF documents as one page of a PDF document onto one page of the report for each page of a PDF document.

We already created and load a PDF document on the Report Title band in the report. Let’s stretch it to the whole page of the report template page. It should look like the picture below.

Setting up of the report template

If we click on the report preview now, we will see only one page of the load PDF document even when a document has more than one page. To print all the pages, we need to perform a series of steps.

Let’s run the report preview and check the report output.

The report preview

FastReport VCL prints all pages of PDF document each on the report page.

The TfrxPDFView object has and other properties. The “Password” property sets a PDF document password. “DrawOptions” flags allow controlling document output.

DrawOptions settings

In addition, you can use a file name as a source for the TfrxPDFView object by using the FileLink property. And that’s not all! With the new DataLink property, it’s possible to load documents even through HTTP and HTTPS protocols.

Now FastReport VCL can print PDF documents inside a report and not only generate them!