XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Create PDF from PowerPoint
  |  
Home ›› XDoc.PDF ›› C# PDF: Create PDF from PowerPoint

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

Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.


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




.NET Class Namespace Required



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner.Office03.dll


  RasterEdge.XDoc.PowerPoint.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PowerPoint;





public override void ConvertToDocument(DocumentType targetType, String filePath)

Description:
     Convert to PDF/TIFF and save it on the disk.

Parameters:



public override void ConvertToDocument(DocumentType targetType, Stream stream)

Description:
     Convert to PDF/TIFF and save it into stream.

Parameters:



public override void ConvertToDocument(DocumentType targetType, float zoomValue, String filePath)

Description:
     Convert to PDF/TIFF with specified zoom value and save it on the disk.

Parameters:



public override void ConvertToDocument(DocumentType targetType, float zoomValue, Stream desStream)

Description:
     Convert to PDF/TIFF with specified zoom value and save it into stream.

Parameters:



public override void ConvertToDocument(DocumentType targetType, int resolution, String filePath)

Description:
     Convert to PDF/TIFF with specified resolution and save it on the disk.

Parameters:



public override void ConvertToDocument(DocumentType targetType, int resolution, Stream desStream)

Description:
     Convert to PDF/TIFF with specified resolution and save it into stream.

Parameters:



public override void ConvertToDocument(DocumentType targetType, ImageCompress compression, String filePath)

Description:
     Convert to PDF/TIFF with specified compression method and save it on the disk.

Parameters:



public override void ConvertToDocument(DocumentType targetType, ImageCompress compression, Stream desStream)

Description:
     Convert to PDF/TIFF with specified resolution and save it into stream.

Parameters:



public override void ConvertToDocument(DocumentType targetType, string filePath, ImageOutputOption options)

Description:
     Convert to PDF/TIFF with specified settings through options and save it on the disk.

Parameters:



public override void ConvertToDocument(DocumentType targetType, Stream desStream, ImageOutputOption options)

Description:
     Convert to PDF/TIFF with specified resolution and save it into stream.

Parameters: