XDoc.PDF
Features
Tech Specs
How-to C#
Pricing
How to Start Convert PDF Read PDF Build PDF Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF SDK Library
How to Convert Microsoft PowerPoint (pptx, ppt) to Adobe PDF file using XDoc.PDF for .NET library in C#, asp.net, Winforms


How to Use C#.NET PDF Control to Create PDF from Microsoft PowerPoint Presentation in .NET Project. Free Online Trail Download.










  • Best C# Microsoft Office PowerPoint to adobe PDF file converter SDK for Visual Studio .NET
  • An advanced .NET library supports creating PDF from ppt and pptx formats in both C#.NET WinForms and ASP.NET
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Excellent .NET control for turning all PowerPoint presentation into high quality PDF without losing formatting in C#.NET Class
  • Convert to PDF with embedded fonts or without original fonts fast
  • Convert multiple pages PowerPoint to fillable and editable PDF documents
  • Easy to create searchable and scanned PDF files from PowerPoint
  • Directly import tables, hyperlinks (url links) inside pptx, and insert to pdf file. Do not support animations, notes inside pptx document.
  • Professional .NET PDF converter control for batch conversion
  • Export PowerPoint hyperlink to PDF in .NET console application
  • Free online PowerPoint to PDF converter without email
  • C# source code is provided for .NET WinForms class
  • Evaluation PDF library and components for .NET framework




C#: Converting PowerPoint to PDF in C#.NET Application


Following sample code may help you with converting PowerPoint(.pptx/.potm/.ppsm/.ppsx/.potx) to PDF file.



        #region powerpoint(2007 or higher) to pdf (file to file)
        internal static void pptxToPdf()
        {
            String inputPath = @"C:\demo.pptx";
            String outputPath = @"C:\output.pdf";
            //convert .pptx to .pdf
            PPTXDocument doc = new PPTXDocument(inputPath);
            doc.ConvertToDocument(DocumentType.PDF, outputPath);
        }
        #endregion

        #region powerpoint(2003) to pdf (file to file)
        internal static void pptToPdf()
        {
            String inputPath = @"C:\demo.ppt";
            String outputPath = @"C:\output.pdf";
            //convert .ppt to .pdf
            PPTDocument doc = new PPTDocument(inputPath);
            doc.ConvertToDocument(DocumentType.PDF, outputPath);
        }
        #endregion

        #region powerpoint(2007 or higher) to pdf (stream to stream)
        internal static void pptxStreamToPdf()
        {
            String inputPath = @"";
            byte[] arr = File.ReadAllBytes(inputPath);
            Stream inputStream = new MemoryStream(arr);
            PPTXDocument doc = new PPTXDocument(inputStream);
            Stream outputStream = new MemoryStream();
            doc.ConvertToDocument(DocumentType.PDF, outputStream);
        }
        #endregion

        #region powerpoint(2003) to pdf (stream to stream)
        internal static void pptStreamToPdf()
        {
            String inputPath = @"";
            byte[] arr = File.ReadAllBytes(inputPath);
            Stream inputStream = new MemoryStream(arr);
            PPTDocument doc = new PPTDocument(inputStream);
            Stream outputStream = new MemoryStream();
            doc.ConvertToDocument(DocumentType.PDF, outputStream);
        }
        #endregion




C# turn, change two or multiple PowerPoint files to PDF (batch conversion)


        #region powerpoint(2007 or higher) to pdf (batch files and single tread)
        internal static void pptxFilesToPdf()
        {
            String[] files = new String[] { @"C:\demo1.pptx", @"C:\demo2.pptx", @"C:\demo3.pptx" };
            String outputFilePath = @"C:\output.pdf";
            List<MemoryStream> streams = new List<MemoryStream>();
            foreach (String file in files)
            {
                MemoryStream outputStream = new MemoryStream();
                PPTXDocument doc = new PPTXDocument(file);
                doc.ConvertToDocument(DocumentType.PDF, outputStream);
                streams.Add(outputStream);
            }
            PDFDocument.CombineDocument(streams.ToArray(), outputFilePath);
        }
        #endregion

        #region powerpoint(2003) to pdf (batch files and single tread)
        internal static void pptFilesToPdf()
        {
            String inputDirectory = @"C:\input\";
            String outputDirectory = @"C:\output\";
            String[] files = Directory.GetFiles(inputDirectory, "*.ppt");
            foreach (String filePath in files)
            {
                int startIdx = filePath.LastIndexOf("\\");
                int endIdx = filePath.LastIndexOf(".");
                String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
                PPTDocument doc = new PPTDocument(filePath);
                doc.ConvertToDocument(DocumentType.PDF, outputDirectory + docName + ".pdf");
            }
        }
        #endregion

        #region powerpoint to pdf (batch file and multiple threads)
        internal static void pptxfiles2pdf()
        {
            String inputDirectory = @"C:\input\";
            String outputDirectory = @"C:\output\";
            String[] files = Directory.GetFiles(inputDirectory, "*.pptx");
            List<ConversionArgs> args = new List<ConversionArgs>();
            foreach (String filePath in files)
            {
                int startIdx = filePath.LastIndexOf("\\");
                int endIdx = filePath.LastIndexOf(".");
                String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
                ConversionArgs arg = new ConversionArgs(filePath, outputDirectory + docName + ".pdf");
                args.Add(arg);
            }

            List<Thread> threads = new List<Thread>();
            foreach (ConversionArgs arg in args)
            {
                Thread thread = new Thread(pptxToPdfThread);
                thread.Start(arg);
            }
            foreach (Thread thread in threads)
            {
                thread.Join();
            }
        }

        private static void pptxToPdfThread(object args)
        {
            ConversionArgs toPdfArgs = (ConversionArgs)args;
            PPTXDocument srcDoc = new PPTXDocument(toPdfArgs.SrcPath);
            if (srcDoc != null)
            {
                srcDoc.ConvertToDocument(DocumentType.PDF, toPdfArgs.DstPath);
                srcDoc.Dispose();
            }
        }
        #endregion




