none
How to convert Powerpoint .pptx to PDF document?

    Question

  • Hi,

    I am using Office Interop to convert powerpoint to pdf using save as functionality with below code. I have some issues with InterOp on some pcs where I get application is busy error.

    Is it possible to convert .pptx to .pdf using open xml sdk? if yese, please provide me some sample.

          public static void ConvertPPTtoPDF(string pptFile, string pdfFile)
            {

                try
                {
                    Microsoft.Office.Interop.PowerPoint.Application ppApp = new
                        Microsoft.Office.Interop.PowerPoint.Application();

                    Microsoft.Office.Interop.PowerPoint.Presentation presentation = ppApp.Presentations.Open
                        (pptFile, Microsoft.Office.Core.MsoTriState.msoTrue,
                            Microsoft.Office.Core.MsoTriState.msoFalse,
                            Microsoft.Office.Core.MsoTriState.msoFalse);
                    presentation.ExportAsFixedFormat(pdfFile,

                                    PPT.PpFixedFormatType.ppFixedFormatTypePDF,

                                    PPT.PpFixedFormatIntent.ppFixedFormatIntentPrint,

                                    Microsoft.Office.Core.MsoTriState.msoFalse,

                                    PPT.PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst,

                                    PPT.PpPrintOutputType.ppPrintOutputSlides,

                                    Microsoft.Office.Core.MsoTriState.msoFalse,

                                    null,

                                    PPT.PpPrintRangeType.ppPrintAll,

                                    "",

                                    false,

                                    false,

                                    false,

                                    true,

                                    true,

                                    System.Reflection.Missing.Value);

                    presentation.Close();

                    presentation = null;

                    ppApp = null;

                    GC.Collect();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("exception happened while converting to PDF file..." + ex);

                    throw ex;
                }

            }


    VM7258

    Wednesday, May 02, 2012 3:08 PM

Answers

  • HI,

    Where exactly you run this code? web, windows ..?

    Open XML can not convert a document into pdf. Its just an API to manage the data which sits in the documents. 

    Thanks
    Ankush


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Technology Lover!!

    Thursday, May 03, 2012 5:05 AM

All replies

  • HI,

    Where exactly you run this code? web, windows ..?

    Open XML can not convert a document into pdf. Its just an API to manage the data which sits in the documents. 

    Thanks
    Ankush


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Technology Lover!!

    Thursday, May 03, 2012 5:05 AM
  • Hi,

    To illustrate how to do it, see a simple app:

    using System;
    using System.IO;
    using System.Collections;
    using SautinSoft;
    
    class Test
    {
        static void Main(string[] args)
        {
            SautinSoft.UseOffice u = new SautinSoft.UseOffice();
            string pointPath = @"d:\My slides.pptx";
            string pdfPath = Path.ChangeExtension(pointPath,".pdf");
    
            // Prepare UseOffice .Net, loads MS PowerPoint in memory
            if (u.InitPowerPoint() == 0)
            {
                u.ConvertFile(pointPath, pdfPath, SautinSoft.UseOffice.eDirection.PPTX_to_PDF);
                // Convert other PPT, PPTX files here ...
                u.ClosePowerPoint();
            }
        }
    }
    
    Best wishes,
    Max

    Tuesday, December 10, 2013 11:05 AM