I need to create a PDF file automatically (preferable via a batch process / command-line, the optimum would be something XSLT/SAXON-based).

The PDF will have many pages (ca. 500), and each page contains nothing but a set of (partially overlapping) images (in scalable format, e.g. SVG or WMF).

But there is only a basic set of ~20 images used for this, and the various pages differ one from another only in the particular choice out of these 20 images.

The problem: If I use XSL-FO and feed it into the Apache FOP then the result is a PDF of approx. 300 MB file-size, because the image data is fed multiple times into the PDF.

Now I am looking for a possibility to create a PDF in a way such that the image data of these 20 images are present only once in the PDF, and each PDF-page uses only "links"/references to this set of image data (so that the resulting PDF-file has only ~2MB file-size).

I know that the PDF-language as such features such references, but of course, I am not interested to build a PDF-file directly, "low Level" ;-)

Any help/ideas would be highly appreciated! Thanks a lot!

3 Answers 3


Report Lab has both open source software to do this sort of thing, (from python), and paid for Report Lab Plus tool that you can use via their Report Markup Language (RML).

  • 1
    Thanks a lot for your answer! I installed and tested the open source variant, but unfortunately it turned out that only the paid variant supports scalable (vector) images. Well, in general I don't mind paying a fair fee for good software, but their only offer is to pay every year, i.e. an annual fee that even depends on the number of created PDF pages. Well, sorry, this is not an acceptable business model for me...
    – gawl
    Jan 11, 2017 at 11:32
  • @gawl svglib pypi.python.org/pypi/svglib may be a help as it can convert svg images to ReportLab Drawing objects. Jan 11, 2017 at 18:15

You can easily accomplish this with PDFTron PDFNet.

Image shared_img_object = Image.Create(doc, input_path + "peppers.jpg");
// then per page add image this way

Element element = builder.CreateImage(shared_img_object, new Matrix2D(sx, 0, 0, sy, dx, dy));

See the AddImage or ElementBuilder samples for more details.


Well, after all, I decided in favor of a well-known well-established tool, "(plain) pdfTeX". Its \pdfximage and \pdfrefximage macros offer exactly what I needed. (Of course, pdfTeX cannot handle SVG, but converting my SVG images to a set of PDF files was not a problem, especially since this needed to be done only once.) So, as a result, I have an XSLT now that converts my input XML to (plain) pdfTeX, and the whole conversion works amazingly fast on modern PCs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.