tealeg / xlsx

Go library for reading and writing XLSX files.
Other
5.85k stars 819 forks source link

Excel to PDF Page size issue #800

Closed Sarsewar closed 6 months ago

Sarsewar commented 6 months ago

Please find attached Demo_Excel.xlsx, which we are currently using to convert to PDF. The conversion process is being conducted directly on DocuSign. However, we've encountered issues regarding page size and scaling, as illustrated in the screenshots below. Despite attempting conversion through other online free platforms specializing in direct XLSX to PDF conversion, we've encountered the same issues. Notably, the same Excel file converts correctly using Microsoft's "Save As" or "Print" functionality.

We have explored various combinations in the worksheet's XML, including adjustments to pageSize, scale, fitToWidth, and fitToHeight, yet none have proven successful. We seek your insights into the possible reasons for these challenges.

fitToPage fitToWidth fitToHeight Scale
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 1 1
0 1 0 1
0 1 1 0
0 1 0 0
1 0 0 0
1 0 0 1
1 0 1 0

image

Your guidance in resolving this matter is greatly appreciated.

tealeg commented 6 months ago

I'm not sure what the exact issue with formatting you have is? In any case, the general approach if you see something that works when you create the file by hand, but not with this library, is to inspect the output files themselves. An XLSX file is actually just a Zip file containing multiple XML files. In the case of the file you attached above, it also contains two binary blobs:

xl/printerSettings/printerSettings1.bin
xl/printerSettings/printerSettings2.bin

These were added at some other stage as this library doesn't create such files. It could well have removed references to them from other files within the XLSX bundle)., as was the embedded WMF file. Again, if you're creating a template and then using this library to modify it, I'd strongly suggest just doing a very minimal open and save with this library and comparing the before and after files.

Sarsewar commented 6 months ago

Thanks for the reply @tealeg.

Despite the presence of page setup and sheet properties, certain online conversion platforms and DocuSign are considering the total column width of the worksheet. For example, if the total column width of the first worksheet is 100 and for the second worksheet it is 70, the converted PDF may have the width of the first page greater than that of the second page.

This is weird. I am closing the issue.

Thanks again.

tealeg commented 6 months ago

Thanks @Sarsewar. Good luck, and if you want to run anything by me feel free to come back here and comment.