Merge Images to PDF in PHP

Place multiple images on separate slides and export them as a single PDF document with Aspose.Slides for PHP via Java.

Merge Images to PDF in PHP

Load each source file with Images::fromFile, add a slide with addEmptySlide, place the image with addPictureFrame, and call save with SaveFormat::Pdf.

PHP code for merging images into PDF

$presentation = new Presentation();
try {
    $presentation->getSlides()->removeAt(0);
    $layoutSlide = $presentation->getLayoutSlides()->get_Item(0);

    $imagePaths = ["image1.png", "image2.jpg"];
    foreach ($imagePaths as $imagePath) {
        $slide = $presentation->getSlides()->addEmptySlide($layoutSlide);

        $sourceImage = Images::fromFile($imagePath);
        try {
            $presentationImage = $presentation->getImages()->addImage($sourceImage);
        } finally {
            $sourceImage->dispose();
        }

        $slide->getShapes()->addPictureFrame(
            ShapeType::Rectangle, 0, 0, 720, 540, $presentationImage);
    }

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

Merge Images to PDF using Aspose.Slides

Aspose.Slides for PHP via Java lets you place each source image on a separate presentation slide and export all the slides as a single multi-page PDF document.

How to merge images to 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, remove its default slide, and access a layout slide.
  4. Load each source image with Images::fromFile, add an empty slide with addEmptySlide, and place the image with addPictureFrame.
  5. Save the presentation with SaveFormat::Pdf.

Built with Aspose.Slides

Merge Image 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 Image files.

  • Runs in your browser, nothing to install.
  • See how Aspose.Slides merges files before you write code.
  • Upload several Image 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.