|
Rank: Newbie Groups: Member
Joined: 1/29/2013 Posts: 9
|
Hi, I am using EO.pdf to create PDF from HTML. I would like to add couple of editable text boxes on the PDF. The editable text boxes will be in the header and footer.
My code uses HtmlToPdf.ConvertHtml(html, doc, options) to render the PDF. I set the header (options.HeaderHtmlFormat) and footer(options.FooterHtmlFormat) in the options. I am also using options.AfterRenderPage to set some formatting of the block before rendering.
I would like to add one editable text box in the header and one in the footer. Inside my On_AfterRenderPDFPage method I am able to create new AcmTextBox and add to the block. It works but it adds the textbox to the end of the document.
I am not able to figure out how to add the text boxes in the right spots inside the header or footer. What is the best way to this. I have gone through some of the examples provided but could not figure this out.
Can you please help.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi, You are on the right path. The reason that the TextBox did not appear at the right place for you is because everything is rendered in the "content area", and the default "content area" has a one inch margin on all sides. So in order for you to render into the header/footer area, you have to adjust the content area to cover those. You can find more details on how to do that here: http://www.essentialobjects.com/doc/4/acm/advanced%20formatting/page_layout.aspxLook for "Setting Page Margins". Hope this helps. Please feel free to let us know if you have any more questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/29/2013 Posts: 9
|
Thanks for the quick response.
I should have mentioned earlier that my footer contains a table and I need one cell to be editable. The table contains 3 rows and some nested columns. I am able to bind most of the data to the HTML before converting to PDF so that's good. The issue is that 2 of the fields can not be pre-popuplated and we need to make them editable so customer can export the PDF, and then fill up to print out etc. (Same in the header)
I am not sure if setting margins would help in this case. I was hoping we can somehow access a cell in the table on the fly and add the editable textbox to it. Is that possible.
I can share a sample PDF if that's possible. Let me know.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi, It doesn't matter what you want to do when you use AcmTextBox you have to get the margin right first. The margins defines where the rendering region starts. So when that is wrong, everything else will be off. So that's absolutely the first you want to check. Forget about what you already have in your header/footer region from ConvertHtml. That has nothing to do with how your AcmTextBox is positioned. You can access a table cell and get the location of the cell if the cell is generated by ConvertHtml as the main content BUT NOT through HeaderHtmlFormat/FooterHtmlFormat. You can do that by not using HeaderHtmlFormat/FooterHtmlFormat at all, but inside your AfterRenderPage to make another call again with your header/footer HTML ---- at the right place, once again you have to override the default margin here. However the way to override default margin for ConvertHtml is different than ACM: http://www.essentialobjects.com/doc/4/htmltopdf/page_size.aspxOnce you use ConvertHtml to generate your header/footer, you will be able to use the returned HtmlToPdfResult object to find the exact location of each table cell. You can use use that location information to position your AcmTextBox. Hope this helps. Please feel free to let us know if you still have any questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/29/2013 Posts: 9
|
Great. I will start working on this implementation.
One final question:
How do I use HtmlToPdfResult object to find the exact location of each table cell? Do we have any working examples?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
You will use HtmlToPdfResult.HtmlDocument property to get the HtmlDocument object, which has a number of methods for you to get an HtmlElement, you can then access HtmlElement.Location property to get the location of the element.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/29/2013 Posts: 9
|
so far so good. i changed the implementation and i am here
HtmlToPdfResult html_pdf = HtmlToPdf.ConvertHtml(footer, doc, options); HtmlElement html_e = html_pdf.HtmlDocument.GetElementById("test_div"); //i can get html_e.Location.X, html_e.Location.Y
//i also have this textbox defined. AcmTextBox tbFirstName = new AcmTextBox();
how do I add the tbFirstName to html_pdf using the location information?
sorry for multiple questions but i am a newbie and will get better with this library.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
You will want to read the "Using PDF Creator" section in the help file first. If you still have questions after that we will be happy to help you further.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 1/29/2013 Posts: 9
|
I got it. It works; hope the approach is correct.
AcmBlock block = new AcmBlock(new AcmText("First Name: "), tbFirstName); block.Style.OffsetX = html_e.Location.X; block.Style.OffsetY = html_e.Location.Y;
Thanks again for helping.
|
|
Rank: Newbie Groups: Member
Joined: 1/29/2013 Posts: 9
|
So far...
In the On_AfterRenderPDFPage method, I am using HtmlToPdf.ConvertHtml(header, e.Page) to generate the header at the right spot and utilize the output to create an editable textbox in the desired cell.
I got this done fine except for one issue. I lost the HeaderHtmlFormat feature of putting {page_number}. Now {page_number} appears as text on my PDF.
Is there a way to maintain this while using HtmlToPdf.ConvertHtml. I tried ways of doing this reading the documentation but no luck so far.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
No. You just have to format the page number yourself.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 1/29/2013 Posts: 9
|
i can work around the page number by using a counter for current page number. but i need to also print the total number of pages in the footer like page 1 of 5.
how do i get around that.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
You can run the main conversion first, then run a loop to add page header/footers on each page. You don't have to do it inside On_AfterRenderPDFPage event handler.
Thanks
|
|