Skip to content

TTMSFNCWXPDFViewer

The TTMSFNCWXPDFViewer is a component to display PDF files in your applications, including page thumbnails. There is programmatic access to navigate through pages, search text and more. It uses the PDF.js JavaScript library.

Load a PDF

You can load a PDF through different methods:

To load from a URL, use TTMSFNCWXPDFViewer.LoadFromURL. Keep in mind that the PDF will be retrieved via an HTTP request in this case, so any URLs that are CORS protected won’t be able to load.

A PDF can be load as a base64 encoded string by using the TTMSFNCWXPDFViewer.LoadFromBase64 method.

For VCL, FMX and LCL there is also an extra method available which enables PDF loading directly from files.

procedure TForm1.Button1Click(Sender: TObject);
begin
 //From URL:
 TMSFNCWXPDFViewer1.LoadFromUrl('my/url');
 //From base64:
 TMSFNCWXPDFViewer1.LoadFromBase64('base64encodedfile');
 //From file (only VCL, FMX and LCL):
 TMSFNCWXPDFViewer1.LoadFromFile('path\to\pdf_file.pdf');
end;

Thumbnails

By default thumbnail generation is disabled. To enable this functionality, set the TTMSFNCWXPDFViewer.CalculateThumbnails property to True. After that, whenever a PDF is loaded, the thumbnails will be calculated. These thumbnails can be accessed by implementing the OnGenerateThumbnail event.

procedure TForm1.TMSFNCPDFViewer1GenerateThumbnail(Sender: TObject;
 NumPage: Integer; Base64Img: string);
var
 ms: TMemoryStream;
 b: TBytes;
 Base64DataImg: string;
begin
 Base64DataImg := Copy(Base64Img, Pos(',', Base64Img) + 1, 
Length(Base64Img));
 b := TTMSFNCUtils.Decode64ToBytes(Base64DataImg);
 ms := TMemoryStream.Create;
 try
 ms.Write(b, Length(b));
 ms.Position := 0;
 //Use your image here 
 //For example: load it into a bitmap from a stream
 finally
 ms.Free;
 end;
end;

Methods

Property name Description
NextPage Navigate to the next page.
PreviousPage Navigate to the previous page.
ShowPage(AIndex: Integer) Show a page with a given index.
ZoomIn Zoom into the PDF.
ZoomOut Zoom out of the PDF.
TurnAngleLeft Rotate the PDF to the left by 90 degrees.
TurnAngleRight Rotate the PDF to the right by 90 degrees. GenerateImageActualPage
Get the current page as an image. Search for a given text.

Events

Property name Description
OnLoaded Event triggers when the PDF has loaded.
OnPageLoaded Event triggers when the current page has loaded.
OnPageRendered Event triggers when the current page has been rendered.
OnLoadError Event triggers when an error happens during loading.
OnGenerateThumbnail Event triggers for each generated thumbnail.
OnGenerateImagePage Event triggers as a result of the GenerateImageActualPage method.
OnHyperlinkClick Event triggers when a hyperlink is clicked in the PDF.
OnThumbnailProgress Event triggers as the thumbnails are being loaded. The progress can be tracked here.
OnViewerInitialized Event triggers when the TTMSFNCWXPDFViewer is initialized.
OnFoundSearchText Event triggers for each match for the SearchText method.
OnNotFoundSearchText Event triggers when no search results were found for a given text.
OnSearchTextFinished Event triggers when the text search finished.