Converting Excel to pDF with improper formatting

Hi Support desk,

I am working on evaulation copy of Aspose.cells dll to convet excel file to PDf file.
Below is my code snippet:

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_QuickStart();
var destinationFileName = dataDir + “Xls2PdfSaveOut.pdf”;

// creating file formats
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);

//Instantiate the Workbook object
Workbook workbook = new Workbook(dataDir + “Test1.xlsx”);

//execute workbook formulas before pdf generation
workbook.CalculateFormula(true);


//Open an excel file
// workbook.Open(dataDir + “XlsTestingFile.xls”);
// The above method is not present in aspose.cell dll , i am using so commenting this.

// Worksheet worksheet = workbook.Worksheets[worksheetCount-1];
foreach (Worksheet worksheet in workbook.Worksheets)
{
worksheet.AutoFitColumns();
var typeWorksheet = worksheet.Type;
worksheet.PageSetup.PrintQuality = 180;
worksheet.PageSetup.CenterVertically = true;
worksheet.AutoFitColumns();
worksheet.PageSetup.PaperSize = PaperSizeType.PaperA4;

}

//Implement one page per worksheet option
var pdfSaveOptions = new PdfSaveOptions {AllColumnsInOnePagePerSheet = true,};



//Save the document in Pdf format
workbook.Save(destinationFileName, Aspose.Cells.SaveFormat.Pdf);

Console.WriteLine("\n Excel Document converted to PDF successfully.\nFile saved at " + dataDir + “Xls2PdfSaveOut.pdf”);

Attached the excel file and pdf after conversion.

Hi,


Thanks for providing us template files.

I think you may try to change the line of code:
i.e.,
//Save the document in Pdf format
workbook.Save(destinationFileName, Aspose.Cells.SaveFormat.Pdf);
to:
//Save the document in Pdf format
workbook.Save(destinationFileName, pdfSaveOptions);

Also, for your information, Aspose.Cells does render PDF file based on what is shown in print preview of the sheets in Ms Excel. So, you may open your spreadsheet in Ms Excel manually, specify your desired Page Setup options and then take the print preview of the sheet(s), then compare it with the different pages of the output PDF file, you will see both are same.

Thank you.

Hi Amjad,

Thanks for quick response. I understand your logic for conversion. I want to change the print setup properties programmatically to view the all columns in one excel. can you help on that.

Hi,


Well, you may try PageSetup attributes for the worksheet(s) before rendering to PDF. Aspose.Cells will try to render PDF file as per your specified PageSetup options, see the document for your reference:
http://www.aspose.com/docs/display/cellsnet/Setting+Page+Options

Thank you.


Hi Thank you for reply.

I am having one more issue. The excel is not printing the all rows from one of worksheets.
programmatically, I dont know which excel will have this issue in print set up.

Can you help me to identify the methods for printing the complete rows for excel for which print preview somewhat doesnot take all rows for starnge reasons.

Hi,


I am afraid, if MS Excel cannot do it then Aspose.Cells also cannot do it as Aspose.Cells follows Ms Excel standards and specifications. Anyways, you may also try to use OnePagePerSheet option to render whole worksheet into single page of PDF, see the document for your reference:
http://www.aspose.com/docs/display/cellsnet/Render+One+Pdf+Page+Per+Excel+Worksheet±+Excel+to+Pdf+Conversion

Thank you.