Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_pdf: allow to choose the quality #1697

Closed
fzumstein opened this issue Aug 5, 2021 · 5 comments · Fixed by #1808
Closed

to_pdf: allow to choose the quality #1697

fzumstein opened this issue Aug 5, 2021 · 5 comments · Fixed by #1808
Milestone

Comments

@fzumstein
Copy link
Member

this is currently hardcoded to PrintQuality.

@fzumstein fzumstein added this to the 0.24.8 milestone Aug 5, 2021
@fzumstein fzumstein modified the milestones: 0.24.8, 0.24.9, 0.24.10 Aug 24, 2021
@Acer1968
Copy link

Hi Felix.
I am sorry, I am newbie in python and github, so I don´t know if I can ask you here for help.
My problem is that the PDF file created via .to_pdf() method is too big (more then 10 times) in comparation with printing via NitroPDF, for example.
I add two files for your comparing, so you can see that.
The printing via NitroPDF´s CLI are not quite easy (for me - I tried call NitroPDF via os.system(command) or via subprocess.run() method), but some issues are there (for example, NitroPDF ignore print_area or when I setup print-area via xlwings, NitroPDF is not running and Excel give error with duplicate area :-O ).
So I return to your .to_pdf() method, but the size of file is quite big :-(
Do you have some advice?

Petr V.

P.S: I appologise for my English.
op30_nitro.pdf
op30_xlwings.pdf

@fzumstein
Copy link
Member Author

Hi Petr, could you upload the Excel file from which you're printing?

I am surprised by the size even with the current high quality. As the issue says, I'll add the option to chose the low-quality option which will definitely shrink size. To use another PDF print driver, we'd have to use the print method, see: #504

@Acer1968
Copy link

Acer1968 commented Sep 2, 2021

Hi Felix.
Thx for your reply. Yes, I can send the excel file. And yes, I am sending the PDF file Sheet1.pdf as result from:

xlwings.Book(r"D:/somepathtofile/docasny.xlsx").sheets[0].to_pdf()

So you see that the file size is 410kB and from NitroPDF only 33kB...

And the advice from #504 is not working for me too, because this error appears:
xlwings.Sheet("Invoice").xl_sheet.PrintOut()
'Sheet' object has no attribute 'xl_sheet'

I bought your book Python for Excel and nothing about PDF or .to_pdf() method is there :-(

Maybe you will find why is the file so big ... Thank you.

Petr V.
Sheet1_nitro.pdf
Sheet1.pdf
docasny.xlsx

@fzumstein
Copy link
Member Author

Here are my findings:

  • Opening your file causes a name conflict with Print_Area
  • Exporting it from Excel to PDF with high quality or running mybook.to_pdf() both results in a file around 110KB
  • Exporting it from Excel to PDF with low quality results in around 95KB, so not a huge difference in this case. As mentioned, this option isn't available yet via to_pdf, but this issue is about adding this option. While these file sizes are still bigger than the one produced by nitro, it's still 4x smaller than your version.
  • xlwings.Sheet('Sheet').print ? #504 is super old, so you'd need to scroll to the bottom for the correct syntax. These days you need to to:
import xlwings as xw
book = xw.Book(...)
book.sheets['Invoice'].api.PrintOut()

@Acer1968
Copy link

Acer1968 commented Sep 3, 2021

Hi Felix.
Thank you for your investigation, it pointed to me the next direction ...

I will be patiently waiting you add a choose of quality, good luck.

Now I don´t want to abuse your willingness.

Petr V.

P.S. your book is written very clearly, my English is not advanced (as you noticed), but I understand all. Great job.

@fzumstein fzumstein modified the milestones: 0.25.0, 0.25.1 Oct 26, 2021
@fzumstein fzumstein modified the milestones: 0.25.1, 0.25.2 Nov 11, 2021
@fzumstein fzumstein modified the milestones: 0.25.2, 0.25.3, 0.25.4 Dec 3, 2021
@fzumstein fzumstein removed this from the 0.26.1 milestone Feb 1, 2022
@fzumstein fzumstein added this to the 0.26.2 milestone Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants