pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: Replacing images in PDFs.
Date Tue, 01 Sep 2015 16:31:01 GMT
Am 01.09.2015 um 11:26 schrieb Lachezar Dobrev:
>    Hello all.
>    I'm tasked with providing a service to generate PDFs from template PDFs
> by replacing text place holders and image place holders with data from a
> database.
> ​  For replacing text we decided to use Form Field​s to keep minimal effect
> on the page layout, and to avoid problems with texts being split into parts
> by the editor.
>    Replacing images is also achievable using
> COSStream.replaceWithStream(COSStream).
>    Q1: The replaceWithStream method is being deprecated. What can I use to
> do the same thing in PDFBox 2? I tried stream-copying, but I get a
> "WARNING: DCTFilter#encode is not implemented yet, skipping this stream."
> and the image disappears from the output file.

If you want to copy a JPEG, you should use createRawInputStream().

The JPEG should be of the same size and same colorspace than the 
original image.

Alternatively - just put nothing in the templare, and simply put an 
image of whatever size you want with traditional methods (see image 
handling in PDPageContentStream)

>    Q2: Is there any way to identify which image is what? Form fields have
> Mapping Name that I can use to detect which field needs to contain what,
> but I can not find a way to get some user-controllable identifier for an
> image. Any thoughts?

Images do have a name in the resources. So it should work if you do the 
template yourself.



To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org

View raw message