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.