User Guide > How to Work with... > Formats with Additional Functionality > PDF > How to... > Convert... > Microsoft Office Documents to PDF |
ImageGear .NET provides the ability to convert any Microsoft Office Open XML document currently supported by the product or any page of a Microsoft Office Open XML document and save the converted content to a PDF file. This can be done by using one of the following API calls:
ImageGear .NET Office to PDF converter provides the conversion of all currently supported text elements, raster images, and graphic shapes for Microsoft Office Open XML formats described in Using ImageGear.Formats.Office Namespace.
Note the following conversions that take place when converting to PDF:
|
This sample shows how to input a Word document in the DOCX format and output all pages as a PDF document.
ImageGear does not support MS Word 97 DOC files. |
After some initializations, load the necessary ImGear filters to create an instance of Microsoft Word format for input and an instance of PDF format for output using code that looks like:
Copy Code | |
---|---|
ImGearFileFormats.Filters.Add(ImGearOffice.CreateWordFormat()); ImGearFileFormats.Filters.Add(ImGearPDF.CreatePDFFormat()); |
Next, the PDF library requires its own initialization:
Copy Code | |
---|---|
ImGearPDF.Initialize(); |
Then, simply read in all pages of the Word document using the ImGearFileFormats.LoadDocument() method:
Copy Code | |
---|---|
ImGearDocument igDocument; using (FileStream fileStream = new FileStream(inputFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { igDocument = ImGearFileFormats.LoadDocument(fileStream); } |
Finally, write out the document as PDF using the ImGearFileFormats.SaveDocument() method with the saving format set to ImGearSavingFormats.PDF and no special options:
Copy Code | |
---|---|
using (FileStream fileStream = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite)) { ImGearFileFormats.SaveDocument(igDocument, fileStream, 0, ImGearSavingModes.OVERWRITE, ImGearSavingFormats.PDF, null); } |
This sample can be easily adjusted to accept Excel Spreadsheet XSLX documents as input.
ImageGear does not support reading Excel 97-2007 XLS documents. |
To accept XSLX files as input, create an instance of Microsoft Excel format after initializing ImageGear .NET:
Copy Code | |
---|---|
ImGearFileFormats.Filters.Add(ImGearOffice.CreateExcelFormat()); |
and modify the sample's open file dialog to accept the *.xlsx extension:
Copy Code | |
---|---|
ofd.Filter = @"DOCX files (*.docx)|*.docx|XLSX files (*.xlsx)|*.xslx"; |
This sample can be easily adjusted to accept PowerPoint PPTX files as input.
ImageGear does not support reading legacy PowerPoint PPT files. |
To accept PPTX files as input, create an instance of Microsoft PowerPoint format after initializing ImageGear .NET:
Copy Code | |
---|---|
ImGearFileFormats.Filters.Add(ImGearOffice.CreatePowerPointFormat()); |
and modify the sample's open file dialog to accept the *.pptx extension:
Copy Code | |
---|---|
ofd.Filter = @"DOCX files (*.docx)|*.docx|PPTX files (*.pptx)|*.pptx"; |