Merge PNG Images to PDF in PHP

Arrange PNG images on a slide and export the result as PDF with Aspose.Slides for PHP via Java.

Merge PNG to PDF in PHP

Load the source files with Images::fromFile, add them to the slide with addPictureFrame, and save the presentation with SaveFormat::Pdf.

PHP code for merging PNG to PDF

$presentation = new Presentation();
try {
    $slide = $presentation->getSlides()->get_Item(0);

    $firstSourceImage = Images::fromFile("image1.png");
    try {
        $firstPresentationImage = $presentation->getImages()->addImage($firstSourceImage);
    } finally {
        $firstSourceImage->dispose();
    }

    $secondSourceImage = Images::fromFile("image2.png");
    try {
        $secondPresentationImage = $presentation->getImages()->addImage($secondSourceImage);
    } finally {
        $secondSourceImage->dispose();
    }

    $slide->getShapes()->addPictureFrame(
        ShapeType::Rectangle, 0, 0, 360, 540, $firstPresentationImage);
    $slide->getShapes()->addPictureFrame(
        ShapeType::Rectangle, 360, 0, 360, 540, $secondPresentationImage);

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

Merge PNG to PDF using Aspose.Slides

Aspose.Slides for PHP via Java lets you place multiple PNG images in a custom layout on a presentation slide and export the composed slide as a single PDF file.

How to merge PNG images to PDF in PHP

Follow these steps to merge multiple PNG images into a PDF in PHP.

  1. Install Aspose.Slides for PHP via Java. See Installation.
  2. Configure Aspose.Slides in your PHP project.
  3. Create a Presentation instance and access its first slide through a variable.
  4. Load the PNG images with Images::fromFile and place them on the slide with addPictureFrame.
  5. Call save with the output file path and SaveFormat::Pdf.

Built with Aspose.Slides

Merge PNG to PDF Online

The free Aspose.Slides Merger app is built with Aspose.Slides for PHP via Java, the same API as the code above. Open it and see what the API can do with your own PNG files.

  • Runs in your browser, nothing to install.
  • See how Aspose.Slides merges files before you write code.
  • Upload several PNG files and combine them into one PDF file.
  • Download the merged result as one file.

Merge Other Files

You can also combine files in other supported formats.