PDFiumVCL Docs

Quick Start Guide

This guide will help you get started with PDFium VCL components in just a few minutes.

Step 1: Create a New Project

  1. Create a new VCL Forms Application in your IDE
  2. Save the project in a convenient location

Step 2: Add Components to Your Form

  1. Open the losLab component palette
  2. Drop a TPdf component onto your form
  3. Drop a TPdfView component onto your form
  4. Set the TPdfView's Pdf property to point to your TPdf component

Step 3: Load Your First PDF

Simple PDF Loading:

// Load a PDF file
Pdf1.FileName := 'C:\Sample.pdf';
Pdf1.Active := True;
ShowMessage('Pages: ' + IntToStr(Pdf1.PageCount));

// Or load from a memory stream
var
  Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  try
    Stream.LoadFromFile('C:\Sample.pdf');
    Pdf1.LoadDocument(Stream, True);
    Pdf1.Active := True;
  finally
    Stream.Free;
  end;
end;

Step 4: Basic PDF Operations

Navigate Pages

// Go to next page
if PdfView1.PageNumber < Pdf1.PageCount then
  PdfView1.PageNumber := PdfView1.PageNumber + 1;

// Go to previous page
if PdfView1.PageNumber > 1 then
  PdfView1.PageNumber := PdfView1.PageNumber - 1;

Extract Text

// Extract all text from the current page
Pdf1.PageNumber := 1;
Memo1.Text := Pdf1.Text;

// Extract text from a rectangular area
var
  RectText: WString;
begin
  RectText := Pdf1.TextInRectangle(100, 100, 500, 200);
  ShowMessage(RectText);
end;

Search Text

// Find text in the document
var
  Position: Integer;
begin
  Position := Pdf1.FindFirst('search term');
  if Position >= 0 then
    ShowMessage('Found at position: ' + IntToStr(Position))
  else
    ShowMessage('Not found');
end;

Create a New PDF

// Create a new PDF with text
Pdf1.CreateDocument;
Pdf1.Compressed := True; // enable stream compression
Pdf1.Active := True;
Pdf1.AddPage(0, 595, 842); // A4 size
Pdf1.AddText('Hello World!', 'Arial', 24, 100, 700, clBlack, $FF, 0.0);
Pdf1.SaveAs('C:\NewDocument.pdf');
Pdf1.Active := False;

Zoom and Display

// Set zoom level (1.0 = 100%)
PdfView1.Zoom := 1.5; // 150%

// Set display mode
PdfView1.DisplayMode := dmSingleContinuous;

// Rotate page
PdfView1.Rotation := ro90;

Step 5: Document Properties

// Read document metadata
ShowMessage('Title: ' + Pdf1.Title);
ShowMessage('Author: ' + Pdf1.Author);
ShowMessage('Creator: ' + Pdf1.Creator);
ShowMessage('Producer: ' + Pdf1.Producer);
ShowMessage('Pages: ' + IntToStr(Pdf1.PageCount));
ShowMessage('Version: ' + IntToStr(Ord(Pdf1.PdfVersion)));

Step 6: Password-Protected Documents

// Open a password-protected PDF
Pdf1.FileName := 'C:\Protected.pdf';
Pdf1.Password := 'mypassword';
Pdf1.Active := True;

Next Steps