API referenceImport & Output APIs

pdfOpenImportFile

Open an existing PDF file as the instance's import source.

Exported namespdfOpenImportFileA (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.

C
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);
Delphi
function pdfOpenImportFileW(const IPDF: PPDF; const FileName: PWideChar;
  PwdType: Integer; const Password: PAnsiChar): Integer; stdcall; external 'LumasPdf.dll';

Parameters

ParameterTypeDescription
IPDFPPDFInstance handle.
FileNamestringPath of the PDF to open for import.
PwdTypeint32_tIgnored — the password is tried as user and owner password.
Passwordconst char*Open password (8-bit, may be NULL for unencrypted files). Note: 8-bit in the W variant too.

Return value0-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 alsopdfOpenImportBuffer, pdfImportPDFFile, pdfImportPage

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
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);
Area
Import & Output APIs
Category

Import

Exported names

pdfOpenImportFileA pdfOpenImportFileW

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.