THPDFPage.AddRichTextField Method

 

THPDFPage.AddRichTextField

THPDFPage

 

Вгору

Додає на current page PDF 1.5+ AcroForm rich-text text widget (ISO 32000-1 12.7.4.3 + Annex L) Widget містить standard /V + /DV plain-text fallback для readers, що не parse rich text, плюс нові entries /RV rich-text XHTML body і /DS default style, які Acrobat і Foxit consume directly для styled text Flag /Ff RichText bit (26) OR'd 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());

 

Опис

Widget emitиться як Tx form field з /FT /Tx, /DA (/Helv 12 Tf 0 0 0 rg), /Ff з RichText bit set, supplied InitialValue як /V і /DV, RichValue як /RV і DefaultStyle як /DS InitialValue, RichValue і DefaultStyle auto-detect multi-byte content і switch to UTF-16BE hex-string encoding when needed (matching existing AddTextField behavior для international plain-text fields)

Rich-text rendering відбувається у reader: Acrobat / Foxit / Edge / Chrome PDF viewer parse /RV, коли RichText bit on, і беруть Unicode font fallbacks із system, тому CJK, Cyrillic, Arabic і accented Latin content displays correctly без embedding CID font у /DR Resources Для власного path AutoFormAppearances HotPDF placeholder empty-AP branch для multi-byte text лишається (task v2.56.0+); rich-text-aware readers ignore that AP і render from /RV directly

 

FieldName - partial name /T PDF form field (має бути unique within parent) Spaces і non-ASCII bytes accepted; non-ASCII triggers UTF-16BE encoding on emitted /T string

InitialValue - plain-text PDF text string, written to /V і /DV Readers, що не parse /RV, fallback 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 - /Rect widget у HotPDF screen coordinates (top-left origin); YProjection happens automatically when rect 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; будь-які extra field flags для OR into /Ff beyond auto-added RichText bit Типові extra flags: ffMultiline для multi-paragraph rich-text bodies, ffReadOnly для display-only formatted text Flag ffRichText always added, тому caller не потрібно 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