Skip to main content
All docs
V25.1
  • Export Loaded or Generated Presentation with DevExpress Presentation API Library

    • 6 minutes to read

    The DevExpress Presentation API library allows you to export generated or loaded PPTX presentations to PDF files.

    Call the Presentation.ExportToPdf method to export the presentation to a PDF file or stream.

    using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx"))) {
      //...
      presentation.ExportToPdf("C:\\Documents\\Presentation_upd.pdf");
    }
    

    Specify PDF Export Options

    Create the PdfExportOptions object and pass it as an Presentation.ExportToPdf method parameter to specify PDF export options. The following settings are available:

    Security Settings

    The PdfExportOptions.EncryptionOptions property contains security options. You can protect the exported PDF file with a password, encryption algorithm, and operation restrictions.

    Specify the UserPassword property to prevent unauthorized access to a document. The Algorithm property allows you to specify the encryption algorithm.

    A PDF file can be protected by a user password (restricts access) and an owner password (restricts available operations).

    If a user inputs the correct password or the document is not protected by a password, you can still perform only permitted operations.

    Use the following options to restrict data extraction, data modification, interactive, or printing operations:

    Specify the EncryptionOptions.OwnerPassword property to apply restrictions. If the user wants to get full access to document operations, they need to enter the owner password when opening the document.

    Note

    If the Owner and User passwords are the same or the Owner password is missing and the document is protected only with a User password, entering the password opens the document and allows full access to all operations.

    The following code snippet specifies available encryption settings:

    using DevExpress.Docs.Pdf;
    using DevExpress.Docs.Presentation;
    using DevExpress.Docs.Presentation.Export;
    
    using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx")))
    {
        var options = new PdfExportOptions();
        // Specify operation restrictions:
        options.EncryptionOptions.DataExtractionPermissions =
            DocumentDataExtractionPermissions.NotAllowed;
        options.EncryptionOptions.PrintPermissions =
            DocumentPrintPermissions.LowQuality;
        options.EncryptionOptions.ModificationPermissions = DocumentModificationPermissions.NotAllowed;
    
        // Set user and owner passwords:
        options.EncryptionOptions.UserPassword = "userPassword";
        options.EncryptionOptions.OwnerPassword = "ownerPassword";
    
        // Specify encryption algorithm:
        options.EncryptionOptions.Algorithm = EncryptionAlgorithm.AES256;
    
        presentation.ExportToPdf(new FileStream("C:\\Documents\\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite), options);
    }
    

    Signature Settings

    The SignatureOptions class members allow you to apply a signature to the exported PDF file. Use the PdfExportOptions.SignatureOptions property to obtain these options.

    The following code snippet signs the exported PDF file:

    using DevExpress.Docs.Presentation;
    using DevExpress.Docs.Presentation.Export;
    using System.Security.Cryptography.X509Certificates;
    //...
    using (var presentation = new Presentation(File.ReadAllBytes("C:\\Documents\\Presentation.pptx")))
    {
      var options = new PdfExportOptions();
      options.SignatureOptions.Certificate = new X509Certificate2(@"..\..\..\SignDemo.pfx", "dxdemo");
      options.SignatureOptions.HashAlgorithm = DevExpress.Docs.Pdf.HashAlgorithm.SHA256;
      options.SignatureOptions.ImageData = File.ReadAllBytes("..\\..\\..\\image.emf");
    
      options.SignatureOptions.Location = "USA";
      options.SignatureOptions.ContactInfo = "john.smith@example.com";
      options.SignatureOptions.Reason = "Approved";
    
      presentation.ExportToPdf(new FileStream("C:\\Documents\\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite), options);
    }
    

    Image Optimization Settings

    The PdfExportOptions class has the following image optimization options:

    ConvertImagesToJpeg
    Set this property to true to convert bitmap images into JPEG and reduce the file size.
    ImageQuality
    Defines the image quality for all images in the PDF file. This property is in effect only if the ConvertImagesToJpeg property is set to true.
    PdfExportOptions.RasterizeImages
    Specifies whether to rasterize vector images.
    PdfExportOptions.RasterizationResolution
    Defines the resolution (in DPI) used to rasterize vector images. This resolution is used only if the RasterizeImages property is set to true.

    The following code snippet specifies available image optimization settings:

    using DevExpress.Docs.Pdf;
    using DevExpress.Docs.Presentation;
    using DevExpress.Docs.Presentation.Export;
    
    using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx")))
    {
        var options = new PdfExportOptions();
        options.RasterizeImages = true;
        options.RasterizationResolution = 96;
        options.ConvertImagesToJpeg = true;
        options.ImageQuality = DevExpress.Docs.Pdf.ImageQuality.Medium;
    
        presentation.ExportToPdf(new FileStream("C:\\Documents\\Presentation_upd.pptx", FileMode.Create, FileAccess.ReadWrite), options);
    }
    

    Attachment Settings

    The PdfExportOptions.Attachments property obtains the list of attached files. Each item in the list is the Attachment object. Create an Attachment instance and pass it as the Attachments.Add method parameter to attach a file.

    The following code snippet attaches a PDF file to the exported presentation:

    using DevExpress.Docs.Pdf;
    using DevExpress.Docs.Presentation;
    using DevExpress.Docs.Presentation.Export;
    //...
    using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx")))
    {
        var attachment = new Attachment();
        attachment.Data = File.ReadAllBytes(@"C:\Documents\test.pdf");
        attachment.Relationship = AttachmentRelationship.Supplement;
        attachment.FileName = "attachment.pdf";
        attachment.CreationDate = DateTime.Now;
        attachment.Type = "application/pdf";
    
        PdfExportOptions options = new PdfExportOptions();
        options.Attachments.Add(attachment);
    
        presentation.ExportToPdf(new FileStream("C:\\Documents\\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite), options);
    }
    

    Document Properties

    The PdfExportOptions.DocumentOptions property allows you to specify metadata (or document properties) that describe the PDF file and its contents.

    The following code snippet specifies available document properties:

    using DevExpress.Docs.Presentation;
    using DevExpress.Docs.Presentation.Export;
    //...
    
    using (var presentation = new Presentation(File.ReadAllBytes("C:\\Documents\\Presentation.pptx")))
    {
        var options = new PdfExportOptions();
        options.DocumentOptions.Author = "Simon Peacock";
        options.DocumentOptions.Application = "DevExpress Presentation API";
        options.DocumentOptions.Keywords = "Presentation, DevExpress, Exported, PDF";
        options.DocumentOptions.Producer = "Developer Express Inc., 25.1.3.0";
        options.DocumentOptions.Subject = "Test Presentation";
        options.DocumentOptions.Title = "Presentation Title";
        presentation.ExportToPdf(new FileStream("C:\\Documents\\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite), options);
    }
    

    Limitations

    The DevExpress Presentation API library ships with the following PDF export limitations:

    • All presentation content is exported as an image, so the PdfExportOptions.NonEmbeddedFonts property has no effect.
    • The Presentation API library does not export certain presentation elements to PDF:
      • Tables
      • SmartArt diagrams
      • Chart
      • Comments
    • PDF/A and PDF/UA compatibility options are not available.
    • The following ModificationPermissions and InteractivityPermissionsproperty value combinations are not supported:

      ModificationPermissions = PdfDocumentModificationPermissions.Allowed;
      InteractivityPermissions = PdfDocumentInteractivityPermissions.NotAllowed;
      
      ModificationPermissions = PdfDocumentModificationPermissions.DocumentAssembling;
      //...or...
      ModificationPermissions = PdfDocumentModificationPermissions.Allowed;
      InteractivityPermissions = PdfDocumentInteractivityPermissions.FormFillingAndSigning;
      
      ModificationPermissions = PdfDocumentModificationPermissions.DocumentAssembling;
      InteractivityPermissions = PdfDocumentInteractivityPermissions.Allowed;