I'm using ABCpdf 9.1 x64 .Net with Coldfusion to create PDF's based on HTML content. Each PDF document has a different header and footer which are generated as HTML with some Coldfusion code. The header is identical for every page where the footer is slightly different for every page (because it shows the page number). Here's the main part of my code:
// add content
theDoc.Get_Rect().Set_String("67 80 573 742");
theContentID = theDoc.AddImageHTML(pdfContent);
while (true) {
if (!theDoc.Chainable(theContentID)) {
break;
}
theDoc.Set_Page(theDoc.AddPage());
theContentID = theDoc.AddImageToChain(theContentID);
}
// add header & footer on each page
for (i=1; i <= theDoc.Get_PageCount(); i++) {
// set page
theDoc.Set_PageNumber(i);
// HEADER
theDoc.Get_Rect().Set_String("67 755 573 809");
theDoc.AddImageHTML(headerContent);
// FOOTER
theDoc.Get_Rect().Set_String("67 0 573 65");
theDoc.AddImageHTML(replace(footerContent, "[page]", i));
}
As you can see, the AddImageHTML()
method gets called 2 times for every page and once for the content. So if I have content which creates 6 pages, the method gets called 13 times. This isn't ideal because the method consums a lot of time.
Is there a more efficient way to add a header and footer from HTML? There's a method AddImageCopy()
but it doesn't work with objects created by AddImageHtml()
.
Just for understandig: Those getter and setter methods are created by Coldfusion to access .Net properties.
If your HTML is relatively simple and does not rely on CSS, you can perhaps tweak it to HTML Styled text and use use
AddHtml
instead ofAddImageHtml
.AddHtml
should perform much faster thanAddImageHtml
. As a side benefit you will be able to use referenced (not system-installed) fonts and CMYK colors if necessary.Since your header is identical on every page, perhaps you could use
AddImageHtml
on a secondaryDoc
object, then add that as an image on each page. This would cut the calls for the header from one per page to one only per file.Since the footer is different on each page, I don't see how you can avoid a call to something on each page.