[PDFNet] Rich text fields in PDF

Q: I tried to set that flag and insert rich text into the field, but
it did not work? Am I doing something wrong or is rich text not
A: You can use PDFNet to create or modify rich text fields in PDF
(please keep in mind that rich text fields are not well supported by
many PDF consuming applications/viewers). Here is an example of how to
create a new Widget annotation with rich text field:

using System;
using pdftron;
using pdftron.Common;
using pdftron.PDF;
using pdftron.SDF;

namespace PDFTronTest
internal class Program
private const string RtfText =
  "<?xml version=\"1.0\"?>" +
  "<body xfa:APIVersion=\"Acroform:\" xfa:spec=\"2.1\" xmlns=
\"http://www.w3.org/1999/xhtml\" xmlns:xfa=\"http://www.xfa.org/schema/
xfa-data/1.0/\">" +
  "<p dir=\"ltr\" style=\"margin-top:0pt;margin-bottom:0pt;text-
valign:middle;font-family:Helvetica;font-size:12pt\">Hello<span style=
\"xfa-spacerun:yes\">&#160;</span><span style=\"color:#ff5400;font-
style:italic\">World</span></p>" +

private static void Main(string[] args)

    var doc = new PDFDoc();


    Page blank_page = doc.PageCreate();

    Field emp_first_name = doc.FieldCreate("employee.name.first",

    // Create text annotations
    pdftron.PDF.Annots.Widget annot1 =
pdftron.PDF.Annots.Widget.Create(doc, new Rect(50, 550, 350, 600),
    annot1.SetFlag(Annot.Flag.e_print, true);

    doc.GetAcroForm().PutBool("NeedAppearances", true);

    emp_first_name.SetFlag(Field.Flag.e_rich_text, true);

    emp_first_name.GetSDFObj().PutString("DS", "font: Helvetica,sans-
serif 12.0pt; text-align:left; color:#000000");
    emp_first_name.GetSDFObj().PutString("RV", RtfText);
    emp_first_name.SetValue("Hello World");

    doc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized);

  catch (PDFNetException e)
  catch (Exception e)

You received this message because you are subscribed to the "PDFTron PDFNet SDK" group. To post to this group, send email to support@pdftron.com
To unsubscribe from this group, send email to pdfnet-sdk-unsubscribe@googlegroups.com. For more information, please visit us at http://www.pdftron.com