ImageGear .NET
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:

  • Gradients with Transparency: Microsoft Office Open XML gradients with transparency are converted as non-transparent PDF gradients.
  • Text with Gradients: Microsoft Office Open XML text with gradient fill and stroke is converted to solid PDF text with the color of the first gradient stop.
  • Patterns: Microsoft Office Open XML text with patterns is converted to solid black PDF text.

Word (DOCX) 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);
}

Excel (XLSX) to PDF

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";

PowerPoint (PPTX) to PDF

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";

 

 


©2017. Accusoft Corporation. All Rights Reserved.

Send Feedback