Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Apr 25, 2023 9:13 am

Hello,

I am using the free version of Spire.XLS to convert a xlsx table to a pdf file.

I also want this pdf to be a printable on a A4 format.

I have configured everything to work fine and fit the table to the page, but my last rows on my last page are visualized on top of the page when in pdf format, but when I print them (or in print preview) they are visualized on the center of the A4 page.

I am using the Workbook.SaveToStream() method where I see there some converter settings that can be used, but nothing particular for my problem. Maybe I should try converting with the PDF library?

How can I make them be printed the same way they are visualized in pdf (on top of page).

I am using FreeSpire.Office 8.2.0.

I am attaching my pdf file and xlsx file.

Thank you in advance!
Attachments
xlsx123.zip
(223.17 KiB) Downloaded 373 times

Krisko_99
 
Posts: 4
Joined: Tue Apr 25, 2023 9:05 am

Wed Apr 26, 2023 6:04 am

Hi,

Thanks for your inquiry.
I did not quite understand your need, could you provide your code and some screenshots to help us understand your requirements and work out a solution for you? Thanks for your assistance and understanding.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Apr 26, 2023 7:13 am

This my code, for your testing cases use the files I have provided in this reply.

MemoryStream pdfStream = new MemoryStream(); //file is later saved on my system

using(Workbook workbook = new Workbook())
{
workbook.LoadFromStream(xlsxStream); //xlsxStream is the file in the example
workbook.ConverterSetting.SheetFitToPage = true;

workbook.SaveToStream(pdfStream, Spire.Xls.FileFormat.PDF);
}

I generate a PDF file, but the end page (which is shown completely fine in PDF) has its content centered in the print preview when trying to print trough browser (I have shown on the images I have provided here).

I think there is something with the scale of the page that is being touched when converting can you check that out?

Maybe I need the other library (Spire.PDF)?

Thank you for the quick response!
Attachments
example.zip
Two screenshots of the result + xlsx file converted into pdf
(562.96 KiB) Downloaded 391 times

Krisko_99
 
Posts: 4
Joined: Tue Apr 25, 2023 9:05 am

Wed Apr 26, 2023 8:33 am

Hi,

Thanks for your feedback.
After investigating, we have found that the last page of your document has a size of 11.53 x 5.54 inches, which is not a standard A4 paper size (8.27 x 11.69 inches).

When attempting to print the document onto A4 paper, the printer will automatically adjust the page to fit the paper by scaling it according to the width and height of your document. This can result in differences between the print preview and the display in the PDF viewer.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Apr 26, 2023 12:37 pm

Hi,

I figured out my problem with the scaling.

Thank you for the quick response!

Have a nice day!

Krisko_99
 
Posts: 4
Joined: Tue Apr 25, 2023 9:05 am

Thu Apr 27, 2023 1:21 am

Hi,

Thanks for your feedback.
Glad to hear that you have found the solution, if you have any other questions related to our products, just feel free to contact us.

Have a nice day! :D

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS

cron