We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Font formatting and Line Breaking in RichTextBoxFields using Aspose.PDF for .NET - Line Break is not working

We are trying to get formatted text (some words bold, some superscript, etc) and line breaks in a rich text box field. We were able to create the xml for the RValue of a RichTextBoxField to display some words as bold and some words as underlines, however we can’t get line breaks in the RichTextBoxField. We have also been able to get line breaks in regular TextBoxFields, but then we lose the ability to make certain words bold and underlined.

Is there a way to make text superscript, and to add line breaks to a RichTextBoxField in C# code?


Thanks for using our products.

Can you please share the source PDF file and the code snippet that you are using so that we can test the scenario at our end. We are sorry for your inconvenience.

Here is the code we are using to try and populate the RichTextBoxField with formatted data:

private Stream FillInDocument(Stream stream)


Stream ret = new MemoryStream();

Aspose.Pdf.Document doc;



doc = new Aspose.Pdf.Document(stream);


catch (Exception)


return stream;


Assembly assembly = Assembly.GetExecutingAssembly();

string path = System.IO.Path.GetDirectoryName(assembly.Location) + @"\Aspose.Pdf.lic";

Aspose.Pdf.License lic = new Aspose.Pdf.License();


// Method returns the aspose field given the field name

Aspose.Pdf.InteractiveFeatures.Forms.Field formField = getField(doc, “DrugClass1Bin1Drugs”);

Aspose.Pdf.InteractiveFeatures.Forms.RichTextBoxField currentTextbox = formField as Aspose.Pdf.InteractiveFeatures.Forms.RichTextBoxField;

// The formfield wasn’t a richtextfield

if (currentTextbox == null)

return stream;

string htmlText = String.Empty;

string text = “This is some **bolded** text. This is some underlined text.
Here is some text on a new line.”;

htmlText = CreateXmlText(text);

currentTextbox.RValue = htmlText;



return ret;


private Aspose.Pdf.InteractiveFeatures.Forms.Field getField(Document doc, string p)


foreach (Aspose.Pdf.InteractiveFeatures.Forms.Field formField in doc.Form)


if (formField.PartialName == p)

return formField;


return null;


private string CreateXmlText(string mainText)


string xmlString = String.Empty;

xmlString += “<?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/">";](http://www.xfa.org/schema/xfa-data/1.0/%22%3E%22;)

xmlString += “<p dir=“ltr” style=“margin-top:0pt;margin-bottom:0pt;font-family:‘Arial’;font-size:11pt;”>”;

xmlString += mainText;

xmlString += “”;

xmlString = ReplaceBoldTags(xmlString);

xmlString = ReplaceUTags(xmlString);

xmlString = ReplaceBRTags(xmlString);

return xmlString;


private string ReplaceBoldTags(string mainText)


mainText = mainText.Replace(”**”, “<span dir=“ltr” style=“font-weight:bold;”>”);**

**mainText = mainText.Replace("**", “”);

return mainText;


private string ReplaceUTags(string mainText)


mainText = mainText.Replace("", “<span dir=“ltr” style=“text-decoration:underline;”>”);

mainText = mainText.Replace("", “”);

return mainText;


private string ReplaceBRTags(string mainText)


// doens’t work

//mainText = mainText.Replace("
", “

//doesn’t work

//mainText = mainText.Replace("
", “<span style=“xfa-spacerun:yes”><p dir=“ltr” style=“margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:11pt”>”);

return mainText;


Hi there,

Thanks for sharing additional information. In reference to line break issue, we have managed to reproduce the issue at our side and logged as PDFNEWNET-34975 in our issue tracking system for further investigation and resolution. We will keep you updated regarding issue progress via this forum thread.

Further more in reference to postscript text requirement, please check following documentation link for details. Hopefully it will serve the purpose.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-34975) have been fixed in Aspose.Pdf for .NET 8.0.0.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.