Merge PNG to PDF in Java

Use Aspose.Slides for Java to merge PNG images in Java applications.

Merge PNG to PDF using Aspose.Slides

Aspose.Slides for Java is a Java API for creating, editing, converting, and merging presentation content. You can place PNG images into a Presentation and save the combined slide as a PDF file.

Merge PNG to PDF in Java

Using Aspose.Slides for Java , you can merge PNG images and create a PDF result with a few lines of Java code.

Java code for merging PNG to PDF

Presentation presentation = new Presentation();
try {
    ISlide slide = presentation.getSlides().get_Item(0);

    byte[] firstImageData = Files.readAllBytes(Paths.get("image1.png"));
    IPPImage firstImage = presentation.getImages().addImage(firstImageData);
    slide.getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, 100, 100, firstImage);

    byte[] secondImageData = Files.readAllBytes(Paths.get("image2.png"));
    IPPImage secondImage = presentation.getImages().addImage(secondImageData);
    slide.getShapes().addPictureFrame(ShapeType.Rectangle, 0, 200, 100, 100, secondImage);

    presentation.save("merged.pdf", SaveFormat.Pdf);
} finally {
    presentation.dispose();
}

How to merge PNG images in Java

  1. Install Aspose.Slides for Java .

  2. Add the library as a reference in your project.

  3. Create a Presentation instance.

  4. Load the source PNG images with Files.readAllBytes and Paths.get.

  5. Save the presentation with SaveFormat.Pdf.

Merge Files Online

Merge presentations and slides online.