Aspose.Pdf convert Excel to PDF

good morning Apose,

i'm new to your products and trying to figure out which of your products will do the thing i need to do. am i able to only use Aspose.Pdf to convert an excel file to pdf? or do i need to purchase only Aspose.Cells instead to do the conversion from excel to pdf?

i've been looking at aspose.pdf product info and it keeps saying it can convert word and excel files to pdf but i don't see your example code demos showing how to do that.

bottom line, i need to be able to convert excel files to pdf. and i need to be able to convert individual worksheets inside the excel file/workbook to pdf.

thank you very much for your help on this Aspose.

Hi sam,

Thanks for using our products.

You may check the following documentation links for details and code snippets as per your requirement.

Export Excel Worksheet data into PDF table

Please do let us know if you need any further assistance.

Thanks & Regards,

hi there,

actually, the response didn't really answer my question. can i use ONLY Aspose.Pdf to convert excel files to pdf? Is that possible?

thank you

Hi,

Aspose.Cells for .NET can directly convert Ms-Excel files into PDF file. So you do not need Aspose.Pdf for this purpose.

Please see the following code that will convert a sample xls file to pdf.

Please download the latest version:
Aspose.Cells for .NET v7.0.3.2


I have attached the source and output files too.

C#


string path = @“F:\Shak-Data-RW\Downloads\source.xls”;

Workbook workbook = new Workbook(path);

workbook.Save(path + “.out.pdf”);


i see. the reason i ask about Aspose.Pdf because it can convert many other things which we like and may find using later down the road like converting images to pdf and xml to pdf.

if Aspose.Pdf can directly convert excel to pdf, then we wouldn't need to think any further and just buy Apose.Pdf.

but i guess from what i'm sensing, Aspose.Pdf cannot directly convert excel files to pdf. Would that be a correct assumption?

thank you

Can Aspose.Cells go inside an excel file/workbook and extrapolate out individual worksheets and convert each worksheet into a pdf file?

ultimately, i need to be able to convert each worksheet in a workbook into its own pdf file. so if a workbook has 5 unique worksheest, i need to be able to convert them where the result outcome would be 5 invidually unique pdf (1 pdf for each worksheet in the workbook).

thank you

Hi,

Yes, Aspose.Pdf cannot directly convert Excel files to Pdf. Also, Aspose.Cells can go inside an excel file/workbook and extrapolate out
individual worksheets and convert each worksheet into a pdf file.

Please see a code example how to save each of your worksheet as separate pdf.

C#


string filePath = @“C:\Downloads\test.xlsx”;


Workbook workbook = new Workbook(filePath);


int sheetCount = workbook.Worksheets.Count;


//Make all sheets invisible except first

for (int i = 1; i < workbook.Worksheets.Count; i++)

{

workbook.Worksheets[i].IsVisible = false;

}//for


//Take pdfs of each sheet

for (int j = 0; j < workbook.Worksheets.Count; j++)

{

Worksheet ws = workbook.Worksheets[j];


Debug.Print("Processing: " + ws.CodeName);


workbook.Save(“F:\downloads\sheet-” + ws.CodeName + “.pdf”);


if (j < workbook.Worksheets.Count - 1)

{

workbook.Worksheets[j + 1].IsVisible = true;

workbook.Worksheets[j].IsVisible = false;

}//if

}//for


//Make all sheets invisible except first
for (int i = 1; i < workbook.Worksheets.Count; i++)
{
workbook.Worksheets[i].IsVisible = false;
}

why do u need to make each worksheet invisible?

workbook.Save("F:\\downloads\\sheet-" + ws.CodeName + ".pdf");
how does this line of code know what sheet to save? it's just passing a filepath with the name of the new pdf file that is to be created and saved on the drive.

Hi,

Aspose.Cells convert your xls/xlsx file into PDF as Ms-Excel renders it in a Print Preview. It converts your entire workbook’s visible sheets.

Since you need separate pdf for your each of sheet, we need to make all other sheets invisible/hidden. Once you get the pdf of first worksheet, you will make second unhidden and all others hidden and then save it in pdf format and this will goes on till the last worksheet.

The code name in the last line is just used to save the pdf in new file rather than overwriting any existing file.

so does the print preview screen actually show up? because i just need it to convert and save behind the scenes without any prompt or screen showing up.

is there a link/url to the sample code that converts individual worksheets in a workbook into their respective individual pdf files?

Hi,


Do what Shakeel Faiz suggested you.

Also, the print preview screen will not show up as the code would generate individual pdf files (based on individual sheets) to the disk/path.

See an article on it here:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/save-each-worksheet-to-a-different-pdf-file.html

Thank you.

thank u very much for the url link.

I have a couple of scenarios i need research on for what we need to do:

Scenario 1:

Lets say I have a workbook of 5 worksheets. Am I able to:

  1. Extract out worksheet 3 through code

  2. Create a new workbook and insert worksheet 3 into the NEW workbook, through code

  3. Then while the new workbook object is in memory, convert to a pdf file and save it to a folder on my drive???

Scenerio 2:

Lets say I have a workbook of 5 worksheets. Am I able to:

  1. Select certain worksheets and have those converted into 1 pdf file? So lets see i needed worksheet 1, 3, & 5 all converted together into 1 single pdf file that has 3 pages in it, one for each of the selected worksheets, can that be done by setting Worksheets[1], Worksheets[3], and Worksheets[5] 's IsVisible = true so those 3 selected worksheets are visible?

Thank you

Hi,

Yes, you can do so, Aspose.Cells will allow you to copy worksheet from one workbook to another, it also allows you to create new workbook from scratch.

So, you can split your single workbook into multiple workbooks and save each of them to pdf separately.

Please refer to Copying and Moving Worksheets

At the moment, i'm trying to convert an excel file to pdf but not save it to a folder on my drive but instead, once converted, the Save() method of the Aspose.Cells.Workbook object needs to return a byte[] object.

is there a way to get an in memory byte[] object of the converted excel file? so basically, convert file to byte[] and the contents in the byte[] is the converted excel file to pdf.

thank you

Hi,


Sure, you can do that, see the code segment below:


MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.Pdf);
byte[] bytes = ms.ToArray();
Debug.WriteLine(bytes.Length);

can Aspose.Cells load an html file and convert it to PDF. I'm going through the documentation, and it looks like it can but i need to double check and confirm.

thank you for your help Aspose

Hi,

If you can create a Workbook object from HTML file, then you can save it to PDF.

Aspose.Cells for .NET will allow you create a workbook object from HTML generated by Ms-Excel.

It means, you cannot use/load any type of HTML, you can only use/load the HTML generated by Ms-Excel.

can one print the converted pdf file using Aspose.Cells?

thank you

Hi,

To print workbook/worksheet, please use WorkbookRender.toPrinter/SheetRender.toPrinter() methods.

Please refer to this thread: Printing Workbooks