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 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.

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();
}

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.

Merge Images Online

Try the free Aspose.Slides Merger

Merge Other Files

You can also combine files in other supported formats.