|
Rank: Member Groups: Member
Joined: 2/6/2012 Posts: 21
|
Can you give some guidance about how you'd approach using HTML to PDF to generate documents that include PDF fill-in fields?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
You would have to do it separately. The HTML to PDF would convert everything except for the form element, then you can use the ACM interface to add form elements. You will need to:
1. Apply "visibility:hidden" on your form element in your HTML so that the HTML to PDF converter would not render them at all but still reserve spaces for them; 2. Use the HtmlToPdfResult object returned by the HTML to PDF converter to get the location and size information about each form element; 3. Use ACM interface with the information acquired on step 2 to create the form elements;
Not very often it is not possible for you to duplicate all HTML form elements precisely. This is because:
1. Not all HTML input elements have PDF equivalent; 2. Some PDF form elements do not have the same look and feel as their HTML equivalent; 3. PDF does not have the same JavaScript engine/object model as a HTML page;
If you hit any of the above, then you may need to adjust your page design slightly in order to achieve consistent look/behavior between your HTML page and your PDF file.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 2/6/2012 Posts: 21
|
OK that looks interesting. This proof of concept seems to work well:
Code: C#
PdfDocument pdf = new PdfDocument();
var conversion = EO.Pdf.HtmlToPdf.ConvertHtml(html, pdf, pdfOptions);
var inputs = conversion.HtmlDocument.GetElementsByTagName("INPUT");
foreach (HtmlElement input in inputs)
{
var txt = new AcmTextBox();
txt.Name = input.Name ?? input.ID;
txt.Style.OffsetX = input.Location.X;
txt.Style.OffsetY = input.Location.Y;
txt.Style.Height = input.Size.Height;
txt.Style.Width = input.Size.Width;
var render = new AcmRender(input.Location.Page, 0, new AcmPageLayout(new AcmPadding(0, 0, 0, 0)));
render.Render(txt);
}
pdf.Save(...);
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Yeah. The code would be like that. Thank you very much for sharing!
|
|