mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 646 forks source link

'in' unit is not working rails 4,2 #695

Open PetrosKalafatidis opened 6 years ago

PetrosKalafatidis commented 6 years ago

In my controller I am trying to create a new pdf when I use px works

pdf=WickedPdf.new.pdf_from_string(
  html,
  margin:  { top:               "0.5625in", 
             bottom:            "0.4375in",
             left:              "0.0in",
             right:             "0.0in" },
  page_height: '1056px',
  page_width: '816px')

When I use 'in' the page is too big.

pdf=WickedPdf.new.pdf_from_string(
  html,
  margin:  { top:               "0.5625in", 
             bottom:            "0.4375in",
             left:              "0.0in",
             right:             "0.0in" },
  page_height: '11in',
  page_width: '8.5in')
unixmonkey commented 6 years ago

Is the margin being added on top of your page height and width?

Does it make it right to set the page_height to 10.9in?

You might also try playing with the dpi, zoom and disable_smart_shrinking options. Some people report that different systems have different default dpi setup in their headless configs.

Here's a related issue thread with some suggestions: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2893

Let me know what ends up working for you!

PetrosKalafatidis commented 6 years ago

Thanks for your response, if I pass parameter zoom: 10 everything looks fine, but this is not acceptable because this will probably going to be broken in my server, what setting on my machine could probably affect the result ?

PetrosKalafatidis commented 6 years ago

No 10.9in does not solves the problem,

unixmonkey commented 6 years ago

I think your screen resolution, as well as the screen resolution of your headless xserver is a factor.

https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2171

I've seen it get really crazy on a 4k monitor, the pdf coming out postage stamp sized. Try specifying a dpi of 96 and disabling smart shrinking. Maybe update wkhtmltopdf if you are being affected by one of the issues reported in the linked issues.

PetrosKalafatidis commented 6 years ago

I have tried disable_smart_shrinking: true, dpi: '96' Also reinstall the wkhtmltopdf this morning but nothing yet.