API reference › Import & Output APIs
pdfOpenImportFile
Open an existing PDF file as the instance's import source.
| Exported names | pdfOpenImportFileA (UTF-8), pdfOpenImportFileW (UTF-16 path) |
|---|
Purpose — Open an existing PDF file as the instance's import source.
Description — Closes any previous import source, then opens the file read-only (fmShareDenyWrite) and parses its xref/trailer. If the file is encrypted, the supplied password is applied — PwdType is ignored; the decryptor tries the password as both user and owner password. On success the source's pages, info dictionary, catalog, bookmarks, form fields, and structure tree become available to the pdfImport* family. The source file path is remembered for pdfReOpenImportFile.
int32_t __stdcall pdfOpenImportFileA(PPDF IPDF, const char* FileName, int32_t PwdType, const char* Password);
int32_t __stdcall pdfOpenImportFileW(PPDF IPDF, const wchar_t* FileName, int32_t PwdType, const char* Password);
function pdfOpenImportFileW(const IPDF: PPDF; const FileName: PWideChar;
PwdType: Integer; const Password: PAnsiChar): Integer; stdcall; external 'LumasPdf.dll';
Parameters
| Parameter | Type | Description |
|---|---|---|
IPDF | PPDF | Instance handle. |
FileName | string | Path of the PDF to open for import. |
PwdType | int32_t | Ignored — the password is tried as user and owner password. |
Password | const char* | Open password (8-bit, may be NULL for unencrypted files). Note: 8-bit in the W variant too. |
Return value — 0-based import-file handle: 0 on success, -1 on error (file missing, unreadable, not a valid PDF, or wrong password). This is *not* a boolean — a plain if (pdfOpenImportFile(...)) test is inverted.
Errors — logs Import file not found, Cannot open import file, or Import file is not a valid PDF to the instance error log (pdfGetErrLogMessageCount / pdfGetErrLogMessage).
See also — pdfOpenImportBuffer, pdfImportPDFFile, pdfImportPage
C# (P/Invoke)
public static extern int pdfOpenImportFileA(IntPtr IPDF, [MarshalAs(UnmanagedType.LPStr)] string FileName, int PwdType, [MarshalAs(UnmanagedType.LPStr)] string Password);
public static extern int pdfOpenImportFileW(IntPtr IPDF, [MarshalAs(UnmanagedType.LPWStr)] string FileName, int PwdType, [MarshalAs(UnmanagedType.LPStr)] string Password);
Import
pdfOpenImportFileA
pdfOpenImportFileW
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.