|
Adds a PDF 1.5+ AcroForm rich-text text widget (ISO 32000-1 12.7.4.3 + Annex L) to the current page. The widget carries the standard /V + /DV plain-text fallback used by readers that do not parse rich text, plus the new /RV rich-text XHTML body and /DS default style entries that Acrobat and Foxit consume directly to render styled text. The /Ff RichText bit (26) is OR'd in automatically.
Delphi syntax:
procedure AddRichTextField(const FieldName, InitialValue: AnsiString; const RichValue, DefaultStyle: AnsiString; Rectangle: TRect; MaxLen: Integer = 0; Flags: THPDFFormFieldFlags = []);
C++ syntax:
void AddRichTextField(const AnsiString& FieldName, const AnsiString& InitialValue, const AnsiString& RichValue, const AnsiString& DefaultStyle, const TRect& Rectangle, int MaxLen = 0, THPDFFormFieldFlags Flags = THPDFFormFieldFlags());
Description
The widget is emitted as a Tx form field with /FT /Tx, /DA (/Helv 12 Tf 0 0 0 rg), /Ff with the RichText bit set, the supplied InitialValue as both /V and /DV, RichValue as /RV, and DefaultStyle as /DS. InitialValue, RichValue and DefaultStyle auto-detect multi-byte content and switch to UTF-16BE hex-string encoding when needed (matching the existing AddTextField behaviour for international plain-text fields).
Rich-text rendering happens in the reader: Acrobat / Foxit / Edge / Chrome PDF viewer all parse /RV when the RichText bit is on and pick up Unicode font fallbacks from the system, so CJK, Cyrillic, Arabic and accented Latin content displays correctly without HotPDF embedding a CID font into /DR Resources. For HotPDF's own AutoFormAppearances path the placeholder empty-AP branch for multi-byte text remains in place (the v2.56.0+ task); rich-text-aware readers ignore that AP and render from /RV directly.
FieldName - the PDF form field's /T partial name (must be unique within its parent). Spaces and non-ASCII bytes are accepted; non-ASCII triggers UTF-16BE encoding on the emitted /T string.
InitialValue - plain-text PDF text string written to /V and /DV. Readers that don't parse /RV fall back to this value for display.
RichValue - PDF 1.7 Annex L tagged XHTML body (the most portable form starts with <?xml version="1.0"?> and an XHTML <body> root carrying the xfa:contentType="text/html" namespace attribute). Inline styling uses <span style="..."> with CSS properties (font-family, font-size, font-weight, font-style, color, etc.).
DefaultStyle - CSS-like style string applied to characters the user types at fill time when no per-character style is present in /RV. Example: 'font: 12pt Helvetica; color: #000000'.
Rectangle - the widget's /Rect in HotPDF screen coordinates (top-left origin); the YProjection happens automatically when the rect is converted to PDF user space.
MaxLen - optional; when greater than zero, emits a /MaxLen entry capping the user-entered character count. Defaults to 0 (no limit).
Flags - optional; any extra field flags to OR into /Ff beyond the auto-added RichText bit. Typical extra flags: ffMultiline for multi-paragraph rich-text bodies, ffReadOnly for display-only formatted text. The ffRichText flag is always added so the caller does not need to include it.
Code Example
// Rich-text Tx widget with bold + italic markup.
var
Rich, DS: AnsiString;
R: TRect;
begin
HPDF.BeginDoc;
Rich :=
'<?xml version="1.0"?>' +
'<body xmlns="http://www.w3.org/1999/xhtml" ' +
'xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" ' +
'xfa:contentType="text/html">' +
'<p style="font-family:Helvetica;font-size:12pt">' +
'<span style="font-weight:bold">Bold</span> and ' +
'<span style="font-style:italic">italic</span> text.' +
'</p></body>';
DS := 'font: 12pt Helvetica; color: #000000';
R.Left := 60; R.Top := 60; R.Right := 280; R.Bottom := 100;
HPDF.CurrentPage.AddRichTextField(
'Biography', 'Plain biography text', Rich, DS, R);
HPDF.EndDoc;
end;
See Also
AddTextField, AutoFormAppearances, Version, AcroForm Support
|