Convert PNG to PDF in PHP

Place a PNG image on a presentation slide and export the result as PDF with Aspose.Slides for PHP via Java.

Convert PNG to PDF using PHP

Create a Presentation, load the PNG with Images::fromFile, match the slide size to the image with setSize, add the image with addPictureFrame, and call save with SaveFormat::Pdf.

PHP code for converting PNG into PDF

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

    $sourceImage = Images::fromFile("input.png");
    try {
        $embeddedImage = $presentation->getImages()->addImage($sourceImage);
    } finally {
        $sourceImage->dispose();
    }

    $imageWidth = java_values($embeddedImage->getWidth());
    $imageHeight = java_values($embeddedImage->getHeight());

    $presentation->getSlideSize()->setSize(
        $imageWidth, $imageHeight, SlideSizeScaleType::DoNotScale);

    $slide->getShapes()->addPictureFrame(
        ShapeType::Rectangle, 0, 0, $imageWidth, $imageHeight, $embeddedImage);

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

Convert PNG to PDF in PHP

Aspose.Slides for PHP via Java lets you place a PNG image on a presentation slide at its original dimensions and export the result as a PDF document.

The PNG remains embedded as an image on the slide, while SaveFormat::Pdf exports the complete presentation to PDF.

How to convert PNG to PDF using Aspose.Slides for PHP API

These are the steps to convert PNG to PDF in PHP.

  1. Install Aspose.Slides for PHP via Java.
  2. Create a Presentation, access its first slide, and load the PNG with Images::fromFile.
  3. Set the slide dimensions with setSize, then place the image on the slide with addPictureFrame.
  4. Call save with the output file path and SaveFormat::Pdf.

Free Online Converter

Try our free Conversion app

Convert PNG To Other Supported Formats

You can also convert PNG and save to other file formats. See all supported formats below: