|
Loads an existing PDF file
Delphi syntax:
function LoadFromFile ( FileName: TFileName ): Integer;
function LoadFromFile ( FileName: TFileName; const Password: AnsiString ): Integer;
function LoadFromFile ( FileName: TFileName; AutoDecrypt: Boolean ): Integer;
C++ syntax:
int __fastcall LoadFromFile ( AnsiString FileName );
int __fastcall LoadFromFile ( AnsiString FileName, System::AnsiString Password );
int __fastcall LoadFromFile ( AnsiString FileName, bool AutoDecrypt );
Description
Call LoadFromFile to load an existing PDF file. Function LoadFromFile returns count of pages in the loaded file. A file in which no page can be found, such as an empty or non-PDF file, returns 0 or raises an exception. An encrypted file whose pages lie in encrypted object streams cannot produce usable page results without its valid password; use the password overload
Cross-reference stream configuration is read from its own dictionary keys, including PDF name escapes. A nested direct /Encrypt dictionary supplies security-handler parameters without overriding the outer stream /Length, /Filter, /W, /Index, or trailer references. This supports genuine AES-256 revision 6 documents with unfiltered xref streams and encrypted object streams
PNG predictor parameters in /DecodeParms also resolve escaped PDF names and reject duplicate semantic keys. The xref stream marker is located after the complete outer dictionary, so names, strings, and comments containing stream do not become payload boundaries. Reading consumes only the required line ending after the marker and preserves a whitespace-valued first payload byte
Local files at or above LocalFileMappingThreshold use bounded windowed memory mapping with a shared LRU window cache for parser reads and immutable lazy stream ranges. Configure the mapping geometry with LocalFileMappingWindowSize and LocalFileMappingCacheWindows; set the threshold to zero to retain the TFileStream path. Mapping failures fall back automatically. Smaller files, and every file when mapping is off or fails, are read through a 64 KB read buffer over the file stream
Use the password overload for supported RC4 and AES Standard encrypted PDFs. HotPDF validates the user or owner password, recovers the file key from bounded trailer, xref, document-ID, and encryption-dictionary ranges, decrypts loaded strings and streams in memory, clears the loaded encryption state, and lets SaveLoadedDocument write an unencrypted copy. Loading without a password captures the raw encryption object by its authoritative xref offset so a later DecryptLoadedDocument call can use exact binary security-handler values without reopening the file. Unsupported encryption revisions raise an exception. Bounded key recovery is available since HotPDF v2.489.0, and zero-reread delayed decryption is available since HotPDF v2.490.0
The AutoDecrypt overload opens documents the way viewers do. When AutoDecrypt is True and the document is encrypted with an empty user password, which is how documents that only restrict permissions are written, it is decrypted in memory exactly as the password overload would with an empty password, so its text can be extracted, rendered and exported; IsEncrypted is then False and a later SaveLoadedDocument writes an unencrypted copy. A document that needs a password, and an unencrypted one, loads as the plain overload loads it. Whether the empty password opens the document is checked first from the same bounded ranges, without loading the document twice. With AutoDecrypt False the overload is the plain one
When importing existing PDF objects, HotPDF decodes ISO 32000-1 PDF name #XX escape sequences before storing name values internally. Names such as /PANTONE#20216#20CVC, /lime#20Green, and /The_Key_of_F#23_Minor are preserved as their intended byte values when the document is later copied or saved
See also: Windowed Local File Mapping، LoadFromStream، DecryptLoadedDocument
|