PDFium VCL API Reference
TPdf Component Methods
Document Management
| Method | Description |
CreateDocument | Create a new empty PDF document |
LoadDocument(Data: TMemoryStream; Buffered: Boolean = True) | Load PDF document from memory stream |
LoadDocument(Data: Pointer; Size: Integer; Buffered: Boolean = True) | Load PDF document from memory buffer |
LoadDocument | Load PDF document from FileName |
LoadDocument(const Data: TBytes; Buffered: Boolean = True) | Load PDF document from TBytes |
SaveAs(Stream: TStream; Option: TSaveOption = saNone; PdfVersion: TPdfVersion = pvUnknown): Boolean | Save document to stream. When Compressed is True, ensures all streams are FlateDecode compressed. |
SaveAs(const FileName: string; Option: TSaveOption = saNone; PdfVersion: TPdfVersion = pvUnknown): Boolean | Save document to file |
ImportPages(Pdf: TPdf; const Range: string; PageNumber: Integer = 1): Boolean | Import pages from another PDF document. Range format: '1,3,5-7' |
ImportPreferences(Pdf: TPdf): Boolean | Import viewer preferences from another PDF |
Page Operations
| Method | Description |
AddPage(PageNumber: Integer; Width, Height: Double) | Add a new page at the specified position with given dimensions (in points, 72 points = 1 inch) |
DeletePage(PageNumber: Integer) | Delete page at specified index |
ReloadPage | Reload the current page |
UpdatePage | Apply pending changes to the current page (calls FPDFPage_GenerateContent) |
Text Operations
| Method | Description |
Text(StartIndex: Integer = 0; Count: Integer = MaxInt): WString | Extract text from current page |
TextInRectangle(Left, Top, Right, Bottom: Double): WString | Extract text from rectangular area (page coordinates) |
TextInRectangle(Rectangle: TPdfRectangle): WString | Extract text from rectangle |
AddText(const Text, Font: WString; FontSize: Single; X, Y: Double; Color: TColor = clBlack; Alpha: Byte = $FF; Angle: Double = 0.0) | Add text at specified position with font, color, transparency, and rotation angle |
SetText(ObjectIndex: Integer; const Text: WString) | Set text for an existing text object (undocumented PDFium API, may cause formatting issues) |
FindFirst(const Text: WString; Options: TSearchOptions = []; StartIndex: Integer = 0; DirectionUp: Boolean = True): Integer | Start text search, returns character index or -1 if not found |
FindNext: Integer | Continue text search forward, returns character index or -1 |
FindPrevious: Integer | Continue text search backward, returns character index or -1 |
CharacterIndexAtPos(X, Y, ToleranceX, ToleranceY: Double): Integer | Get character index at page position |
RectangleCount(StartIndex: Integer = 0; Count: Integer = MaxInt): Integer | Get the number of text rectangles for a character range |
Annotation Operations
| Method | Description |
CreateAnnotation(const Annotation: TPdfAnnotation) | Create a new annotation on the current page |
DeleteAnnotation(Index: Integer) | Delete annotation at index |
Form Flattening
| Method | Description |
GenerateFormAppearances | Regenerates /AP appearance streams for every form widget on every page (FPDF_FFLDraw). Call after FormField[] assignments and before SaveAs / FlattenPage / FlattenAllPages. |
FlattenPage(nFlag: Integer = FLAT_NORMALDISPLAY): Integer | Flatten annotations and form widgets on the current page into static content. Returns FLATTEN_SUCCESS, FLATTEN_NOTHINGTODO, or FLATTEN_FAIL. |
FlattenAllPages(nFlag: Integer = FLAT_NORMALDISPLAY): Boolean | Flatten every page in the document. Returns True when all pages succeed. |
Attachment Operations
| Method | Description |
CreateAttachment(const Name: WString): Boolean | Create a new empty attachment |
DeleteAttachment(Index: Integer): Boolean | Delete attachment at index |
Image Operations
| Method | Description |
AddJpegImage(JpegImage: TStream; X, Y, Width, Height: Double): Boolean | Add JPEG image from stream at specified position and size |
AddPicture(Picture: TPicture; X, Y: Double) | Add picture at position (original size) |
AddPicture(Picture: TPicture; X, Y, Width, Height: Double) | Add picture at position with specified size |
Drawing Operations
| Method | Description |
CreatePath(X, Y: Single; FillMode; FillColor; FillAlpha; Stroke; StrokeColor; StrokeAlpha; StrokeWidth; LineCap; LineJoin; BlendMode) | Create a path starting at position (X, Y) |
CreatePath(X, Y, Width, Height: Single; ...) | Create a rectangular path with given bounds |
MoveTo(X, Y: Single) | Move the current point to (X, Y) |
LineTo(X, Y: Single) | Draw a line from the current point to (X, Y) |
BezierTo(X1, Y1, X2, Y2, X3, Y3: Single) | Draw a Bezier curve with two control points and an endpoint |
ClosePath | Close the current subpath |
AddPath | Add the completed path to the current page |
Rendering
| Method | Description |
RenderPage(DeviceContext: HDC; Left, Top, Width, Height: Integer; Rotation; Options) | Render page to a device context (HDC) |
RenderPage(Left, Top, Width, Height: Integer; Rotation; Options; Color): TBitmap | Render page to a new bitmap |
RenderPage(Bitmap: TBitmap; Left, Top, Width, Height: Integer; Rotation; Options; Color) | Render page to an existing bitmap |
RenderTile(Left, Top, Width, Height, PageWidth, PageHeight: Integer; ...): TBitmap | Render a tile (portion) of a page to a new bitmap |
RenderTile(Bitmap: TBitmap; Left, Top, Width, Height, PageWidth, PageHeight: Integer; ...) | Render a tile to an existing bitmap |
Coordinate Conversion
| Method | Description |
DeviceToPage(X, Y, Left, Top, Width, Height: Integer; Rotation: TRotation; out PageX, PageY: Double): Boolean | Convert device coordinates to page coordinates |
PageToDevice(PageX, PageY: Double; Left, Top, Width, Height: Integer; Rotation: TRotation; out X, Y: Integer): Boolean | Convert page coordinates to device coordinates |
TPdf Component Properties
Published Properties (Design-Time)
| Property | Type | Description |
About | string | Component version information (stored False) |
Active | Boolean | Set to True to load/activate the document, False to close it |
FileName | string | Path to the PDF file to load |
FormFill | Boolean | Enable interactive form filling with JavaScript support (default True) |
PageNumber | Integer | Current page number (1-based, 0 when no document is loaded) |
Password | string | Password for opening encrypted PDF documents |
Document Properties
| Property | Type | R/W | Description |
Author | WString | R | Document author |
Compressed | Boolean | R/W | When True (default), SaveAs post-processes the output to ensure all streams are FlateDecode compressed |
CreationDate | WString | R | Document creation date metadata |
Creator | WString | R | Application that created the document |
Document | FPDF_DOCUMENT | R | Low-level PDFium document handle |
FormType | TPdfFormType | R | Form type: ftNone, ftAcroForm, ftXFAFull, ftXFAForeground |
IsTagged | Boolean | R | True if document is a tagged PDF |
Keywords | WString | R | Document keywords |
MetaText[const Tag: string] | WString | R | Arbitrary metadata value by tag name |
ModifiedDate | WString | R | Last modification date metadata |
PageCount | Integer | R | Total number of pages |
PdfVersion | TPdfVersion | R | PDF version (pv10 through pv17) |
Permissions | LongWord | R | Document permissions flags |
PrintCopies | Integer | R | Number of print copies specified |
PrintPaperHandling | TPrintPaperHandling | R | Paper handling preference |
PrintScaling | Boolean | R | Whether print scaling is enabled |
Producer | WString | R | PDF producer application |
Subject | WString | R | Document subject |
Title | WString | R | Document title |
UserPermissions | LongWord | R | User-level permissions |
ViewerPreference[const Key: string] | WString | R | Viewer preference value by key |
XFA | Boolean | R | True if document contains XFA forms |
Page Properties
| Property | Type | R/W | Description |
Page | FPDF_PAGE | R | Low-level PDFium page handle |
PageBounds | TPdfRectangle | R | Bounding rectangle of the current page |
PageHeight | Double | R | Height of current page in points |
PageLabel[PageNumber: Integer] | WString | R | Page label for a given page number |
PageMode | TPageMode | R | How the document should be displayed when opened |
PageRotation | TRotation | R/W | Rotation of the current page (ro0, ro90, ro180, ro270) |
PageWidth | Double | R | Width of current page in points |
Thumbnail | TBitmap | R | Thumbnail bitmap of the current page |
Transparent | Boolean | R | True if the current page contains transparent content |
Text and Character Properties
| Property | Type | Description |
Character[Index] | WideChar | Unicode character at index |
CharacterAngle[Index] | Single | Character rotation angle in radians |
CharacterCount | Integer | Number of characters on current page |
CharacterFontSize[Index] | Double | Font size of character at index; FontSize[Index] remains as a compatible alias |
CharacterFontWeight[Index] | Integer | Font weight of character at index |
CharacterGenerated[Index] | Boolean | True if character was generated (not from original content) |
CharacterIsHyphen[Index] | Boolean | True if character is a hyphen |
CharacterMapError[Index] | Boolean | True if character has a mapping error |
CharacterOrigin[Index] | TPdfPoint | Origin point of the character |
CharacterRectangle[Index] | TPdfRectangle | Bounding rectangle of the character |
Charcode[Index] | WideChar | Character code at index |
Find | FPDF_SCHHANDLE | Low-level PDFium search handle |
Rectangle[Index] | TPdfRectangle | Text rectangle from last RectangleCount call |
TextPage | FPDF_TEXTPAGE | Low-level PDFium text page handle |
Font Properties
| Property | Type | Description |
FontAscent[Index; FontSize] | Single | Ascent of the font used by the text object at index |
FontBaseName[Index] | WString | Base font name for the text object at index |
FontData[Index] | TBytes | Raw font data for the text object at index |
FontDescent[Index; FontSize] | Single | Descent of the font used by the text object at index |
FontFamilyName[Index] | WString | Font family name for the text object at index |
FontHandle[Index] | FPDF_FONT | Low-level PDFium font handle for the text object at index |
FontIsEmbedded[Index] | Boolean | True if the text object's font is embedded in the PDF |
FontItalicAngle[Index] | Integer | Italic angle of the text object's font |
FontSize[Index] | Double | Backward-compatible alias for CharacterFontSize[Index] |
FontWeight[Index] | Integer | Font weight of the text object's font (e.g., 400 = normal, 700 = bold) |
Object Properties
| Property | Type | Description |
ObjectCount | Integer | Number of page objects |
ObjectType[Index] | TObjectType | Type: otUnknown, otText, otPath, otImage, otShading, otForm |
ObjectBounds[Index] | TPdfRectangle | Bounding rectangle of the object |
ObjectBitmap[Index] | TBitmap | Bitmap representation of the object |
ObjectHandle[Index] | Pointer | Low-level object handle |
ObjectTransparent[Index] | Boolean | True if object is transparent |
Image Properties
| Property | Type | Description |
Bitmap[Index] | TBitmap | Bitmap of page object at index |
BitmapCount | Integer | Number of bitmap objects on page |
Image[Index] | TPdfImage | Image data (Width, Height, Data) at index |
ImageCount | Integer | Number of images on page |
Annotation Properties
| Property | Type | R/W | Description |
Annotation[Index] | TPdfAnnotation | R/W | Get or set annotation at index |
AnnotationCount | Integer | R | Number of annotations on current page |
Form Properties
| Property | Type | R/W | Description |
FormField[Index] | WString | R/W | Form field value by index |
FormFieldAt[X, Y: Single] | WString | R/W | Form field value at page position |
FormFieldCount | Integer | R | Number of form fields on current page |
FormFieldInfo[Index] | TPdfFormFieldInfo | R | Form field information by index |
FormFieldInfoAt[X, Y: Single] | TPdfFormFieldInfo | R | Form field information at page position |
FormHandle | FPDF_FORMHANDLE | R | Low-level form fill handle |
HasFormFieldAt[X, Y: Single] | Boolean | R | True if a form field exists at the position |
Attachment Properties
| Property | Type | R/W | Description |
Attachment[Index] | TBytes | R/W | Attachment data by index |
AttachmentCount | Integer | R | Number of attachments |
AttachmentName[Index] | WString | R | Attachment filename by index |
Navigation Properties
| Property | Type | Description |
Bookmark[const Title: WString] | TBookmark | Find bookmark by title |
BookmarkChildren[const Bookmark: TBookmark] | TBookmarks | Child bookmarks of a bookmark |
BookmarkFrom[Handle: FPDF_BOOKMARK] | TBookmark | Bookmark data from a handle |
Bookmarks | TBookmarks | Top-level bookmarks array |
Destination[Index] | TDestination | Named destination by index |
DestinationByName[const Name: WString] | TDestination | Named destination by name |
DestinationCount | Integer | Number of named destinations |
HasBookmarkChildren[const Bookmark: TBookmark] | Boolean | True if bookmark has children |
LinkAnnotation[PageNumber, Index] | TLinkAnnotation | Link annotation on a given page |
LinkAnnotationCount[PageNumber] | Integer | Number of link annotations on a page |
WebLink[PageNumber, Index] | TWebLink | Web link (URL) on a given page |
WebLinkCount[PageNumber] | Integer | Number of web links on a page |
Digital Signature Properties
| Property | Type | Description |
Signature[Index] | TPdfSignature | Digital signature information at index |
SignatureCount | Integer | Number of digital signatures in the document |
TPdf Events
| Event | Type | Description |
OnFormFieldEnter | TPdfFormFieldEnterEvent | Fired when a form field is entered. Parameters: Sender: TObject; const Text: WString |
OnFormFieldExit | TNotifyEvent | Fired when focus leaves a form field |
OnPageChange | TNotifyEvent | Fired when the current page changes |
OnUnsupportedFeature | TPdfUnsupportedFeatureEvent | Fired when the PDF contains an unsupported feature |
TPdfView Component
TPdfView is a scrollable visual control for displaying and interacting with PDF documents. It requires a Pdf: TPdf reference.
Published Properties (Design-Time)
| Property | Type | Default | Description |
About | string | | Component version information |
Active | Boolean | False | Activate/deactivate the viewer |
CurrentCharIndex | Integer | 0 | Application-selected character index retained for compatibility |
DisplayMode | TPdfDisplayMode | dmSingleContinuous | Page display mode (dmSingleContinuous, dmTwoPageContinuous) |
Options | TRenderOptions | [reLcd] | Rendering options (LCD text, annotations, grayscale, etc.) |
PageNumber | Integer | 1 | Current page number (1-based) |
Pdf | TPdf | nil | Reference to the TPdf component |
Rotation | TRotation | ro0 | Display rotation (ro0, ro90, ro180, ro270) |
Zoom | Double | 1.0 | Zoom level (1.0 = 100%) |
TPdfView-Specific Public Properties
| Property | Type | Description |
ActualSizeZoom[PageNumber] | Double | Zoom value to display the page at its actual size |
Canvas | TCanvas | Canvas for custom drawing on the viewer |
CharacterAngle[Index] | Single | Character rotation angle in radians |
CharacterFontSize[Index] | Double | Font size of character at index; FontSize[Index] remains as a compatible alias |
CharacterFontWeight[Index] | Integer | Font weight of character at index |
FontAscent[Index; FontSize] | Single | Ascent of the font used by the text object at index |
FontBaseName[Index] | WString | Base font name for the text object at index |
FontData[Index] | TBytes | Raw font data for the text object at index |
FontDescent[Index; FontSize] | Single | Descent of the font used by the text object at index |
FontFamilyName[Index] | WString | Font family name for the text object at index |
FontHandle[Index] | FPDF_FONT | Low-level PDFium font handle for the text object at index |
FontIsEmbedded[Index] | Boolean | True if the text object's font is embedded in the PDF |
FontItalicAngle[Index] | Integer | Italic angle of the text object's font |
FontWeight[Index] | Integer | Font weight of the text object's font |
PageHeightZoom[PageNumber] | Double | Zoom value to fit the page height in the viewer |
PageWidthZoom[PageNumber] | Double | Zoom value to fit the page width in the viewer |
PageZoom[PageNumber] | Double | Zoom value to fit the entire page in the viewer |
WindowHandle | HWND | Window handle of the viewer control |
TPdfView-Specific Methods
| Method | Description |
DeviceToPage(X, Y: Integer; out PageX, PageY: Double): Boolean | Convert screen coordinates to page coordinates |
DeviceToPage(X, Y: Integer; var PageNumber: Integer; var PageX, PageY: Double): Boolean | Convert screen coordinates to page coordinates with page detection |
DeviceToPage(Rectangle: TRect): TPdfRectangle | Convert screen rectangle to page rectangle |
PageToDevice(PageX, PageY: Double; out X, Y: Integer): Boolean | Convert page coordinates to screen coordinates |
PageToDevice(Rectangle: TPdfRectangle): TRect | Convert page rectangle to screen rectangle |
LinkAnnotationAtPos(X, Y: Integer): Integer | Get link annotation index at screen position |
LinkAnnotationAtPos(X, Y: Integer; out PageNumber: Integer): Integer | Get link annotation index with page number |
WebLinkAtPos(X, Y: Integer): Integer | Get web link index at screen position |
WebLinkAtPos(X, Y: Integer; out PageNumber: Integer): Integer | Get web link index with page number |
PaintSelection(SelectionStart, SelectionEnd: Integer; Mask: TColor) | Paint text selection highlight |
GenerateFormAppearances | Regenerates /AP appearance streams via the associated TPdf component (see TPdf.GenerateFormAppearances) |
FlattenPage(nFlag: Integer = FLAT_NORMALDISPLAY): Integer | Flatten annotations and form widgets on the current page into static content |
TPdfView Events
| Event | Type | Description |
OnPageChange | TNotifyEvent | Fired when the displayed page changes during scrolling |
OnPageNumberChanged | TNotifyEvent | Fired when the PageNumber property is modified |
OnPaint | TNotifyEvent | Fired during custom painting operations |
Data Types and Enumerations
Core Types
| Type | Definition |
WString | Wide string type for Unicode text |
TPdfPoint | Record: X, Y: Double |
TPdfRectangle | Record: Left, Top, Right, Bottom: Double |
TPdfVersion | pvUnknown, pv10, pv11, pv12, pv13, pv14, pv15, pv16, pv17 |
TRotation | ro0, ro90, ro180, ro270 |
TSaveOption | saNone, saIncremental, saNoIncremental, saRemoveSecurity |
TObjectType | otUnknown, otText, otPath, otImage, otShading, otForm |
TPageMode | pmNone, pmOutline, pmThumbs, pmFullScreen, pmOptionalContentGroup, pmAttachments, pmUnknown |
TPdfAction | acUnsupported, acGoto, acGotoRemote, acUri, acLaunch |
TPdfDisplayMode | dmSingleContinuous, dmTwoPageContinuous |
Search and Render Options
| Type | Values |
TSearchOption | seCaseSensitive, seWholeWord, seConsecutive |
TSearchOptions | Set of TSearchOption |
TRenderOption | reAnnotations, reLcd, reNoNativeText, reGrayscale, reDebugInfo, reNoCatchException, reLimitCache, reHalftone, rePrinting, reReverseByteOrder, reNoSmoothText, reNoSmoothImage, reNoSmoothPath |
TRenderOptions | Set of TRenderOption |
Drawing Types
| Type | Values |
TPdfFillMode | fmNone, fmAlternate, fmWinding |
TPdfLineCap | lcDefault, lcButt, lcRound, lcProjectingSquare |
TPdfLineJoin | ljDefault, ljMiter, ljRound, ljBevel |
TPdfBlendMode | bmDefault, bmMultiply, bmScreen, bmOverlay, bmDarken, bmLighten, bmColorDodge, bmColorBurn, bmHardLight, bmSoftLight, bmDifference, bmExclusion, bmHue, bmSaturation, bmColor, bmLuminosity |
Annotation Types
| Type | Description |
TPdfAnnotationSubtype | Annotation subtypes: Text, Link, FreeText, Line, Square, Circle, Polygon, PolyLine, Highlight, Underline, Squiggly, StrikeOut, Stamp, Caret, Ink, Popup, FileAttachment, Sound, Movie, Widget, Screen, PrinterMark, TrapNet, Watermark, 3D, RichMedia, XFAWidget |
TPdfAnnotationFlag | Flags: afInvisible, afHidden, afPrint, afNoZoom, afNoRotate, afNoView, afReadOnly, afLocked, afToggleNoView |
TPdfAnnotation | Record containing Subtype, Flags, Color, InteriorColor, Contents, Rectangle, and other properties |
Form Types
| Type | Description |
TPdfFormType | ftUnknown, ftNone, ftAcroForm, ftXfaFull, ftXfaForeground |
TPdfFormFieldType | fiUnknown, fiPushButton, fiCheckBox, fiRadioButton, fiComboBox, fiListBox, fiTextField, fiSignature |
TPdfFormFieldFlag | ffReadOnly, ffRequired, ffNoExport, and type-specific flags |
TPdfFormFieldInfo | Record containing FieldType, Flags, Name, Value, AlternateName, and other properties |
Record Types
| Type | Fields |
TBookmark | Handle, Title, PageNumber, Action, ActionPageNumber |
TDestination | Handle, Name, PageNumber, HasX, X, HasY, Y, HasZoom, Zoom |
TLinkAnnotation | Handle, Rectangle, PageNumber, Action, ActionPageNumber, ActionPath, Points |
TWebLink | Url: WString, Rectangles: TPdfRectangles |
TPdfImage | Width: Integer, Height: Integer, Data: TBytes |
TPdfSignature | Content: TBytes, Encoding: WString, Reason: WString, Time: WString, Permission: Integer |
Global Functions
| Function | Description |
Loaded: Boolean | Returns True if the PDFium library (pdfium.dll) is loaded |
LoadLibrary | Manually load the PDFium library |
UnloadLibrary | Unload the PDFium library |
DecodeDate(const Value: string; out DateTime: TDateTime; out DateTimeOffset: Integer): Boolean | Parse PDF date string to TDateTime and UTC offset |
PointsToInches(Points: Double): Double | Convert PDF points to inches |
PointsToPixels(Points, PixelsPerInch: Double): Double | Convert PDF points to pixels |
PixelsToInches(Pixels, PixelsPerInch: Double): Double | Convert pixels to inches |
PixelsToPoints(Pixels, PixelsPerInch: Double): Double | Convert pixels to PDF points |
Global Variables
| Variable | Type | Default | Description |
LibraryName | string | 'pdfium.dll' | Name of the PDFium DLL to load |
EnableV8Engine | Boolean | False | Set to True before loading to enable V8 JavaScript engine support |
Common Usage Patterns
PDF Viewer Implementation
procedure TMainForm.OpenPDF(const FileName: string);
begin
Pdf.FileName := FileName;
Pdf.Active := True;
PdfView.Pdf := Pdf;
PdfView.Active := True;
StatusBar1.SimpleText := Format('Loaded: %s (%d pages)',
[ExtractFileName(FileName), Pdf.PageCount]);
end;
Create PDF with Compression
Pdf.CreateDocument;
Pdf.Compressed := True;
Pdf.Active := True;
Pdf.AddPage(0, 595, 842);
Pdf.AddText('Hello World!', 'Arial', 24, 100, 700, clBlack, $FF, 0.0);
Pdf.SaveAs('output.pdf');
Pdf.Active := False;
Text Extraction
Pdf.FileName := 'document.pdf';
Pdf.Active := True;
for I := 1 to Pdf.PageCount do
begin
Pdf.PageNumber := I;
Memo1.Lines.Add(Format('--- Page %d ---', [I]));
Memo1.Lines.Add(Pdf.Text);
end;
Pdf.Active := False;
Form Field Processing
Pdf.FileName := 'form.pdf';
Pdf.Active := True;
Pdf.PageNumber := 1;
for I := 0 to Pdf.FormFieldCount - 1 do
begin
FieldInfo := Pdf.FormFieldInfo[I];
case FieldInfo.FieldType of
fiTextField:
Pdf.FormField[I] := 'New Value';
fiCheckBox:
Pdf.FormField[I] := 'Yes';
end;
end;
Pdf.SaveAs('filled_form.pdf');
Pdf.Active := False;
Flatten a Filled Form
// Bake form values into permanent (non-editable) page content.
Pdf.FileName := 'form.pdf';
Pdf.Active := True;
Pdf.FormField[0] := 'John Smith';
Pdf.FormField[1] := 'Yes';
Pdf.GenerateFormAppearances; // step 1: refresh /AP from /V
Pdf.FlattenAllPages(FLAT_NORMALDISPLAY); // step 2: flatten all pages
Pdf.SaveAs('flattened.pdf'); // step 3: save
Pdf.Active := False;