RichTextBox Field is not rendering the HTML

Here my code is:
1.Get the PDF template (Empty Template, No values in textbox,checkbox) and convert to bytes
2. Convert to PDF.Documents to collect the form fields
3. Collect the control name and values from DB
4. Map the FormFields (FillForms) to DB values by using Aspose.PDF.Facades & Forms and Render as PDF in browser
5. Here problem, in the UI,they have entered the values in Rich Text Box Editor. So, Bold, Italic, Bulletin, underline, next lines are using. The values are not rendering in PDF while map the RichTextBox to DB Values (Its Html Content) . We are using Aspose.PDF 23.0 version. Whether is possible by Aspose.PDF ?
Please check and let me know the solutions or Code Samples
Note: PDF and Code - Couldnt Share due to Office policy

@Amarsha

It looks like you want to read a PDF template in bytes and then fill form fields using form fields names and their respective values from database. You can simply initialize Document instance using bytes of a valid PDF template. Once Document is initialized, you can read form fields information and fill their values accordingly. Please check below code examples in the API documentation:

Thanks for response. The above all are we have used, and the code changes are running in production. Last release in UI, business included the RichTextBoxEditor and the values are stored in DB. They need the same values will be rendered in Same PDF itself. So, we have analyzed and plan to include the RichTextBoxField in existing code. (formattedValue, RichTextValue and value - all the options are used). But we couldn’t render the html content in PDF. Plain HTML values are rendering. our content like “-html>-body> this is demo -b>included -/b> -/br>-/br> -u>rendering PDF-/u> -/body>-/html>.” Please share the some examples how render the HTML values. whether the values will be format like any XML based and will give to input to RichTextBoxField. If not possible, team will be try do POC like Aspose.HTML or ITextsharp tool. Thank you!

@Amarsha

Thanks for your feedback. We need some information from your side in order to share our feedback and assist you accordingly. Can you please share a sample PDF document with the RichTextbox field along with a sample HTML string value that you are trying to set? We will use this information to test the things in our environment and address it accordingly. Also, please share the sample code snippet that you are using to fill the fields.

hi, Thanks for your response.

my Code Changes here:

document doc = new Doc(); 
doc.pages.add(); 
string htmlObj = "-html -body This is new PDF render in HTML format -body -html";
string problemHtml =  "-html -body This is new PDF render in HTML format -/br> -body -html";
RichTextBoxField obj = new RichBF(doc.Pages[1], new rect(100,200,300,400));
obj.FormattedValue = problemHtml; (i use htmlObj,it will render as HTML)
obj.Height = 100
obj.Multiline= true;
doc.Form.Add(obj);
doc.save("C:\PDF\New.pdf");

If i use problemHtml and assigned to FormattedValue, it will convert to XML value like
-?xml version="1.0" encoding=UTF-8"?> -body xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://xfa.org/schema> -html -body This is new PDF render in HTML format -/br> -body -html and then its not rendering.

Here, its converting to Xhtml instead of html. if we use the br, b, u, I, /n tags, it will not render properly.

@Amarsha

Are you using Java API? Can you please also share the PDF generated using the above code snippet?

No, Dot Net only. I have used the code changes in VS2019.

BR_Tag_Problem_html.pdf (95.9 KB)
CorrectHtml.pdf (91.8 KB)
PDF_Issue.jpg (336.9 KB)

Attached Files here.
If i use, BR, Bold, Italic,underline tags in inside HTML,it will generate the xml type codings.

@Amarsha

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-54889

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Can you please check the issue status. ? Or Can you please provide the some examples. We are using license product only. Code and Document could not be share with outside. So, i have installed trial version in my own laptop and generated the PDF.

We are facing the issue is, if the HTML content is single line like (Hi this hello world) - Its working, But in real scenario, the content is coming from DB as paragraph. Because, User has entered the data in UI RichTextBoxEditor. So, based on that, using Acrobat Writer 2020 version, we were created the PDF Template with TextboxField, CheckBox and RichTextBoxField. All the fields are mapping with fields are rendering fine.Only issue with RichTextBox field (.FormattedValue). If any special character is in HTML Content paragraph, it will not render properly. I hope you have test code snippets correct. If any pls share with me.

Thanks.

@Amarsha

