PDFium Component Docs

LoadDocument method

Component: TPdf  ·  Unit: PDFium
Open and load a PDF document from FileName

Syntax

procedure LoadDocument;

 

procedure LoadDocument(Data: Pointer; Size: Integer; Buffered: Boolean = True);

DataPointer. A pointer to the raw PDF data in memory
SizeInteger. The size of the data buffer in bytes
BufferedBoolean. When True (default), PDFium copies the data immediately. When False, the buffer must remain valid until the document is unloaded

 

procedure LoadDocument(const Data: TBytes; Buffered: Boolean = True);

DataTBytes. The PDF file content as a byte array
BufferedBoolean. When True (default), PDFium copies the data immediately. When False, the buffer must remain valid until the document is unloaded

 

procedure LoadDocument(Data: TMemoryStream; Buffered: Boolean = True);

DataTMemoryStream. A TMemoryStream containing the PDF data
BufferedBoolean. When True (default), PDFium copies the data immediately. When False, the buffer must remain valid until the document is unloaded

Description

Opens and loads a PDF into the component. The no-argument overload reads from the path stored in FileName. The Pointer, TBytes, and TMemoryStream overloads load directly from in-memory data, bypassing the file system

When Buffered is True (default), PDFium immediately copies the supplied data into its own buffer. When False, the caller's buffer must remain valid and unchanged until UnloadDocument or Active := False — this avoids an extra copy but requires careful lifetime management

On success, Active becomes True and all page properties reflect the first page (PageNumber = 1). On failure, an EPdfError exception is raised

Example

// From file
Pdf.FileName := 'C:\docs\file.pdf';
Pdf.LoadDocument;

// From TBytes
var Bytes: TBytes;
Bytes := TFile.ReadAllBytes('file.pdf');
Pdf.LoadDocument(Bytes);

// From TMemoryStream (unbuffered)
Pdf.LoadDocument(FStream, False);

See Also

Active, FileName, LoadCustomDocument, SaveAs