[Solved] convert image inputstream to pdf inputstream – Java


Some ideas may be useful instead of all the comments.. 🙂

At the risk of stating the obvious, do it in steps. For example …

  1. Use avax.imageio.ImageIO to create a java.awt.image.BufferedImage

  2. Wrap it as a com.itextpdf.text.Image

  3. Embed it in a com.itextpdf.text.PdfDocument

  4. Use com.itextpdf.text.DocumentWriter to write the com.itextpdf.text.PdfDocument to a java.io.ByteArrayOutputStream

  5. Get the byte[] and wrap it in a java.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