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

Rendering everything small on MacOS #754

Closed
jpaulomotta opened this issue Jul 19, 2018 · 8 comments
Closed

Rendering everything small on MacOS #754

jpaulomotta opened this issue Jul 19, 2018 · 8 comments

Comments

@jpaulomotta
Copy link

Hello.

I'm having this issue on a MacOS High Sierra 10.13.5

Expected behaviour
I've followed the tutorial on the documentation, so I was expecting WickedPDF to render my page with no styles, just plain HTML in a way that's readable.

Current behaviour
This is what I'm getting. Super tiny fonts on my doument.

screen shot 2018-07-19 at 3 55 25 pm

Zooming in shows the document with a super small font.
screen shot 2018-07-19 at 3 55 42 pm

Using the param debug shows the HTML with the expected fonts.
screen shot 2018-07-19 at 4 01 43 pm

The error does not happen on Heroku as you can see in the picture below from the same application:
screen shot 2018-07-19 at 4 02 31 pm

My enviroment

Rails 5.2.0
Ruby 2.4.4
Bundler version 1.16.2
wicked_pdf (1.1.0)
wkhtmltopdf-binary (0.12.4)
MacOS High Sierra 10.13.5

Code
Layout app/views/layouts/print_headless.pdf.erb

<!DOCTYPE html>
<html>
  <head>
    <title>OdontoCloud</title>
    <meta charset="utf-8">

    <%= wicked_pdf_stylesheet_link_tag "pdf_styles" -%>
  </head>

  <body >
    <h1>Heading from Rails Layout print_headless.pdf.erb</h1>
    <%= yield %>
  </body>
</html>

pdf_styles is a blank css file. Setting the font on the css was also unsuccessfull.

Controller

# GET /medical_records/1
  # GET /medical_records/1.json
  def show
    respond_to do |format|
      format.html #suppresed
      format.pdf { render pdf: 'medical_records', layout: 'print_headless', show_as_html: params.key?('debug') }
    end
  end

Am I missing any special installation step on MacOS?

@jpaulomotta
Copy link
Author

Hello,

I have found a discussion for this issue on wkhtmltopdf repository. The problem is on the binary not on this gem.

wkhtmltopdf/wkhtmltopdf#3241

@unixmonkey
Copy link
Collaborator

Yeah, that's a tough one, and it's OS/configuration specific.

You can try setting the dpi and zoom options to a fixed value, or even developing without or with a different monitor. Maybe changing monitor resolution, but then you need to work out the difference between development and production (which is usually linux-based).

There are also other suggestions in the linked thread. Hope it helps!

@jpaulomotta
Copy link
Author

The fix for non retina MacOS 10.13.5 with wkhtlmtopdf 0.12.4 is to add the flag --lowquality to wkhtmltopdf binary.

WickedPdf supports this flag through the config lowquality: true.

To run the flag on development only:
config/wicked_pdf.rb

WickedPdf.config = {
  #cross enviroment configs
}

if Rails.env.development?
  WickedPdf.config[:lowquality] = true
end

Thanks for your support @unixmonkey

@unixmonkey
Copy link
Collaborator

Whoa, thanks for letting me know about that. I'm sure the info will help others.

@ohboyd
Copy link

ohboyd commented Oct 18, 2018

I'm not sure if it will work for everyone, but the solution that seems to be easiest to implement on my projects is as follows:

When making the controller method, I set the dpi to 300:

respond_to do |format|
  format.html
  format.pdf {dpi: 300, pdf: 'filename', page_size: 'Letter', etc.}
end

and then I add a stylesheet that gives the body a font-size:

body {
  font-size: 16px;
}

and then I just add the stylesheet tag to the actual pdf and put everything in the body of the html:

= wicked_pdf_stylesheet_link_tag 'filename'

<body>
  <h1>Oh hey guise</h1>
</body>

Maybe this will help some of you that find this when searching for other solutions. This is with the 12.4 binary, and I'm on Sierra 10.13.6

@cesc1989
Copy link

The opposite occurs in Heroku. The font gets way too big in version 0.12.4 of the binary gem. Fortunately, it can be solved with the same setting suggested by @jpaulomotta

format.pdf do
  render pdf: "orden_#{@order.id}_#{@order.customer.full_name}",
               layout: 'pdf.html',
               page_size: 'A7',
               margin: {
                 top: 3,
                 right: 3,
                 bottom: 3,
                 left: 3
               },
               lowquality: true
end

@wdiechmann
Copy link

wdiechmann commented Mar 19, 2019

@jpaulomotta thank you so so much for opening this issue ahead of me <3

shout out to @unixmonkey and @ohboyd and @cesc1989 obviously for chippin' in !

I just spent the better part of 24hrs fighting this - and am angry with myself for not stopping by sooner [:|

@mmccarthy15
Copy link

For anyone else finding this issue, I somehow just ran into this same issue. I assume it was due to a recent MacOS update, but was jarring to see really tiny text in our environment.

Now, the simple fix is to update to wkpdftohtml-binary gem to 0.12.5
bundle update wkhtmltopdf-binary or specifically stating that version in your Gemfile.
No dpi changes required.

Thanks all who struggled through it way more than I did!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants