Multiple <br> has no effect in RichTextBoxField

Hi, i’m trying to upgrade my aspose.pdf .net library from an an older version to a new one.
It seems that something has changed to insert multiples blank lines in a RichTextBoxField
In my older version rtb.value = “-html–body-line1,-br–br–br–br-line2-/body–/html-”’
gives as result
line1

Line2

now after upgrading my library i only get 1 carriage return without any blank line so it gives
line1
line2
without the empty lines

when i try the oldest nugets packages, it seems that the behavior has changed between version 17.8 et 17.9 (wich is the version were i seems to lose my old behavior)

I see in version 17.9 releases notes that PDFNET-42933 has been fixed so maybe something as changed please help me on having the right syntax or the proper way to do what i need to

thanks !

ps. sorry in my example i replaced the br tags with -br- to not have blank line after saving my post

@S.Cyr

In the mentioned issue ID i.e. PDFNET-42933, the line height (space between lines) were not being honored by the RichTextBoxField. Following code snippet were tested after applying the fix and you can try them to check if they resolve your issue:

var richText = (RichTextBoxField) doc.Form.Fields[0];
richText.Style = "margin-top:0pt;line-height:7pt;font-family:Arial;font-size:7pt";
richText.Value = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10";
var richText = (RichTextBoxField) doc.Form.Fields[0];
richText.Value = "12345678910";
// Open document
Document pdfDocument = new Document();
// add page to pages collection of PDF file
pdfDocument.Pages.Add();
// create RichTextBoxField
Aspose.Pdf.Forms.RichTextBoxField field = new Aspose.Pdf.Forms.RichTextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 100, 230, 230));
// set height of form field
field.Height = 100;
// enable multiline for form field
field.Multiline = true;
// the default value for form field
// field.Value = "A multi line form field \n new line";
// field.Style = "margin-top:0pt;line-height:7pt;font-family:Arial;font-size:7pt";
field.Value = "12345678910";
// add RichTextBoxField to forms collection of PDF file
pdfDocument.Form.Add(field);
// Save updated document
pdfDocument.Save("c:/pdftest/MultiLine_Value.pdf");

@asad.ali
Sorry i’ve already tryed adding style statement but did’nt solve my problem.
Problem occurs if i got multiple line break (br) one ofter another (ex:line break and one or two blank line)

also, problem occurs only for blank lines ex : -br–br–br- as no effect but -br-a-br-b-br-c gives me
a
b
c

in my code, \n did not make any line break

thank for helping me out

@S.Cyr

Have you tried using 22.4 version of the API? Can you please share the complete code snippet along with the generated output PDF? We will test the scenario in our environment and address it accordingly.

hello @asad.ali

I have tested with version 20.1 wich is the highest version my actuel license permits.
Like I said earlier, problem occurs only if I got multiple blank line one after another. I found that it appends only if i got nothing in that line (empty line with no caracter at all).
I think I have found some kind of work around, maybe you can take a look at it and get back to me :

‘’ Test case that does not work - see result 1
dim myTestString as string = “Line1-br–br–br-Line2”
dim myTestString as string = “Line1 -br- -br- -br-Line2”
dim myTestString as string = “Line1” + vbCrLf + vbCrLf + vbCrLf + “Line2”

‘’ Test case that does work - see result 2
dim myTestString as string = “Line1 " + vbCrLf + " " + vbCrLf + " " + vbCrLf + " Line2”

Sample :
Dim myRtbf As RichTextBoxField = TryCast(pdfDocument.Form(“MyRichTextField”), RichTextBoxField)
Dim myValueString as string = “-html–body-” + myTestString + “-/body–/html-”
myRtbf.Value = myValueString

‘’ Result 1
Line 1
Line 2

‘’ Result 2
Line 1

Line 2

if i put just only one single space as a character in an empty line, my carriage return is taken in account. If no caracter at all, my carriage return is ignored.

thanks for helping me out !

@S.Cyr

Thanks for sharing more details. However, as requested earlier - can you please also share the generated output PDF for our reference as well?

@asad.ali
can i send you the pdf over email ?

@S.Cyr

You can send it in a private message by clicking over username and pressing the Blue Message Button.

@S.Cyr

Thanks for sharing the sample files for our reference in private message. Please check the below code snippet that we tested using Aspose.PDF for .NET 22.4 in our environment:

// Open document
Document pdfDocument = new Document();
// add page to pages collection of PDF file
pdfDocument.Pages.Add();
// create RichTextBoxField
Aspose.Pdf.Forms.RichTextBoxField field = new Aspose.Pdf.Forms.RichTextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 100, 230, 230));
// set height of form field
field.Height = 100;
field.Value = "1\n\n2\n3\n\n\n\n4\n5\n6\n7\n8\n9\n10";
field.Style = "margin-top:0pt;line-height:7pt;font-family:Arial;font-size:7pt";
// enable multiline for form field
field.Multiline = true;
// add RichTextBoxField to forms collection of PDF file
pdfDocument.Form.Add(field);
// Save updated document
pdfDocument.Save(dataDir + "MultiLine_Value.pdf");

MultiLine_Value.pdf (87.6 KB)

An output PDF is also attached above. You can notice in the PDF that values in the field are not being shown with the specified line breaks but as soon as you click in the text box to edit, the values become normal as expected (i.e. with specified line breaks). Can you please confirm if same is the issue at your end as well?

@S.Cyr

We have received another file from your side. However, it does not look like it was generated using the same code snippet that we shared. Can you please verify if you facing the similar issue that we mentioned in our previous reply?

@S.Cyr

Thanks for the feedback. Please share your sample source file with which you are facing the issue. You have only shared output files for our reference. Please share the respective source file that has an existing rich text box field. We will try to update it in our environment and share our feedback with you.

@S.Cyr

Please check the file that we shared in a private message with you. We used your Template.pdf document and updated it using the below code snippet. The output file looks fine and line breaks were working correctly in it. We used the 22.4 version. Can you please try to test the case using the latest version?

// Open document
Document pdfDocument = new Document(dataDir + "Template.pdf");
// add page to pages collection of PDF file
foreach (var f in pdfDocument.Form.Fields)
{
 if (f is RichTextBoxField)
 {
  // create RichTextBoxField
  Aspose.Pdf.Forms.RichTextBoxField field = (Aspose.Pdf.Forms.RichTextBoxField)f;
  // set height of form field
  field.Height = 100;
  field.Value = "1\n\n2\n3\n\n\n\n4\n5\n6\n7\n8\n9\n10";
  field.Style = "margin-top:0pt;line-height:7pt;font-family:Arial;font-size:7pt";
  // enable multiline for form field
  field.Multiline = true;
  // add RichTextBoxField to forms collection of PDF file
  pdfDocument.Form.Add(field);
  // Save updated document
  pdfDocument.Save(dataDir + "MultiLine_Value.pdf");
 }
}

@asad.ali the code sample seems to work but can we avoid the text to collapse and be forced to click in the field to have the line breaks. Our document must be saved and seen with the final format ?

@S.Cyr

You mean when you flatten the field or document, the line breaks in the rich text box are lost?

in the code sample you gave me, line breaks are not visible by default. I have to click in the field for the text to expand and show me the line breaks

@S.Cyr

We have logged an issue as PDFNET-51840 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.