API referenceImport & Output APIs

pdfGetBuffer

Fetch the finished document bytes after an in-memory close.

Exported namespdfGetBuffer

Purpose — Fetch the finished document bytes after an in-memory close.

Description — Valid after pdfCreateNewPDFW(pdf, NULL)pdfCloseFile. Sets BufSize to the byte count and returns the instance-owned pointer to the PDF bytes. The buffer lives until the next document is opened on the instance or the instance is deleted — copy it out immediately. Passing a null BufSize reference returns NULL defensively.

C
const char* __stdcall pdfGetBuffer(PPDF IPDF, uint32_t* BufSize);
Delphi
function pdfGetBuffer(const IPDF: PPDF; var BufSize: Cardinal): PAnsiChar; stdcall; external 'LumasPdf.dll';

Example — in-memory generation (Delphi)

Delphi
var
  Pdf: PPDF; Size: Cardinal; P: PAnsiChar; Bytes: TBytes;
begin
  Pdf := pdfNewPDF;
  try
    if not pdfCreateNewPDFW(Pdf, nil) then Abort;   // memory mode
    pdfAppend(Pdf);
    // ... content ...
    pdfEndPage(Pdf);
    if not pdfCloseFile(Pdf) then Abort;
    P := pdfGetBuffer(Pdf, Size);
    if (P = nil) or (Size = 0) then Abort;
    SetLength(Bytes, Size);
    Move(P^, Bytes[0], Size);                       // copy NOW
  finally
    pdfDeletePDF(Pdf);
  end;
end;

See alsopdfCreateNewPDF, pdfCloseFile

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern IntPtr pdfGetBuffer(IntPtr IPDF, ref uint BufSize);
Area
Import & Output APIs
Category

Getters

Exported names

pdfGetBuffer

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.