Images To PDF
Developers can use IronPDF to combine multiple images into a single PDF document.
The PdfDocument.fromImage
method accepts a list of Path
objects, each of which reference a valid path to an image stored on a local file system. This gives the developer a lot of freedom in specificity. He can build this list to include groups of images spanning multiple directories, to include images matching specific naming or typing criteria, etc. In the case where the images are sourced from the same directory (as is the case in the above code example), the developer can simply utilize a DirectoryStream
among other java.nio.file
classes to quickly build up a list of all the images contained in the directory.
PdfDocument.fromImage
will render each image referenced in the list on a separate page in the PDF document.
If the images need to be placed in separate PDF documents (not combined into one), then developers can do either of the following:
- Iteratively call
PdfDocument.fromImage
using lists containing only one Path object (e.g.PdfDocument.fromImage(new ArrayList<>().add(Paths.get("path/to/single/image.png"))
); - Combine all images into one PDF document as shown in the above code example, and then copy each page into new PDF documents with the
PdfDocument.copyPage
method.