printpdf icon indicating copy to clipboard operation
printpdf copied to clipboard

Is it possible to reuse an inserted image?

Open lucidBrot opened this issue 5 years ago • 2 comments

I am generating a large pdf where every page consists of the same layout with only the text varying. Is it possible to insert the bitmap only once in order to speed up generation of the file?

specifically, I'm currently using add_to_layer once per page. And noticed that when I use a bitmap of smaller size, the speedup is enormous. However, I understand the documentation so that perhaps this is a limitation of the PDF format?

Adds the image to a specific layer and consumes it This is due to a PDF weirdness - images are basically just "names" and you have to make sure that they are added to the same page as they are used on.

And printpdf::types::plugins::graphics::two_dimensional::image::Image::add_to_layer consumes the image.

So if you would be so kind to tell me whether it is technically possible, I might try to read up on that and create a PR if it is :) Thank you so much for the time you invested into this library!

lucidBrot avatar Nov 17 '19 21:11 lucidBrot

It is technically possible, but it can lead to hard to debug mistakes. The "name" for the ImageXObject has to be added to the page, otherwise the PDF will show an error - and it's not yet possible to check whether that's the case using the printpdf API.

It's more of an API mistake, but right now I'm not going to fix it, because I'm way too busy with other stuff. I'm also generally not happy with how I designed the API two years ago - I'll maybe fix it in a 0.3 version, but that will take a few years.

fschutt avatar Nov 18 '19 19:11 fschutt

Okay, I take this as a "It's possible but don't try to do it if it is not really really important" 👍 Thanks for your surprisingly quick answer, have a nice evening!

lucidBrot avatar Nov 18 '19 20:11 lucidBrot