API referenceImport & Output APIs

pdfImportPDFFile

Import every page of the open import source in one call.

Exported namespdfImportPDFFile
NoteDestPage/scale parameters are ignored — see Remarks

Purpose — Import every page of the open import source in one call.

Description — For each source page: appends a new destination page sized to the source page's MediaBox (not the author default), imports the page as a form XObject, places it 1:1 at the origin, and closes the page. The author's default page size is restored afterwards, so subsequent pdfAppend calls are unaffected. Non-widget annotations come across when the ifAllAnnots import flag is set (default — see pdfSetImportFlags).

C
int32_t __stdcall pdfImportPDFFile(PPDF IPDF, uint32_t DestPage, double ScaleFactX, double ScaleFactY);
Delphi
function pdfImportPDFFile(const IPDF: PPDF; DestPage: Cardinal;
  ScaleFactX, ScaleFactY: Double): Integer; stdcall; external 'LumasPdf.dll';

Return value — Number of pages imported; 0 on failure (no import source open, or the source has no pages).

Remarks — In this engine DestPage, ScaleFactX, and ScaleFactY are accepted for ABI compatibility but ignored: pages are always appended after the current last page at natural size. Requires an open output document (pdfCreateNewPDF… first) and no open page.

Example — merge two PDFs (Delphi)

Delphi
var
  Pdf: PPDF;
begin
  Pdf := pdfNewPDF;
  try
    if not pdfCreateNewPDFW(Pdf, 'merged.pdf') then Abort;
    if pdfOpenImportFileW(Pdf, 'a.pdf', 0, nil) < 0 then Abort;
    if pdfImportPDFFile(Pdf, 1, 1.0, 1.0) = 0 then Abort;
    if pdfOpenImportFileW(Pdf, 'b.pdf', 0, nil) < 0 then Abort; // auto-closes a.pdf
    if pdfImportPDFFile(Pdf, 1, 1.0, 1.0) = 0 then Abort;
    if not pdfCloseFile(Pdf) then Abort;
  finally
    pdfDeletePDF(Pdf);
  end;
end;

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfImportPDFFile(IntPtr IPDF, uint DestPage, double ScaleFactX, double ScaleFactY);
Area
Import & Output APIs
Category

Import

Exported names

pdfImportPDFFile

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.