Incorrect margins and missed graphics for xlsx -> pdf conversion

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,


Thanks for your posting and using Aspose.Cells.

We have found the incorrect margin issue. For missing graphics please add comments manually using Adobe Acrobat inside your output pdf so that we could investigate and fix it easily.

This issue has been logged as

  • 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.

Hi,

Thanks for your posting and using Aspose.Cells.

We will look into your next problem asap. However, for the previous problem logged as CELLSNET-44789:

Because there is no setting about paper size, MS Excel will use printer's setting.

If you want to get same page break as MS Excel. First, get the printer's paper size. Then set it to workbook while loading using the following code:

C#
LoadOptions loadOpts = new LoadOptions();

//e.g. your printer's paper size is A4
loadOpts.SetPaperSize(PaperSizeType.PaperA4);
Workbook wb = new Workbook(srcFile, loadOpts);
wb.Save("outFile.pdf");

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.
Hi

Thanks for using Aspose.Cells

For the page height is still too different problem mentioned in your afterAdv_page1difference.png:

We can't see the problem, please see the attachments (input_Aspose.pdf and input_Ms.pdf). Our printer's paper size is also A4 and we print grid lines of sheet "ガイド" for comparing.

For part of red rectangle with text is absent problem mentioned in your afterAdv_page4(3)difference.png:

This is because we lost shapes order after some shapes are split to multi-pages and it caused shapes overlap by mistake. We can't fix it now. Please try the following workaround if possible:

C#
Workbook wb = new Workbook(srcFile);
PdfSaveOptions pdfSaveOpts = new PdfSaveOptions();
pdfSaveOpts.OnePagePerSheet = true;

wb.Save("outFile.pdf", pdfSaveOpts);

@dasupport,

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