RichEdit and RTF Pagination Import

THotPDF.ImportRTF loads RTF into Windows RichEdit and THotPDF.ImportRichEdit paginates an existing control into PDF pages

Rendering model

Pagination uses EM_FORMATRANGE with a bounded page rectangle and emits each page through an enhanced metafile

Text, font changes, paragraph formatting, vector rules, and other GDI operations remain PDF text or vector operators whenever the RichEdit and EMF pipelines expose them that way

RTF pict data and RichEdit-supported static OLE presentations are carried by the same EMF path, so no whole-page rasterisation is required

Threading and lifecycle

Security and budgets

THPDFRTFImportOptions.Default limits input to 16 MiB, text to 4,000,000 characters, output to 1,000 pages, and accumulated EMF data to 256 MiB

Embedded OLE is disabled by default and requires AllowOLE=True; enabling it should be limited to trusted RTF because Windows RichEdit owns the installed OLE handler surface

CancellationToken is checked between pages and returns risCancelled without rendering additional pages

Result reporting

THPDFRTFImportStatistics reports input bytes, character range, pages rendered and added, accumulated metafile bytes, OLE presence, truncation, and a stable THPDFRTFImportStatus

Budget exhaustion, invalid page geometry, wrong-thread calls, no-progress pagination, and rendering failures return False with a specific status

Example

Options := THPDFRTFImportOptions.Default;
Options.PageWidth := 612;
Options.PageHeight := 792;
Options.MarginLeft := 54;
Options.MarginRight := 54;

Document.BeginDoc;
RTFStream.Position := 0;
if not Document.ImportRTF(RTFStream, Options, Statistics) then
  raise Exception.CreateFmt(
    'RTF import failed with status %d',
    [Ord(Statistics.Status)]
  );

See also: THotPDF.ImportRTF, THotPDF.ImportRichEdit, SVG Form XObject Import