Sign UpSign Up   Sign InSign In Welcome Guest,
Live ChatLive Chat
Spacer

Aspose.Cells Product Family

Directly Converting Excel Files to Pdf with Aspose.Cells

In previous versions, converting Excel files to Pdf needs two components: Aspose.Cells and Aspose.Pdf. With the new version v4.7.0, users can use Aspose.Cells for .NET only to implement this feature. This new change greatly optimizes speed and memory usage.

You will utilize the overloaded Save method of the Workbook class providing the FileFormatType.Pdf enum member that converts the native excel file to pdf format.

The above steps are implemented in the following example.

Example:

[C#]

 

//Instantiate the Workbook object

Workbook workbook = new Workbook();

 

//Open an excel file

workbook.Open("f:\\test\\Input.xls");

 

//Save the document in Pdf format

workbook.Save("f:\\test\\Output.pdf", FileFormatType.Pdf);

 

[VB.NET]

 

'Instantiate the Workbook object

Dim workbook As Workbook = New Workbook()

 

'Open an excel file

workbook.Open("f:\test\Input.xls")

 

'Save the document in Pdf format

workbook.Save("f:\test\Output.pdf", FileFormatType.Pdf)

 

Please download and try the new version at: 

http://www.aspose.com/community/files/51/file-format-components/aspose.cells-for-.net-and-java/default.aspx .

Published Friday, February 27, 2009 6:40 PM by Laurence

Comments

 

mbutler555 said:

This is a great feature.  I am using the PdfOptions.OnePagePerSheet = true; feature and it prints out on one page.  However, it makes the print area of the page larger than a standard 8.5x11 page.  Is there anyway effect the print area or the margins of the page?  Or do I have to move to Aspose.PDF to have that sort of control?
May 11, 2010 12:41 PM
 

Amjad Sahi said:

Well, the main purpose of this api "PdfOptions.OnePagePerSheet = true" is if a user needs to quickly create a pdf file(based on the whole spreadsheet/excel file) and he/she wants that each worksheet should be rendered as a single and separate page in the generated pdf file, he/she may use this api for his/her need. Moreover, surely, the pdf pages that are rendered would be different in size.

Thanks for your understanding!
May 11, 2010 12:58 PM
 

mbutler555 said:

So, I guess the answer to the question is that if I want to have margin and size control of the excel sheet values, I have to use the aspose.pdf control.  Correct?
May 11, 2010 1:14 PM
 

Amjad Sahi said:

Well, you may contact Aspose.Pdf team.

But, you should be careful to use the API "PdfOptions.OnePagePerSheet = true" and use this feature if you need each worksheet in the excel file should be rendered as a single page in pdf file irrespective of the page sizes.

Generally, Aspose.Cells will render the pdf pages based on the Print Preview shown by MS Excel. I think you may set Page Setup options e.g page, margins, sheet attributes etc. before saving to pdf format. Aspose.Cells provides the required API for it. See some documents for reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/setting-page-options.html
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/setting-margins.html
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/setting-print-options.html




May 11, 2010 1:32 PM
Anonymous comments are disabled