Convert Microsoft EXCEL TO PDF

Download Developer API Guide

ExcelToPdf Object Description

This object is used to convert Microsoft Excel to pdf. This object contains many Microsoft Excel related features. ExcelToPdf only works with Microsoft Excel 2007 or higher version. Only Excel 2007 requires the free "Save as PDF or XPS" add-in for Office 2007 to be installed. This add-in is available from Microsoft.

// Create an Object
ExcelToPdf excelToPdf = new ExcelToPdf();
// Covert to Pdf
excelToPdf.convert("C:\\Users\\Desktop\\input. xls","C:\\Users\\Desktop\\output.pdf");


Properties


DocumentPassword Property

Sets a password for password protected Excel document.

Type

String

Usage

Setting Resolution and Quality for print.

// Create an Object
ExcelToPdf excelToPdf = new ExcelToPdf();
// Set the password
excelToPdf.setDocumentPassword("test");
// Covert to Pdf
excelToPdf.convert("C:\\Users\\Desktop\\input.xls","C:\\Users\\Desktop\\output.pdf");

PdfExportQuality Property

Specifies the quality of the exported pdf file. Default its set to PDFXlFixedFormatQuality.PDF_EXPORT_QUALITY_STANDARD.

Type

PDFXlFixedFormatQuality

PDF_EXPORT_QUALITY_MINIMUM = 1 Export pdf with lower quality.
PDF_EXPORT_QUALITY_STANDARD = 0 Export pdf,with higher quailty.

Usage

Example

// Create an Object
ExcelToPdf excelToPdf = new ExcelToPdf();
// Setting the PdfExportQuality
excelToPdf.setPdfExportQuality(PDFXlFixedFormatQuality.PDF_EXPORT_QUALITY_STANDARD);
// Covert to Pdf
excelToPdf.convert("C:\\Users\\Desktop\\input.xls","C:\\Users\\Desktop\\output.pdf");

IncludeDocProps Property

To include document properties in pdf file. Default is set to false. Set it to True to include document properties from the source document in the PDF.

Type

Boolean

Usage

Example

// Create an Object
ExcelToPdf excelToPdf = new ExcelToPdf();
// Setting the IncludeDocProps
excelToPdf.setIncludeDocProps(true);
// Covert to Pdf
excelToPdf.convert("C:\\Users\\Desktop\\input.xls","C:\\Users\\Desktop\\output.pdf");

IgnorePrintAreas Property

true to ignore any print areas set when exporting; otherwise, false. Default is false.

Type

Boolean

Usage

Example

// Create an Object
ExcelToPdf excelToPdf = new ExcelToPdf();
// Setting the IgnorePrintAreas
excelToPdf.setIgnorePrintAreas(true);
// Covert to Pdf
excelToPdf.convert("C:\\Users\\Desktop\\input.xls","C:\\Users\\Desktop\\output.pdf");

PrintAllSheets Property

Default is true to print all sheets.If set to false then need to set from and to

Type

Boolean

Usage

Example

// Create an Object
ExcelToPdf excelToPdf = new ExcelToPdf();
// Setting the PrintAllSheets
excelToPdf.setPrintAllSheets(false);
// Setting from count
excelToPdf.setFrom(1);
// Setting To count
excelToPdf.setTo(10);
// Covert to Pdf
excelToPdf.convert("C:\\Users\\Desktop\\input.xls","C:\\Users\\Desktop\\output.pdf");

ConversionTimeOut Property

Set the file coversion time out property. Default is 5 min.

Type

Int (minute)

Usage

Example

// Create an Object
ExcelToPdf excelToPdf = new ExcelToPdf();
// Set the ConversionTimeOut
excelToPdf.setConversionTimeOut (10); //10 minute
// Covert to Pdf
excelToPdf.convert("C:\\Users\\Desktop\\input.xls","C:\\Users\\Desktop\\output.pdf");