views:

375

answers:

1

It seems (at least that is our understanding of the issue at this point) that given a background image in BIRT, the PDF generation routine repeats the image information inside the PDF instead of having it once referenced as the background image of all pages of the PDF.

This causes our BIRT generated PDFs to be too large. Is there a way to get BIRT to only store the image once inside the PDF and have it be the background image on each page of the PDF while keeping the file size more reasonable?

+2  A: 

Yes, BIRT will create a new incarnation of the same background image for each page. Unfortunately this is too deeply buried in org/eclipse/birt/report/engine/emitter/pdf/PDFPage.java to easily hack around nicely, and is most definitely not configurable.

But despair not! You can use iText (the same iText used internally by BIRT) to eliminate duplicate entities with PdfSmartCopy. Something along the lines of:

PdfReader reader  = new PdfReader(PDF_IN_FROM_BIRT);
Document document = new Document();
PdfSmartCopy copy = new PdfSmartCopy(document,
  new FileOutputStream(PDF_OUT_NO_DUPLICATES));
document.open();
for (int page = 1; page <= reader.getNumberOfPages(); page++) {
  copy.addPage(copy.getImportedPage(reader, page));
}
document.close();

If the above is not acceptable, then you can patch com.itextpdf.text.Image.getInstance(URL) to behave in a singleton-like manner, returning an existing com.itextpdf.text.Image object if the image had already been obtained from the same URL in the past. You can patch and rebuild the iText JAR used by BIRT, or use Javassist to perform code injection at runtime without a need for recompilation.

Cheers, V.

vladr
Thanks Vlad, PdfSmartCopy was a workaround that worked well for us.
Yishai