|
Rank: Newbie Groups: Member
Joined: 2/13/2014 Posts: 3
|
Is there any method in HtmlToPDF that will take a URL to be used as the source for HTML to apply to a header or footer? The only mechanism I see is HtmlToPdf.Options.FooterHtmlFormat and it requires HTML. I realize that the fallback is to do the GET myself.
Thanks, Mark
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, There are no direct options for you to use an URL as header and footer. However you can always call ConvertUrl directly. It will be something like this:
Code: C#
//Convert the main contents
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl(main_url, doc);
//Render header_url to the header section of the first page
//Note the key is to set OutputArea. See here for more details:
//http://www.essentialobjects.com/doc/4/htmltopdf/page_size.aspx
//Also note the second argument of the ConvertUrl call is
//a PdfPage object, not a PdfDocument object. Put the code in a
//loop if you want to add headers in multiple pages
HtmlToPdf.Options.OutputArea = new System.Drawing.RectangleF(0, 0, 8.5f, 1);
HtmlToPdf.ConvertUrl(header_url, doc.Pages[0]);
//Save the result
doc.Save(final_file_name);
Hope this helps. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 2/13/2014 Posts: 3
|
Somewhat suboptimal to make an HTTP round trip for each page (well two, once for header and once for footer).
Thanks for the answer.
|
|
Rank: Newbie Groups: Member
Joined: 2/13/2014 Posts: 3
|
I implemented your suggestion and it has two problems -
1) SLOOOOOWW. I have a 20page document and having to go to the server 2 more times for each page is bad. 2) The {page_number} directive does not work so I would need to write more code
In the end I have had to read the HTML for the header and footer templates myself and set this in HtmlToPdf.Options.[Header|Footer]HtmlFormat.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
Yes. That's why rendering header and footer from Url may not be such a good idea at all. The fastest way to render header and footer is to use the Acm interface (PDF creator). EO.Pdf provide two set of interfaces: HTML to PDF and ACM. HTML to PDF is very powerful but it carries a much larger overhead. So it is suitable to render main contents where you run it once and it takes care of everything. ACM only has limited formatting capabilities but it is much more light weight thus is much faster. So it is very suitable to render relatively simple contents such as header and footer. However ACM requires more coding. So if performance is a major concern for you, then you may want to take a look of the samples and documentations for the ACM interface. Of course, if your header and footer must be HTML, then your current solution might be the best solution.
Thanks!
|
|