Some ideas may be useful instead of all the comments.. 🙂
At the risk of stating the obvious, do it in steps. For example …
-
Use
avax.imageio.ImageIO
to create ajava.awt.image.BufferedImage
-
Wrap it as a
com.itextpdf.text.Image
-
Embed it in a
com.itextpdf.text.PdfDocument
-
Use
com.itextpdf.text.DocumentWriter
to write thecom.itextpdf.text.PdfDocument
to ajava.io.ByteArrayOutputStream
-
Get the
byte[]
and wrap it in ajava.io.ByteArrayInputStream
It is theoretically possible to do the transformation without buffering the image in memory, but the existing APIs don’t support this. (You would have a lot of coding to do it in Java. It would be better to look for a standalone image-to-pdf conversion utility.)
You should be able to avoid the intermediate byte[]
buffer using a PipedOutputStream
/ PipedInputStream
pair.
2
solved convert image inputstream to pdf inputstream – Java