HTML5 Paged-Media Import

THPDFHTMLImporter.RenderHTML5 converts tolerant HTML5 markup and print CSS into paginated PDF content while preserving the compact legacy RenderHTML path

CSS lengths and the importer's Margin, BaseFontSize, ListIndent, and BlockSpacing are in points, so both renderers produce the same page whatever THotPDF.Resolution is set to; your own drawing before and after the import keeps using 1/Resolution inch

Declaration

function RenderHTML5(
  const HTML: WideString;
  const AuthorStyleSheet: WideString = ''
): Boolean;

function HPDFRenderHTML5Document(
  Doc: THotPDF;
  const HTML: WideString;
  const AuthorStyleSheet: WideString = '';
  MarginPt: Single = 72;
  const FontName: AnsiString = 'Arial';
  FontSize: Single = 12
): Boolean;

Profile contract

HTML5ProfileVersion returns 1 and HTML5ProfileMilestones reports parser and cascade, paged layout, tables and forms, and bounded resources

Bounded resources

External stylesheets, images, and fonts are disabled unless OnResource supplies their bytes, so HTML import never opens a file or network connection implicitly

data: resources and callback results share MaxResources, MaxResourceBytes, and MaxTotalResourceBytes limits

MaxDOMNodes, MaxCSSRules, and MaxLayoutOperations independently bound parsing, cascade construction, and layout work

THPDFHTMLResourceEvent = procedure(
  Sender: TObject;
  const URI: WideString;
  ResourceKind: THPDFHTMLResourceKind;
  var Data: TBytes;
  var ContentType: string;
  var Handled: Boolean
) of object;

Statistics

THPDFHTMLImportStatistics reports the profile version, parsed nodes, CSS rules, layout operations, page breaks, tables, form controls, resource requests, accepted and rejected loads, and accepted resource bytes

Every RenderHTML5 call resets the statistics record, and budget violations raise EHPDFHTMLImportBudget

Example

Importer := THPDFHTMLImporter.Create(Doc);
try
  Importer.CreateAcroForms := True;
  Importer.MaxResources := 16;
  Importer.RenderHTML5(
    '<style>@page { margin: 36pt } ' +
    'table { width: 100% }</style>' +
    '<h1>Invoice</h1>' +
    '<table><tr><td>Total</td><td>42</td></tr></table>' +
    '<input name="approved" type="checkbox">'
  );
finally
  Importer.Free;
end;

See also: THPDFPage.TextOutHTML, Declarative Layout DOM, AcroForm Support