RichTextBox Field is not rendering the HTML

@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

@Amarsha

You are right. Aspose.PDF follows a coordinating system that starts from bottom-left. Unlike conventional coordinating system (x=0,y=0) means bottom-left in Aspose.PDF API. Therefore, you can implement the values as per the API specifications.

We totally understand your concerns, however, we are afraid that this particular requirement may need investigation and for that we need some sample information of your use case. If you are not comfortable with sharing your original code snippet and PDF, you can please create a sample console application with basic code and sample PDF and share it with us. We will use this application in our environment to replicate the behavior and apply modifications to meet your requirements.

@asad.ali : Thanks for prompt response. So, currently we have calculating like
int TopPosition = Convert.ToInt(Page.URY - RichTextBox.Rect.URY) - Version Aspose.PDF (10.5) - Its working fine.
int TopPosition = Convert.ToInt(Page.URY - RichTextBox.Rect.URY) - Version Aspose.PDF (22.11) - Its not working properly. As you said Bottom-Left means, how would be calculate the topPosition.
Anyway, i will send the sample code snippet and PDF.

Thanks for your Support!!

@asad.ali, Please find the code changes and attached PDF. Here, we are facing the issue is, While replace the RichTextBox to Table, we are facing the Top position issue and even in single line is not fitting to table and will render into next page. I
2) If we have more content, its not chopping or cut the characters based on the Table width and Height. Its rendering the next page or Its throwing the hard error. Version 10.5 → Sometimes, if content have more, its throwing the error without any proper message. So , we couldnt capture exception also. if any API documentation reference site, please let me know.

Sample_Template.pdf (85.8 KB)

Single_line_But_Render_in_New_Page.pdf (381.6 KB)

NextPage_Render_BigContent.pdf (382.1 KB)

Program.zip (1.4 KB)

@asad.ali , @tilal.ahmad : if any calculation to find the RichTextBox top position (replace from RichTextBox to Table), Please let me know. Thanks