After conversion from xlsx to pdf we discover that pages was splitted different to how it was done in Excel on Print preview display (using default settings and Microsoft.Pdf printer or Foxit Reader Pdf Printer or any other printer we have access to). Also some part of graphics disappears from final pdf. I use green ellipse to highlight found flaws on attached page_4(3)difference.png. Or you can use code bellow to obtain pdf and observer described behavior on page 3.
We use Aspose.Cells 9.0.0 and following code
using (var fs = File.Open(“input.xlsx”, FileMode.Open, FileAccess.Read, FileShare.Read))
{
Workbook doc = new Workbook(fs);
FileInfo fi = new FileInfo(“output.pdf”);
using (var fso = fi.OpenWrite())
{
doc.Save(fso, Aspose.Cells.SaveFormat.Pdf);
}
}
Hi,
- CELLSNET-44789 - Incorrect margins for xlsx to pdf conversions
Hi Faiz,
thank you for fast response.
Please find attached output.pdf with my annotation and arrow on page 3. The problem is that part of red rectangle with text disappears during conversion.
FYI:Try the following code to get the default printer's paper size and set to Aspose.Cells API:C#PrinterSettings printerSettings = new PrinterSettings();Console.WriteLine(printerSettings.PrinterName);Console.WriteLine(printerSettings.DefaultPageSettings.PaperSize);LoadOptions loadOpts = new LoadOptions();loadOpts.SetPaperSize((PaperSizeType)printerSettings.DefaultPageSettings.PaperSize.RawKind);Workbook wb = new Workbook(input.xlsx, loadOpts);Console.WriteLine(wb.DefaultStyle.Font);Worksheet sheet = wb.Worksheets["ガイド"];Console.WriteLine(sheet.PageSetup.PaperSize);wb.Save("outFile.pdf");For getting the default printer's paper size manually:1. Open printers in "Control Panel"2. Right click your default printer and choose "Print Preference" and then choose "Advanced", you will see the paper size.
Thank you, Faiz
I follow your advice and final result is much closer to what we expect to get as output.
I use following code:
C#
using (var fs = File.Open("input.xlsx", FileMode.Open, FileAccess.Read, FileShare.Read)) { PrinterSettings printerSettings = new PrinterSettings(); Console.WriteLine(printerSettings.PrinterName); Console.WriteLine(printerSettings.DefaultPageSettings.PaperSize); LoadOptions loadOpts = new LoadOptions(); loadOpts.SetPaperSize((PaperSizeType)printerSettings.DefaultPageSettings.PaperSize.RawKind); Workbook doc = new Workbook(fs, loadOpts); Console.WriteLine(doc.DefaultStyle.Font); Worksheet sheet = doc.Worksheets["ガイド"]; Console.WriteLine(sheet.PageSetup.PaperSize); FileInfo fi = new FileInfo("output.pdf"); using (var fso = fi.OpenWrite()) { var saveOptions = new PdfSaveOptions(Aspose.Cells.SaveFormat.Pdf); doc.Save(fso, saveOptions); } }
Output was:
Microsoft Print to PDF
[PaperSize A4 Kind=A4 Height=1169 Width=827]
Aspose.Cells.Font [ MS Pゴシック; 11; Regular; Color [A=0, R=0, G=0, B=0] ]
PaperA4
Press any key to continue . . .
But page height is still to different and artifacts from page3(4) is still present.
Please review afterAdv_page1difference.png to see how different my excel splitting
page compared to Aspose.Cells. And on afterAdv_page4(3)difference.png you can see
that part of red rectangle with text is absent (such as red border). I use dark green
ellipses and arrows to highlight described problem on screenshots.
This is to inform you that your issue has been resolved. The fix will be included in an upcoming release (Aspose.Cells v23.3) that we plan to release in the first half of March 2023. You will be notified when the next version is released.
The issues you have found earlier (filed as CELLSNET-44789) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi