Page.pdf does not support pages with decimal witdh/height
meis opened this issue · 3 comments
meis commented
If you want to print a 'letter', for example, it does print a page that's 11 x 8.5 inches. However, if you try to print using width
and height
using those numbers, you'll end up with a page that's 11 x 8 inches.
Step To Reproduce / Observed behavior
irb(main):103:2* Puppeteer::Page::PDFOptions.new({
irb(main):104:2* format: 'letter',
irb(main):105:2* path: 'fake',
irb(main):106:0> }).page_print_args[:paperWidth]
=> 8.5
irb(main):107:0>
irb(main):108:2* Puppeteer::Page::PDFOptions.new({
irb(main):109:2* width: '8.5in',
irb(main):110:2* height: '11in',
irb(main):111:2* path: 'fake',
irb(main):112:0> }).page_print_args[:paperWidth]
=> 8
irb(main):120:2* Puppeteer::Page::PDFOptions.new({
irb(main):121:2* width: 8.5 * 96,
irb(main):122:2* height: 11 * 96,
irb(main):123:2* path: 'fake',
irb(main):124:0> }).page_print_args[:paperWidth]
=> 8
Expected behavior
irb(main):103:2* Puppeteer::Page::PDFOptions.new({
irb(main):104:2* format: 'letter',
irb(main):105:2* path: 'fake',
irb(main):106:0> }).page_print_args[:paperWidth]
=> 8.5
irb(main):107:0>
irb(main):108:2* Puppeteer::Page::PDFOptions.new({
irb(main):109:2* width: '8.5in',
irb(main):110:2* height: '11in',
irb(main):111:2* path: 'fake',
irb(main):112:0> }).page_print_args[:paperWidth]
=> 8.5
irb(main):120:2* Puppeteer::Page::PDFOptions.new({
irb(main):121:2* width: 8.5 * 96,
irb(main):122:2* height: 11 * 96,
irb(main):123:2* path: 'fake',
irb(main):124:0> }).page_print_args[:paperWidth]
=> 8.5
Environment
Tried with ruby 2.6.7
and 3.0.1
.
Other notes
The problem seems to be caused by the liberal usage of to_i
in convert_print_parameter_to_inches
. We can observe:
irb(main):118:0> 8.5 * 96 / 96
=> 8.5
irb(main):119:0> (8.5 * 96).to_i / 96
=> 8
PS: Thanks for the gem! it's saving me to handle a completely separate Node.js environment.
YusukeIwaki commented
Thank you for your detailed reporting.
I will fix it soon.
YusukeIwaki commented
@meis puppeteer-ruby 0.33.0 fixes this issue. Could you try it? Thank you :)
meis commented
So far, so good :)
Thanks @YusukeIwaki ! that was fast