We are afraid that the earlier logged ticket has not been yet investigated. Please note that it was logged under free support model and will be investigated/resolved on a first come first serve basis. We will surely inform you as soon as we make some significant progress towards ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thanks or your detail. In the PDF template, we have Richtextboxfield is available. As we discussed, HTML is not rendering in RichtextBoxField. So, what we planned, find the richtextbox using by ID and find the obj positions (ObjRihTextBox.Margin) and create the

string HtmlstringContent = <html><body>small <b>text</b></body></html>
HtmlFragment objFragment = new HtmlFragment(HtmlstringContent);
objFragment.Margin = ObjRihTextBox.Margin;
document.Paragraphs.Add(objFragment);

If we use the above code snippets, its perfectly converted to HTML to PDF. But, Margins not working properly. We we tried, place the paragraph content in RichTextBox Position.
Is any way to set the positions/Margins for Paragraph. Please provide the sample code snippets to arrange the Paragraph. In the page of middle, we have placed RichTextBox in PDF Template. So, in same place, in Run time, we want to remove the RichtextBoxField and insert the Paragraph as PDF content. Thanks in advance.

@Amarsha

Would you kindly share a sample source PDF and output PDF document generated using the code you just shared with us? We will test the scenario in our environment and address it accordingly.

@Amarsha

Also, you can try below workaround:

1- Get position of the form field
2- Place a floating box at the same location
3- Add HtmlFragment inside FloatingBox

// Load the PDF document
Document doc = new Document("input.pdf");
// Get the form object
Form form = doc.Form;
// Get the form field by name
FormField field = form["FieldName"];
// Get the rectangle of the field
Rectangle rect = field.Rect;
// Create a floating box with the same width and height as the field
FloatingBox box = new FloatingBox(rect.Width, rect.Height);
// Set the background color of the box to yellow
box.BackgroundColor = Color.Yellow;
// Set the border of the box to black
box.Border = new BorderInfo(BorderSide.All, Color.Black);
// Set the left and top position of the box to match the field
box.Left = rect.LLX;
box.Top = rect.URY;
// Create an HTML fragment with some HTML string
HtmlFragment html = new HtmlFragment("<p style='color:blue'>This is an <b>HTML</b> fragment</p>");
// Set the horizontal and vertical alignment of the HTML fragment
html.HorizontalAlignment = HorizontalAlignment.Center;
html.VerticalAlignment = VerticalAlignment.Center;
// Add the HTML fragment to the box
box.Paragraphs.Add(html);
// Add the box to the first page
doc.Pages[1].Paragraphs.Add(box);
// Save the document
doc.Save("output.pdf");

No use Asad. in before, its rendering with in the page. after use the above code, its rendering in 2 pages.

@Amarsha

Can you please share your sample PDF document for our reference along with the field name and other information? We will test the scenario in our environment and address it accordingly.

Hi Asad, Anyway, the above task is completed by using Table property. We have created the table and assign the html content to cell. The Rich Text format is working fine without RichTextBox. But i need one more help. If i want to truncate the data, how will we possible in Table properties. For ex, in table has 70 height, then it should render the based on the height only. I mean, it should occupy with given height.
Thanks, Amar

@Amarsha

You can use Table.GetHeight() method in order to determine the table height while adding it to the page.

Hi Asad, I think you are not capturing my question. Now, we are using the 22.11 (Aspose.PDF).

  1. The same issue we have is, Aspose is calculate the top position of textbox is from bottom to top. I mean, top position calculation is vary from Acrobat and Aspose for Textbox or anyfield. For, Ex: I placed the textbox in page. Top position is 50 in Acrobat. But, while read in Aspose of textbox(.rectangle.URY) top position is 650. This is giving the headache for us.

  2. We have created the table and assign the html (HtmlFragment) content to cell. The Rich Text format is working fine without RichTextBox by using Table Properties. But i need one more help. If i want to truncate the data, how will we possible in Table properties. For ex, in table has 70 height, then it should render the based on the height only. I mean, it should occupy with given height. But, in RichTextbox, its height is 70 means, it will allow only characters of 70 height. Rest of characters are truncated automatically. Even, business ready to buy the 23.6 version and they need the answer to fix these issues.

Note: Due to policy purpose, i could not the share the code and PDF

Thanks, Amar