|
Rank: Newbie Groups: Member
Joined: 9/17/2013 Posts: 4
|
Hi I want to integrate a header and footer section on each page. As I cannot control the page-breaks on certain pages (because certain pages might contain a lot of content), I want to make sure that each page has its header and footer. Because the content of header and footer is dynamically generated by XSLT (XML to HTML) and contains dynamic content (document ID, date, name of document) I cannot rely on the documented
Code: Visual Basic.NET
EO.Pdf.HtmlToPdf.Options.HeaderHtmlFormat
EO.Pdf.HtmlToPdf.Options.FooterHtmlFormat
So I need a way to have the footer and header already present on each page in the HTML document which is being transformed into a PDF. In modern browser (IE9, IE10, Firefox, Chrome) it's no problem to have a
Code: CSS
.header {
position:fixed;
top:0.5cm;
height:2cm;
}
defined in the CSS. Printed this will put the header and footer on each page according to its fixed position, but not with EO.HTMLtoPDF. Does anybody know how to integrate dynamic heeader and footer? I have no way to manipulate header and footer content using C# or VB as the data for the document comes from a different source. Any help is much appreciated Bernhard
|
|
Rank: Newbie Groups: Member
Joined: 9/17/2013 Posts: 4
|
So this method does not work with EO.HTML2PDF: http://stackoverflow.com/questions/6664752/how-to-add-print-headers-and-footers-in-html-css-and-javascriptCan someone confirm this? I believe it has to do with @media="print" which is not recognised by EO.HTML2PDF.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi, No. We do not recognize media="print" because most of our users want the PDF to look exactly like what they see on the screen. So we always generate PDF as it appears on the screen. In order to create header and footer based on your own logic, you must write C#/VB code to do so. You would basically run the converter twice: the first time you generate the main content, then use a loop to add footer/header information. It will be something like this:
Code: C#
//Generate the main content
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl(url, doc);
//Now add footer/header
for (int i = 0; i < doc.Pages.Count; i++)
{
//Get the page object
PdfPage page = doc.Pages[i];
//Set the output area
HtmlToPdf.Options.OutputArea = ....
//Add additional contents to the page
HtmlToPdf.ConvertHtml(header_html, page);
}
The key is the second argument for the ConvertHtml call is a PdfPage object. Hope this helps. Please let us know if you still have any questions. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/17/2013 Posts: 4
|
Hi, Thanks for the reply... It's a pitty that you do not support media statements, as this makes it extremly difficult to generate properly designed "printlike"-PDFs.
However, your suggested method will not work in my case, as I have data in my header, that is not accessible within VB/C#. This is the process we use to generate the PDF:
XML-Data -> XSL(T) -> HTML -> EO.PDF
Because the EO.PDF runs as a webservice, the XML-Data is not available for the EO.PDF, therefore I cannot generate a header or footer which should contain data from the XML....
So the basic line is: it is not possible to create HTML-footer / header with EO.PDF, it is only possible to inject header and footer in an already existing HTML document, but not using content from this document for header and footer.
Kind regards Bernhard
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
Hi,
It's still possible if you are willing to write code. For example, you can use a different XSLT to generate header/footer data and then use code to add it. So it will be:
1. XML Data -> XSLT1 -> HTML -> EO.PDF (main contents) 2. XML Data -> XSLT2 -> header/footer data in whatever format you prefer -> EO.PDF (header/footer)
Or you can even use regular expression to search the HTML file generated in step 1 to get the header/footer data and then add them into the PDF. The bottom line is you have to write some code to do it. If you insist using media="print" without additional code, then no, it won't work.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/17/2013 Posts: 4
|
Okay, I see. I believe this could be a way to achieve it. I will try to follow your suggested process: Quote:1. XML Data -> XSLT1 -> HTML -> EO.PDF (main contents) 2. XML Data -> XSLT2 -> header/footer data in whatever format you prefer -> EO.PDF (header/footer) Which seems to solve most of my headaches... If you have a wishlist: then can I add the @media-selector to it? This would make it perfect for a lot of CSS3 features such as @page. And since a PDF generator has a lot of similiarities to a printer driver, you could really consider this option :-) Thanks for the very quick and prfound reply Bernhard
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,195
|
You are very welcome. And thank you very much for your suggestion!
|
|