MSPowerPoint_SaveAsPDF

Microsoft provides add-ins to the Office products to support saving into PDF or XPS file formats. These add-ins include an API to perform this as well.

The add-ins may be found at:
Save as PDF: http://www.microsoft.com/downloads/details.aspx?FamilyId=F1FC413C-6D89-4F15-991B-63B07BA5F2E5&displaylang=en
Save as XPS: http://www.microsoft.com/downloads/details.aspx?FamilyId=BCE8F991-F0A4-47A0-866B-2FD84A329E02&displaylang=en
Save as PDF or XPS (single package): http://www.microsoft.com/downloads/details.aspx?FamilyId=4D951911-3E7E-4AE6-B059-A2E79ED87041&displaylang=en

Once installed, add a reference to the Microsoft.Office.Interop.[product]
Note: multiple product versions are available as references: version 12 = Office 2007, version 11 = Office 2003
Language:
C#
Keywords:
Office
Code Snippet

using System;
using System.IO;
using MSPowerPoint = Microsoft.Office.Interop.PowerPoint;

/***
* must install: addin for SaveAsPDF for Office 2007
* must add COM references for Microsoft.Office.Interop.PowerPoint, Office
***/

public void MakePowerPointPDF(string SourceDoc, string DestDoc)
{
    //for all missing types.
    object Unknown = Type.Missing;

    MSPowerPoint.
Application newPowerpointAppn = new Microsoft.Office.Interop.PowerPoint.Application();

    MSPowerPoint.
Presentation newpresentation = null;

    Microsoft.Office.Core.
MsoTriState openReadOnly = Microsoft.Office.Core.MsoTriState.msoTrue;
    Microsoft.Office.Core.
MsoTriState openHasTitle = Microsoft.Office.Core.MsoTriState.msoFalse;
    Microsoft.Office.Core.
MsoTriState openWithWindow = Microsoft.Office.Core.MsoTriState.msoFalse;

    newpresentation = newPowerpointAppn.Presentations.Open(SourceDoc, openReadOnly, openHasTitle, openWithWindow);

    //specify the format.
    //           PpSaveAsFileType paramExportFormat = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsXPS;
    //           PpSaveAsFileType paramExportFormat = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsXMLPresentation;
    MSPowerPoint.PpSaveAsFileType paramExportFormat = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;

    // Save it in the target format.
    Microsoft.Office.Core.MsoTriState saveEmbedTrueTypeFonts = Microsoft.Office.Core.MsoTriState.msoTrue;
    newpresentation.SaveAs(DestDoc, paramExportFormat, saveEmbedTrueTypeFonts);

    newPowerpointAppn.Quit();
}

 


Created 2012-02-11
comments powered by Disqus
Login