DrawHTMLPages
HTML, CSS, print layout
Description
Paginate HTML using explicit page rules and caller-registered font resources
Syntax
Delphi
Function TPDFlib.DrawHTMLPages(Const HTMLText: WideString; MaxPages: Integer= 100): WideString;DLL
const wchar_t* DLDrawHTMLPages(int InstanceID, const wchar_t* HTMLText, int MaxPages);
const char* DLDrawHTMLPagesA(int InstanceID, const char* HTMLText, int MaxPages);ActiveX
Function PDFlib::DrawHTMLPages(HTMLText As String, MaxPages As Long) As StringParameters
| HTMLText | The HTML source to paginate; it must not exceed 8388608 characters |
|---|---|
| MaxPages | The maximum number of pages to create, from 1 to 1000; the default is 100. When the limit is reached with content still unplaced, the remainder is returned and LastErrorCode reports the import failure |
Return values
Returns the HTML text that could not be placed on the pages, or an empty string when all content was drawn. When the import fails, the unplaced input is returned and LastErrorCode reports the reason.
Remarks
Starts on the selected page, changes its dimensions when a supported page-size rule requests it, and appends pages as needed; use an empty selected page for a new HTML flow
Returns an empty string on complete placement or the unplaced HTML continuation when processing stops; MaxPages defaults to 100 and must be between 1 and 1000, and source text is limited to 8388608 UTF-16 code units
Page geometry uses physical points independently of the current measurement units and origin; the initial page must be unrotated with UserUnit 1, and page dimensions must not exceed 14400 points
The page profile supports unnamed and named @page rules and :first, :left, :right and :blank selectors, absolute top/right/bottom/left margins, one/two absolute size lengths, A3/A4/A5/Letter/Legal paper names, and portrait/landscape orientation; page numbering is relative to this HTML flow
Default margins are 36 points and the selected page supplies the default size; supported length units are pt, px, in, cm, mm and pc, with 1 CSS px equal to 0.75 points; percentage page dimensions and margins are diagnosed as unsupported
All sixteen page margin boxes accept quoted generated text, counter(page), counter(pages), or a single element(Name) reference; counters support decimal, decimal-leading-zero, lower/upper-alpha, lower/upper-latin and lower/upper-roman styles
Margin-box declarations cascade by page selector specificity, importance and source order; supported font properties inherit from the page context, and absolute width/height/min/max dimensions, horizontal text alignment and top/middle/bottom vertical alignment control the bounded box layout
Headers and footers are painted after body pagination so total-page counters include directional blank pages; incomplete flows suppress total-dependent generated content with an incomplete-page-total finding, while current-page counters remain available
Supported block-flow elements with position:running(Name) leave the body flow and retain their styles, descendants and inherited font/color appearance for element(Name,first), start, last and first-except; names are case-sensitive unescaped ASCII identifiers of at most 256 bytes, and the default selection is first
Running assignments carry forward to later pages; blank pages inherit entering values without consuming upcoming assignments, and running content does not select the body page type; supported child layouts capture nested running elements under the same finite geometry and page-type rules
Margin painting clips to each box and reports overflow or unsupported content/properties; percentage box dimensions, full CSS box decoration, generated named strings and arbitrary counters remain outside this finite profile, and element() cannot combine with other content values
Each page permits at most 256 running assignments and 1 MiB of captured UTF-16 markup; retained names are limited to 256 and 1 MiB, all placed-page captures to 16 MiB, and margin generation/measurement uses a shared 4194304-unit work budget
The page property selects a case-sensitive page type on supported block-flow elements; auto resolves through the nearest non-auto ancestor, and leaving a named block restores the ancestor type for subsequent content
Page-type changes force a boundary before the next supported block or text content, and named selectors combine with :first, :left, :right and :blank; comma-separated selectors use the named-type, first/blank and side specificity order
Names use an unescaped ASCII CSS identifier of at most 256 bytes; named page selection is preserved across continuation and its cache key, and supported sequential Flex/Grid item and homogeneous table-body row transitions select the next page geometry
Supported block-flow break-before and break-after values left/right and recto/verso insert a necessary blank page before placing the next content on the requested side; page progression is explicitly left-to-right, with odd pages right/recto and even pages left/verso, regardless of the document's selected page number
The legacy page-break-before/page-break-after names share the declaration cascade with break-before/break-after; at a shared boundary a later directional break-before wins over the preceding directional break-after, while a generic forced break retains the directional requirement
A leading directional break can make the initial page blank; blank pages receive matching page rules, count toward MaxPages and pagesDrawn, and are reported separately as blankPages; measurement precedes drawing so blank pages receive no body drawing commands, while their matching margin content can still render
Tables retain resolved column proportions and repeat leading header rows across continuations; a row group linked by rowspan stays together when it fits a complete page body, while oversized spanning groups can continue at row boundaries with shortened spans
Oversized rows continue their cell contents independently within the remaining page body; completed cells remain empty in later fragments, active spanning cells retain their continuation content, and text, borders and backgrounds stay within each placed fragment
Leading table headers are kept with a body line when the table moves from a partly occupied page; a header plus body line or an indivisible child that cannot fit the page area fails with a diagnostic and an unplaced continuation rather than drawing below the page
Table continuation currently follows the supported finite cell renderer, with at most 4096 rows/cells, 64 columns, colspan 64 and rowspan 256; arbitrary nested cell-content break propagation and complete CSS table fragmentation remain outside this profile
Directional breaks propagate through supported block flow, table row boundaries and first-level Flex/Grid item bands; containers preserve their own leading/trailing breaks, and a final supported child break can reach content after the container
A first child break can move its container from an occupied page without discarding earlier content; directional blank pages are inserted only at an otherwise fresh page boundary, and repeated table headers do not consume the body row break
The finite propagation profile does not provide writing-mode-dependent progression, arbitrary nested cell-content break propagation or complete CSS fragmentation; ordinary text-box/story frames retain a single-frame fallback with a diagnostic
Inline-content block paragraphs support inherited widows and orphans counts from 1 to 1000, defaulting to 2; measured opening fragments can move to the next page, and the current fragment can end early to retain the requested closing lines
Paragraph line policies survive later continuations; block break-inside:avoid and avoid-page, including the legacy page-break-inside alias, move a block that fits a complete page when it cannot fit the remaining area
Line constraints apply to the supported inline paragraph profile; impossible count combinations and blocks taller than a full page relax with explicit findings, and fragmentation probes have a 64 MiB cumulative source-processing budget per renderer
Oversized supported Flex/Grid containers paginate through their resolved nonoverlapping item geometry, retaining column proportions, vertical gaps, spanning items, backgrounds and independent child-content continuations; fitting containers can still move intact from a partly occupied page
The finite container fragmentation profile permits 256 items, 64 horizontal bands, 256 vertical bands and 4096 generated cells; overlapping items, out-of-bounds item geometry and exhausted bands fail explicitly with the source continuation intact
Container fragmentation preserves resolved geometry through the existing cell continuation path; complete CSS fragmentation, arbitrary overlapping Grid painting and arbitrary nested child breaks and conflicting parallel page-type requirements remain outside this profile
For supported sequential container content, the leading body item determines the initial page type before geometry allocation, and later row/item page-type changes create a continuation on the requested named page; repeated table headers retain their content without choosing the body page type
Named child continuations preserve their page type over multiple pages and restore the ancestor type for following content; the finite profile follows logical first-content order and nonoverlapping item bands, and simultaneous cells or spanning items requiring different page types reject explicitly
Register explicit font resources with SetHTMLNormalFont and the corresponding bold/italic registration methods; a @font-face src URL or local name identifies a registered font-set key, never a request to load a file, installed font or network resource
Font faces support normal/bold (400/700) and normal/italic style descriptors; family aliases and inherited face selection survive continuation, and missing sources use the existing font fallback with a finding
Completed cell fragments discard metadata-only continuation shells while preserving resolved page types; nested cell breaks outside supported row/item bands use an explicit degraded finding, and page-type changes inside one cell reject rather than drawing on incorrect page geometry
Each completed page is committed immediately; on page-budget exhaustion, invalid geometry, a stalled layout or an exception, error 541 and GetLastHTMLImportDiagnostics identify the result and number of placed pages, while earlier pages remain in the document
Initial page-area validation runs before content placement; a returned continuation contains instance-owned font references and must stay with the same live document, using the existing HTML text-box or story continuation APIs rather than being saved as a portable HTML file
The paginator and diagnostic getter are available through native Delphi, Windows DLL, macOS Dylib and ActiveX IPDFlibrary16; existing ActiveX HTML text-box signatures remain available
ActiveX exposes this method through IPDFlibrary16 and the default dispatch interface; Pascal Automation callers can use CoPDFlibrary.CreateConversionTools
The macOS Dylib exposes the same wide and A C entry points shown above using the C calling convention; string pointers belong to the instance and must be copied before the next string-returning call, and A variants follow the configured ANSI or UTF-8 mode