So basically I want to show a BufferedImage on a PDF-Document using Java and PDFBox. There was a way using this method (Add BufferedImage to PDFBox 2.0 document) but it seems to be deprecated. Is there any new way to show a BufferedImage on a PDocument?
Asked
Active
Viewed 153 times
0
-
1Where do you see deprecation of the methods I referenced in my answer to the question you linked? – mkl Aug 08 '22 at 09:46
-
1please take a look into this psot if its helpfull https://stackoverflow.com/questions/7055485/add-bufferedimage-to-pdfbox-document – Suvam Banerjee Aug 08 '22 at 10:44
-
Try also `LosslessFactory.createFromImage(PDDocument document, BufferedImage image)` if your image is something with sharp edges. If your image is a photograph, then use the `JPEGFactory` methods. (Another case is black/white images but I'm skipping that one) – Tilman Hausherr Aug 08 '22 at 11:09
-
the "createFromImage()" method doesnt exist anymore – impressive-eggplant Aug 08 '22 at 11:10
-
Thank you Tilman Hausherr your answer worked for me :) – impressive-eggplant Aug 08 '22 at 11:16
-
1I'm wondering why it didn't work the first time, i.e. why did you think that it "doesnt exist anymore"? – Tilman Hausherr Aug 08 '22 at 12:22
-
because the "createFromImage()" method doesnt belong or exist in the PDImageXObject class since like 2017. It seems to be refactored and is now in the LossLessFactory – impressive-eggplant Aug 08 '22 at 12:55
1 Answers
1
Try also LosslessFactory.createFromImage(PDDocument document, BufferedImage image)
if your image is something with sharp edges. If your image is a photograph, then use the JPEGFactory
methods.

Tilman Hausherr
- 17,731
- 7
- 58
- 97