Html to PDF problem rendering controls

Trying to render checkboxes to my PDF from an HTML file. Result is that the checkboxes are editable, which we don’t want. Following this suggestion, I was able to disable the checkboxes in the output, but the result shows no border around the input control–when the checkbox is checked, we get a check only, and when the checkbox is not checked, we get whitespace.


So I attempted a workaround, replacing the input control with a span that included Bootstrap’s glyphicons for unchecked and checked icons. That failed I believe due to the same issue reported as PDFNEWNET-38331, so consider this a second call for fixing that one. I ended up inserting some img tags, which works, but is not ideal. While trying to figure that out, by the way, I found that relative URLs do not seem to be supported–is that correct? I instantiated the HtmlLoadOptions with my base application path, but no relative path in the HTML seemed to be found during conversion, so I ended up putting in a full path.

Ideally, I’d want the HTML conversion to honor the disabled attribute of the input tag, and render a read-only control to the PDF–that’d be simplest. Any other guidance you can offer? Thanks

Hi Andrew,

Thanks for contacting support.

In order to make the form fields read-only inside the PDF document, you may consider flattening the PDF form. Please try using the following code snippet to flatten form fields inside the PDF file.

However, if the problem still persists, please share the resource HTML so that we can test the conversion in our environment. We are sorry for this inconvenience.

[C#]

Document doc = new Document("source.html", new HtmlLoadOptions());
// flatten form fields inside document
doc.Flatten();
doc.Save("resultant.pdf");

Thanks, that’s useful–Flatten is much easier than recursing through and disabling the fields individually–but the result is the same. Checked checkboxes get a check, unchecked checkboxes get whitespace. Looking for a box around the check, and an empty box for unchecked. Html attached.

Hi Andrew,

In order to accomplish your requirements, first you need to load HTML contents, render the output as PDF, instantiate FormFieldFacade instance, set border for CheckBox fields, set border width and border style, initialize another Document instance and flatten all form fields inside it and then save the resultant file.

For your reference, I have also attached the resultant file generated over my end.

C#

// load HTML and render output as PDF
Aspose.Pdf.Document doc = new Aspose.Pdf.Document("c:/pdftest/AsposeTest4_header.html", new HtmlLoadOptions());

// create FormEditor object and open PDF file
Aspose.Pdf.Facades.FormEditor form = new Aspose.Pdf.Facades.FormEditor();

// bind PDF file generated with Document instance
form.BindPdf(doc);

// create a new facade object
Aspose.Pdf.Facades.FormFieldFacade facade = new Aspose.Pdf.Facades.FormFieldFacade();

// assign the facade to form editor
form.Facade = facade;

// set border style for form fields
facade.BorderStyle = Aspose.Pdf.Facades.FormFieldFacade.BorderStyleSolid;
facade.BorderColor = System.Drawing.Color.Black;

// set border width as 1
facade.BorderWidth = 1;

// set the alignment as center
facade.Alignment = FormFieldFacade.AlignCenter;

// all text fields will be modified:
form.DecorateField(FieldType.CheckBox);

// This line of code is not necessary:
//Aspose.Pdf.Facades.FormFieldFacade.Parse(ostream questi
// It should be removed or commented out

MemoryStream temp_stream = new MemoryStream();

// close and validate the modification like this:
form.Save(temp_stream);
doc = new Aspose.Pdf.Document(temp_stream);

// flatten form fields inside PDF
doc.Flatten();

// save updated document with flatten form fields
doc.Save("c:/pdftest/CheckBoxFlattened.pdf");

That works, thank you!

Hi Andrew,


Thanks for sharing the feedback.

We are glad to hear that your requirement is accomplished. Please continue using our API’s and in the event of any further query, please feel free to contact.