ExtractFilePageContentToString
Extraction, Page properties
Description
Extracts the raw content stream of a specified page from an external PDF file and returns it as a string. This function uses the direct access backend, avoiding loading the entire document into memory, which is ideal for large files
Syntax
Delphi
Function TPDFlib.ExtractFilePageContentToString(Const InputFileName, Password: WideString; Page: Integer): AnsiString;ActiveX
Function PDFlib::ExtractFilePageContentToString(InputFileName As String, Password As String, Page As Long) As StringDLL
const char* DLExtractFilePageContentToString(int InstanceID, const wchar_t* InputFileName, const wchar_t* Password, int Page);
const char* DLExtractFilePageContentToStringA(int InstanceID, const char* InputFileName, const char* Password, int Page);Parameters
| InputFileName | The path to the source PDF file |
|---|---|
| Password | The password to open the file. Pass an empty string if the file is not protected |
| Page | The page number to extract (1-based) |
Return values
| Empty string | Failed to open file, invalid page, or extraction error |
|---|---|
| Content string | The raw PDF content stream of the page |
Remarks
The returned string contains raw PDF page description instructions (such as drawing and text positioning operators) and may include arbitrary binary bytes such as zero bytes inside inline images or encoded content; C and DLL callers should copy DLAnsiStringResultLength(InstanceID) bytes instead of relying on strlen. To extract human-readable text instead, use ExtractFilePageText
Example
var Content: AnsiString;
Content := PDF.ExtractFilePageContentToString('sample.pdf', '', 1);
if Content <> '' then
// Process the content instructions...