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 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.
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();
}
How to convert PNG to PDF using Aspose.Slides for PHP API
These are the steps to convert PNG to PDF in PHP.
Install Aspose.Slides for PHP via Java .
Create a
Presentation, access its first slide, and load the PNG withImages::fromFile.Set the slide dimensions with
setSize, then place the image on the slide withaddPictureFrame.Call
savewith the output file path andSaveFormat::Pdf.
Free Online Converter
Convert PNG To Other Supported Formats
You can also convert PNG and save to other file formats. See all supported formats below: