Handling page size for Excel worksheet to PDF conversion with Aspose.Cells for .NET API in C#

what is the best way to insert a sheet from an excel into a pdf document.
I tried converting it to an image, but the quality is not great.
thank you


Thanks for your query.

If you need to render a single sheet (in the workbook), you may hide all other (unwanted) sheets in the workbook except your desired sheet and save to PDF file format, see the document for your reference:

It is best that you use some vector image type, e.g EMF, PNG, etc., these image types are rendered with good quality.

I tried that, and the quality is much better, but the page size in the resulting pdf is not right and part of the table is cut off. How do I set the page size wider or automatic to the excel size?

Thank yououtput2.pdf (54.9 KB)
image.png (16.3 KB)


Good to know that your issue is sorted out regarding quality.

Please open your file into MS Excel manually and check the print preview of the sheet, you should get the same display as per the output PDF page. If you do not get same output let us know with template file and output file for reference.

By the way, you may apply some measures to cope with it, see the document for your reference:

You were right. The default Print Preview shows in Portrait mode and the table is cut off. If I choose a Landscape mode, it looks fine. But how do I configure this in code with your library?

If I convert the whole excel doc to a pdf, it automatically chooses the correct page size/orientation.
The issue is how to do same thing if converting only certain pages.


Please add the following code segment to your code before rendering to PDF file format:
Sample code:

//Get the first worksheet
//you may change the worksheet index for your desired sheet.
var worksheet = workbook.Worksheets[0];
worksheet.PageSetup.Orientation = PageOrientationType.Landscape;

Kindly provide the template (Excel) file and output file. Also tell which sheets you want to render, so we could help you accordingly.

PS. Please zip the file prior to attaching.