|
|
C# PDF Converter Library
How to Convert Microsoft PowerPoint (pptx, ppt) to Adobe PDF file programmatically without Office, interop 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.
In this page, you will learn how to convert Office PowerPoint document to PDF file in the .NET Windows and ASP.NET application using C#
- Convert PPTX to PDF, one slide per page, or multiple slides per PDF page
- Convert PowerPoint to PDF without Office install in Stream object and Byte Array data
- Convert multiple PowerPoint files to PDFs
How to convert PowerPoint to PDF to programmatically using C#
- 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
-
You cound view more PDF converter at:
convert rtf to pdf using in c#,
c# pdf to tiff,
c# save docx as pdf,
c# convert txt to pdf,
pdf to word c# open source,
c# convert jpg to pdf,
c# convert pdf to image.
- 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 in Stream object or byte array data.
#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
How to convert, print multiple PowerPoint slides in one PDF page using C#?
The text and C# source code below explain how to convert and print two pptx slides in one PDF page without Office PowerPoint installed in the C# code.
- Create a new PPTXDocument object from an existing PowerPoint file
- Convert the PowerPoint file to PDF in a MemoryStream object using PPTXDocument.ConvertToDocument() method
- Create a new PageArrangeOptions object for a new PDF document where two powerpoint slides will be put in one PDF page
- Set page width to 8.5 inch; and page height to 11 inch; and set page margins also
- Set the number of pages per column (ColumnsPerPage) to 1, and number of pages per row RowsPerPage to 2
- Call PDFDocument.CombinePages() to combine PDF from PowerPoint with PageArrangeOptions options applied
- Save the new converted PDF file
String inputFilePath = @"C:\temp\powerpoint-1.pptx";
String outputFilePath = @"C:\temp\powerpoint-1-converted-2-in-1.pdf";
//Step 1: convert PPTX to PDF
PPTXDocument doc = new PPTXDocument(inputFilePath);
MemoryStream tempPDFStream = new MemoryStream();
doc.ConvertToDocument(DocumentType.PDF, tempPDFStream);
// Step 2: combine pages
PageArrangeOptions ops = new PageArrangeOptions();
// set width of new page to 8.5 inches
ops.PageWidth = 8.5F;
// set height of new page to 11 inches
ops.PageHeight = 11F;
// set page margins in inch
ops.TopMargin = 1F;
ops.BottomMargin = 1F;
ops.LeftMargin = 0.5F;
ops.RightMargin = 0.5F;
// properties to arrange region for each page
// 1 page per row
ops.ColumnsPerPage = 1;
// 2 pages per column
ops.RowsPerPage = 2;
// 0.1 inches interval between columns
ops.ColumnInterval = 0.1F;
// 0.1 inches interval between rows
ops.RowInterval = 0.1F;
// set fit mode for each page
ops.FitMode = PageArrangeOptions.PageFitMode.AspectFit;
// disable region border
ops.RegionBorder.Width = 0;
// enable page border
ops.PageBorder.Width = 1;
ops.PageBorder.Color = Color.Blue;
MemoryStream outputPDFStream = new MemoryStream();
PDFDocument.CombinePages(tempPDFStream, outputPDFStream, ops);
PDFDocument outputPDFDoc = new PDFDocument(outputPDFStream);
outputPDFDoc.Save(outputFilePath);
The text and C# source code below show how to convert and print four pptx slides in one PDF page in the C# code.
- Set page width to 11 inch; and page height to 8.5 inch. Now the new converted PDF file page will be in landscape orientation
- Set the number of pages per column (ColumnsPerPage) to 2, and number of pages per row RowsPerPage to 2
- Call PDFDocument.CombinePages() to combine PDF from PowerPoint with PageArrangeOptions options applied
- Save the new converted PDF file
String inputFilePath = @"C:\temp\powerpoint-1.pptx";
String outputFilePath = @"C:\temp\powerpoint-1-converted-4-in-1.pdf";
//Step 1: convert PPTX to PDF
PPTXDocument doc = new PPTXDocument(inputFilePath);
MemoryStream tempPDFStream = new MemoryStream();
doc.ConvertToDocument(DocumentType.PDF, tempPDFStream);
// Step 2: combine pages
PageArrangeOptions ops = new PageArrangeOptions();
// set width of new page to 8.5 inches
ops.PageWidth = 11F;
// set height of new page to 11 inches
ops.PageHeight = 8.5F;
// set page margins in inch
ops.TopMargin = 1F;
ops.BottomMargin = 1F;
ops.LeftMargin = 0.5F;
ops.RightMargin = 0.5F;
// properties to arrange region for each page
// 1 page per row
ops.ColumnsPerPage = 2;
// 2 pages per column
ops.RowsPerPage = 2;
// 0.1 inches interval between columns
ops.ColumnInterval = 0.1F;
// 0.1 inches interval between rows
ops.RowInterval = 0.1F;
// set fit mode for each page
ops.FitMode = PageArrangeOptions.PageFitMode.AspectFit;
// disable region border
ops.RegionBorder.Width = 0;
// enable page border
ops.PageBorder.Width = 1;
ops.PageBorder.Color = Color.Blue;
MemoryStream outputPDFStream = new MemoryStream();
PDFDocument.CombinePages(tempPDFStream, outputPDFStream, ops);
PDFDocument outputPDFDoc = new PDFDocument(outputPDFStream);
outputPDFDoc.Save(outputFilePath);
C# turn, change two or multiple PowerPoint files to PDF (batch conversion)
The following C# sample code will show how to convert multiple PPTX files or all PowerPoint files in one folder to PDF files using C# code.
#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
The following C# source code will explains how to combine more than one PowerPoint files and convert to one single PDF document in C#.NET.
#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
The C# source code below will explains how to insert all slides in PowerPoint file to a PDF file using C# code
#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
|