A question to the author: can I use the pdf export from HTML, without the GUI (headless mode)? It would be useful to produce mail merges. Chromium, for example, has --print-to-pdf option to export any html to pdf.
Yes — Pixie's PDF export is fully headless.
There's no GUI dependency at all:
TPixiePdfExport takes an HTML string and writes a PDF, rendering through its own PDF canvas and built-in TrueType engine, so it never opens a window or touches a platform backend.
uses
Pixie.PdfExport;
var
Pdf: TPixiePdfExport;
begin
Pdf := TPixiePdfExport.Create;
try
Pdf.PageSize := ppsA4;
Pdf.Margins := TPixiePdfMargins.Create(56, 56, 56, 56); // points
Pdf.Title := 'Invoice 1234';
Pdf.SaveToFile(MergedHtml, 'out\invoice_1234.pdf');
// or: Pdf.SaveToStream(MergedHtml, AStream); // straight to memory / attachment
finally
Pdf.Free;
end;
end.
Loop that over your records and you've got a mail merge. Handy properties for it:
- UserCss — inject a shared stylesheet without editing each merged document.
- BaseUrl + OnFetchUrl — resolve and fetch images/CSS (e.g. logos, remote assets).
- SaveToStream — render to a TStream with no temp file, e.g. to attach the PDF directly to an email.
- PageSize / Margins / Title / Author — page setup and document metadata.
Multi-page documents paginate automatically, with break points chosen so block elements aren't split across pages. Fonts are embedded (and subsetted), so the output is self-contained and the text stays selectable/searchable.
One build note: a headless build still links the
LCL package on the unit path (the engine pulls in
LCLType/clipboard for its owner-drawn form controls), but nothing GUI is initialised at runtime — it runs fine as a console app.