[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
supported?
-------------
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:2.7.0.0\" 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>" +
  "</body>";

private static void Main(string[] args)
{
  PDFNet.Initialize();

  try
  {
    var doc = new PDFDoc();

    doc.InitSecurityHandler();

    Page blank_page = doc.PageCreate();
    doc.PagePushBack(blank_page);

    Field emp_first_name = doc.FieldCreate("employee.name.first",
Field.Type.e_text);

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

    blank_page.AnnotPushBack(annot1);
    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);

    //System.Diagnostics.Process.Start("output.pdf");
  }
  catch (PDFNetException e)
  {
    Console.WriteLine(e.Message);
  }
  catch (Exception e)
  {
    Console.WriteLine(e.Message);
  }
}
}
}

--
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