Back to Devexpress

How to: Export a PDF Page to an SVG Image

officefileapi-405230-pdf-document-api-examples-export-a-pdf-document-to-an-image-how-to-export-a-pdf-page-to-an-svg-image.md

latest2.3 KB
Original Source

How to: Export a PDF Page to an SVG Image

  • Nov 08, 2024
  • 2 minutes to read

Important

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use these examples in production code.

Follow the steps below to export a PDF page to SVG:

  • Create a PdfDocumentProcessor instance and call the LoadDocument method to load a file.
  • Call the PdfDocumentProcessor.CreateSvgImage method, and pass the page number and the largestEdgeLength parameter (measured in pixels) as parameters. The largestEdgeLength parameter determines the output image’s height for pages in the portrait orientation and width for landscape pages.

The following code snippet exports each page in a PDF document as SVG images:

csharp
using DevExpress.Drawing;
using DevExpress.Pdf;

int largestEdgeLength = 1000;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    // Load a document
    processor.LoadDocument("..\\..\\Document.pdf");

    for (int i = 1; i <= processor.Document.Pages.Count; i++)
    {

        // Export pages to SVGs
        DXImage image = processor.CreateSvgImage(i, largestEdgeLength);

        // Save the images
        image.Save("..\\..\\MySvg" + i + ".svg", DXImageFormat.Svg);
    }
}
vb
Imports DevExpress.Drawing
Imports DevExpress.Pdf

Private largestEdgeLength As Integer = 1000

Using processor As New PdfDocumentProcessor()
    ' Load a document
    processor.LoadDocument("..\..\Document.pdf")

    For i As Integer = 1 To processor.Document.Pages.Count

        ' Export pages to SVGs
        Dim image As DXImage = processor.CreateSvgImage(i, largestEdgeLength)

        ' Save the images
        image.Save("..\..\MySvg" & i & ".svg", DXImageFormat.Svg)
    Next i
End Using

Limitations

The SVG export has the following limitations:

  • Font embedding is not supported.
  • Patterns and shadings are not supported.
  • Limited transparency support