Convert JPG to PDF in PHP

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

Convert JPG to PDF using PHP

To convert JPG to PDF, create a Presentation, add the image with addPictureFrame, and call save with SaveFormat::Pdf.

PHP code for converting JPG into PDF

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

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

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

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

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

Convert JPG to PDF in PHP

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

Aspose.Slides can export JPG-based slides to PDF, PowerPoint, HTML, and other supported formats.

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

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

  1. Install Aspose.Slides for PHP via Java.
  2. Configure Aspose.Slides in your PHP project.
  3. Create a Presentation, access its first slide, and load the JPG file with Images::fromFile.
  4. Add the JPG image with addPictureFrame, then save the presentation with SaveFormat::Pdf.

Built with Aspose.Slides

Convert JPG to PDF Online

The free Aspose.Slides Conversion 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 JPG files.

  • Runs in your browser, nothing to install.
  • See how Aspose.Slides converts files before you write code.
  • Upload JPG files and save them as PDF.
  • Download the result or convert more files.

Convert JPG To Other Supported Formats

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