C# merge, combine multiple PowerPoint file slides, and print to PDF document


        #region combine and convert powerpoint(2007 or higher) to single pdf
        internal static void combineAndConvertpowerpointToPdf()
        {
            String[] files = new String[] { @"C:\demo1.pptx", @"C:\demo2.pptx", @"C:\demo3.pptx" };
            String outputFilePath = @"C:\output.pdf";
            List<MemoryStream> streams = new List<MemoryStream>();
            foreach (String file in files)
            {
                MemoryStream outputStream = new MemoryStream();
                PPTXDocument doc = new PPTXDocument(file);
                doc.ConvertToDocument(DocumentType.PDF, outputStream);
                streams.Add(outputStream);
            }
            PDFDocument.CombineDocument(streams.ToArray(), outputFilePath);
        }
        #endregion

        #region combine and convert powerpoint(2003) to single pdf
        internal static void combineAndConvertpowerpoint03ToPdf()
        {
            String[] files = new String[] { @"C:\demo1.ppt", @"C:\demo2.ppt", @"C:\demo3.ppt" };
            String outputFilePath = @"C:\output.pdf";
            List<MemoryStream> streams = new List<MemoryStream>();
            foreach (String file in files)
            {
                MemoryStream outputStream = new MemoryStream();
                PPTDocument doc = new PPTDocument(file);
                doc.ConvertToDocument(DocumentType.PDF, outputStream);
                streams.Add(outputStream);
            }
            PDFDocument.CombineDocument(streams.ToArray(), outputFilePath);
        }
        #endregion




C# insert PowerPoint file into pdf document, and create a new PDF file


        #region insert powerpoint(2007 or higher) to pdf
        internal static void insertpowerpointToPdf()
        {
            String filePath = @"C:\demo.pptx";
            PPTXDocument doc = new PPTXDocument(filePath);
            MemoryStream stream = new MemoryStream();
            doc.ConvertToDocument(DocumentType.PDF, stream);
            PDFDocument pdf = new PDFDocument(stream);
            int pageCount = pdf.GetPageCount();
            List<BasePage> pages = new List<BasePage>();
            for (int i = 0; i < pageCount; i++)
            {
                pages.Add(pdf.GetPage(i));
            }
            String outputPdf = @"C:\output.pdf";
            PDFDocument desDoc = new PDFDocument(outputPdf);
            int insertLocation = 2;
            desDoc.InsertPages(pages.ToArray(), insertLocation);
            desDoc.Save(@"C:\desDocumcnet.pdf");
        }
        #endregion

        #region insert powerpoint(2003) to pdf
        internal static void insertpowerpoint03ToPdf()
        {
            String filePath = @"C:\demo.ppt";
            PPTDocument doc = new PPTDocument(filePath);
            MemoryStream stream = new MemoryStream();
            doc.ConvertToDocument(DocumentType.PDF, stream);
            PDFDocument pdf = new PDFDocument(stream);
            int pageCount = pdf.GetPageCount();
            List<BasePage> pages = new List<BasePage>();
            for (int i = 0; i < pageCount; i++)
            {
                pages.Add(pdf.GetPage(i));
            }
            String outputPdf = @"C:\output.pdf";
            PDFDocument desDoc = new PDFDocument(outputPdf);
            int insertLocation = 2;
            desDoc.InsertPages(pages.ToArray(), insertLocation);
            desDoc.Save(@"C:\desDocumcnet.pdf");
        }
        #endregion