ABCpdf copy header and footer

2k views Asked by At

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.

2

There are 2 answers

1
Ross Presser On BEST ANSWER
  1. 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 of AddImageHtml. AddHtml should perform much faster than AddImageHtml. As a side benefit you will be able to use referenced (not system-installed) fonts and CMYK colors if necessary.

  2. Since your header is identical on every page, perhaps you could use AddImageHtml on a secondary Doc 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.

  3. Since the footer is different on each page, I don't see how you can avoid a call to something on each page.

0
Tom Leuntjens On

I used this approach where the header is the same across all pages

doc.PageNumber = 1;
doc.Rect.Rectangle = headerRect; //headerrect should define the rect where the header is
doc.AddImageHtml(headerHtml);  //perform addimage html once

//repeat for other pages (clones the header. much faster than calling addImageHtml every time)
 for (int i = 1; i <= doc.PageCount; i++)
  {
    doc.PageNumber = i;
        doc.AddImageDoc(doc, 1, doc.Rect);
   }