officefileapi-405409-presentation-api-export-presentation.md
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");
}
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
'...
presentation.ExportToPdf("C:\Documents\Presentation_upd.pdf")
End Using
Create the PdfExportOptions object and pass it as an Presentation.ExportToPdf method parameter to specify PDF export options. The following settings are available:
The PdfExportOptions.EncryptionOptions property contains security options. You can protect the exported PDF file with a password, encryption algorithm, and operation restrictions.
To prevent unauthorized access to a document, define the UserPassword parameter of the EncryptionOptions constructor. 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:
To apply restrictions, define the OwnerPassword parameter of the EncryptionOptions constructor. 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 System.IO;
using (var presentation = new Presentation(File.ReadAllBytes(@"C:\Documents\Presentation.pptx"))) {
var options = new PdfExportOptions();
// Initialize encryption options with owner and user passwords:
options.EncryptionOptions = new EncryptionOptions(
ownerPassword: "ownerPassword",
userPassword: "userPassword"
);
// Specify operation restrictions:
options.EncryptionOptions.DataExtractionPermissions =
DocumentDataExtractionPermissions.NotAllowed;
options.EncryptionOptions.PrintPermissions =
DocumentPrintPermissions.LowQuality;
options.EncryptionOptions.ModificationPermissions =
DocumentModificationPermissions.NotAllowed;
// Specify encryption algorithm:
options.EncryptionOptions.Algorithm = EncryptionAlgorithm.AES256;
presentation.ExportToPdf(
new FileStream(@"C:\Documents\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite),
options
);
}
Imports DevExpress.Docs.Pdf
Imports DevExpress.Docs.Presentation
Imports DevExpress.Docs.Presentation.Export
Imports System.IO
Using presentation As New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
Dim options As New PdfExportOptions()
' Initialize encryption options with owner and user passwords:
options.EncryptionOptions = New EncryptionOptions(
ownerPassword:="ownerPassword",
userPassword:="userPassword"
)
' Specify operation restrictions:
options.EncryptionOptions.DataExtractionPermissions =
DocumentDataExtractionPermissions.NotAllowed
options.EncryptionOptions.PrintPermissions =
DocumentPrintPermissions.LowQuality
options.EncryptionOptions.ModificationPermissions =
DocumentModificationPermissions.NotAllowed
' Specify encryption algorithm:
options.EncryptionOptions.Algorithm = EncryptionAlgorithm.AES256
presentation.ExportToPdf(
New FileStream("C:\Documents\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite),
options
)
End Using
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 = "[email protected]";
options.SignatureOptions.Reason = "Approved";
presentation.ExportToPdf(new FileStream("C:\\Documents\\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite), options);
}
Imports DevExpress.Docs.Presentation
Imports DevExpress.Docs.Presentation.Export
Imports System.Security.Cryptography.X509Certificates
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
Dim 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 = "[email protected]"
options.SignatureOptions.Reason = "Approved"
presentation.ExportToPdf(new FileStream("C:\\Documents\\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite), options)
End Using
The PdfExportOptions class has the following image optimization options:
ConvertImagesToJpegSet this property to true to convert bitmap images into JPEG and reduce the file size.ImageQualityDefines 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.RasterizeImagesSpecifies whether to rasterize vector images.PdfExportOptions.RasterizationResolutionDefines 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);
}
Imports DevExpress.Docs.Pdf
Imports DevExpress.Docs.Presentation
Imports DevExpress.Docs.Presentation.Export
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
Dim 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)
End Using
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);
}
Imports DevExpress.Docs.Pdf
Imports DevExpress.Docs.Presentation
Imports DevExpress.Docs.Presentation.Export
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
Dim attachment = New Attachment()
attachment.Data = File.ReadAllBytes("C:\Documents\test.pdf")
attachment.Relationship = AttachmentRelationship.Supplement
attachment.FileName = "attachment.pdf"
attachment.CreationDate = Date.Now
attachment.Type = "application/pdf"
Dim options As New PdfExportOptions()
options.Attachments.Add(attachment)
presentation.ExportToPdf(new FileStream("C:\Documents\Presentation.pdf", FileMode.Create, FileAccess.ReadWrite), options)
End Using
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);
}
Imports DevExpress.Docs.Presentation
Imports DevExpress.Docs.Presentation.Export
'...
Using presentation = New Presentation(File.ReadAllBytes("C:\Documents\Presentation.pptx"))
Dim 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)
End Using
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:
PDF/A and PDF/UA compatibility options are not available.
The following ModificationPermissions and InteractivityPermissionsproperty value combinations are not supported: