Convert PDF to SVG in PHP

Import PDF pages and export them as SVG images with Aspose.Slides for PHP via Java

Convert PDF to SVG in PHP

Use Aspose.Slides for PHP via Java to import the pages of a PDF document as slides and export each slide as an SVG image.

Call addFromPdf to import the PDF pages, then call writeAsSvg for each slide. You can also test PDF conversion in your browser .

You can install the library from Composer using the following command:

Console/Terminal

composer require aspose/slides

Save PDF as SVG in PHP

Use the free app to see a demonstration of the PDF-to-SVG conversion process.

This sample code shows PDF to SVG PHP Conversion

$presentation = new Presentation();
try {
    $presentation->getSlides()->removeAt(0);
    $presentation->getSlides()->addFromPdf("document.pdf");

    $slideCount = java_values($presentation->getSlides()->size());
    for ($slideIndex = 0; $slideIndex < $slideCount; $slideIndex++) {
        $slide = $presentation->getSlides()->get_Item($slideIndex);
        $filePath = "slide_" . ($slideIndex + 1) . ".svg";
        $outputStream = new Java("java.io.FileOutputStream", $filePath);

        try {
            $slide->writeAsSvg($outputStream);
        } finally {
            $outputStream->close();
        }
    }
} finally {
    $presentation->dispose();
}

How to Convert PDF to SVG in PHP

These are the steps to convert a PDF file to SVG using PHP.

  1. Create a Presentation, remove its default slide, and import the PDF pages with addFromPdf.
  2. Access each slide through a variable and create an output stream for its SVG file.
  3. Call writeAsSvg with the output stream.

System Requirements

Before running the PHP conversion example, make sure that you have the following prerequisites.

  1. Install PHP 7 or later, add the PHP directory to the system PATH, and set allow_url_include to On in the php.ini file.
  2. Install JRE 8 and set the JAVA_HOME environment variable to the installed JRE directory.
  3. Install and configure Apache Tomcat 8.0 with PHP/Java Bridge as described in the installation guide .

Built with Aspose.Slides

Convert PDF to SVG 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 PDF files.

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