API reference › Import & Output APIs
pdfGetBuffer
Fetch the finished document bytes after an in-memory close.
| Exported names | pdfGetBuffer |
|---|
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.
const char* __stdcall pdfGetBuffer(PPDF IPDF, uint32_t* BufSize);
function pdfGetBuffer(const IPDF: PPDF; var BufSize: Cardinal): PAnsiChar; stdcall; external 'LumasPdf.dll';
Example — in-memory generation (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 also — pdfCreateNewPDF, pdfCloseFile
C# (P/Invoke)
public static extern IntPtr pdfGetBuffer(IntPtr IPDF, ref uint BufSize);
Getters
pdfGetBuffer
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.