Building a Feature-Rich PDF Viewer with PDFium VCL in Delphi

In this tutorial, we’ll explore how to create a professional PDF viewer application using PDFium VCL, a powerful Delphi component that wraps Google’s PDFium rendering engine. This demo showcases the core viewing capabilities that form the foundation of any PDF application.

Overview

The PDF Viewer demo demonstrates the essential functionality needed for viewing PDF documents in a Delphi application. It provides a complete, ready-to-use PDF viewing solution with features comparable to commercial PDF readers.

Key Features

  • Document Loading – Open PDF files with password protection support
  • Page Navigation – First, previous, next, last page buttons with keyboard shortcuts
  • Zoom Controls – Multiple zoom levels including fit-to-page and fit-to-width
  • Page Rotation – Rotate pages 90° left or right
  • Text Selection – Select and copy text from PDF documents
  • Bookmarks – Navigate using the document’s table of contents
  • Text Search – Find text within the document
  • Printing – Print documents with page range selection
  • Save As – Export the document to a new PDF file

PDFium DLL Requirements

Before running any PDFium VCL application, you must install the PDFium DLL files. The DLLs are located in the DLLs folder of the PDFium VCL package:

  • pdfium32.dll – 32-bit version (~5 MB)
  • pdfium64.dll – 64-bit version (~6 MB)
  • pdfium32v8.dll – 32-bit with V8 JavaScript engine (~23 MB)
  • pdfium64v8.dll – 64-bit with V8 JavaScript engine (~27 MB)

Installation: Run PDFiumVCL\DLLs\CopyDlls.bat as Administrator. This script automatically copies the appropriate DLLs to the Windows system directories:

Note: Use the standard DLLs (pdfium32.dll/pdfium64.dll) for most applications. The V8 versions are only needed if your PDFs contain JavaScript that requires execution.

Core Components

The demo uses two main PDFium VCL components:

TPdf Component

The TPdf component handles all PDF document operations including loading, saving, and accessing document properties like metadata, bookmarks, and page information.

TPdfView Component

The TPdfView component is a scrollable visual control that renders PDF pages with smooth scrolling, zoom support, and user interaction handling.

Loading a PDF Document

Opening a PDF file is straightforward:

Page Navigation

Implementing page navigation is simple with the PageNumber property:

Zoom Control

The TPdfView component offers flexible zoom options:

Page Rotation

Rotate pages using the Rotation property:

Displaying Document Information

Access document metadata through the TPdf component:

Working with Bookmarks

The demo populates a TreeView with the document’s bookmarks for easy navigation:

Render Options

Customize rendering with various options:

Conclusion

The PDF Viewer demo provides a solid foundation for building PDF viewing functionality into your Delphi applications. With PDFium VCL, you get access to the same PDF rendering engine used by Google Chrome, ensuring high-quality, accurate PDF display.

The component handles complex PDF features like annotations, form fields, and embedded fonts automatically, allowing you to focus on building your application’s unique features rather than low-level PDF parsing.

Download PDFium VCL from loslab.com to get started with PDF development in Delphi.