3

I am trying to generate PDF using

WIckedPdf version = 1.1.0

wkhtmltopdf 0.12.4 (with patched qt)

Rails 4.2

Below is my Controller endpoint

@cover = render_to_string layout: "application.html.erb", template: "pdf/cover.html.erb", locals: {report: @report}
@pdf = render_to_string pdf: "report",
encoding: "UTF-8",
page_size: 'A4',
layout: "pdf.html.erb",
orientation: 'Portrait',
disable_smart_shrinking: false,
disable_internal_links: false,
disable_external_links: false,
lowquality: false,
background: true,
no_background: false,
page_height: 297,
page_width: 210,
cover: @cover,
template: "pdf/report.pdf.erb",
locals: {report: @report},
show_as_html: false,
margin: {
bottom: 40,
top: 10
},
footer: {
html: {
template: 'pdf/footer.html.erb' # use :template OR :url
}
},
toc: {
text_size_shrink: 0.8,
header_text: "Table of Contents",
no_dots: false,
disable_dotted_lines: false,
disable_links: false,
disable_toc_links: false,
disable_back_links: false,
}

send_data @pdf, type: :pdf, disposition: 'inline'

Am facing the problem that All the text that are generated in pdf is very very SMALL. To achieve font size of 14 in pdf, i had to change my css as font-size: 56px (Four times than the normal pixel)

Can Anybody help me why font size is rendered like this? Also, All the css that includes pixels such as padding, margin are four times smaller than normal.

Even if changed CSS of my file to four times higher values, CURRENTLY I AM UNABLE TO CHANGE FONT_SIZE FOR TABLE OF CONTENTS GENERATED.

Any help / Reference would be highly helpful and appreciated

Dharmesh
  • 31
  • 2

3 Answers3

7

Setting dpi: 300 should fix your issue with the content rendering too small.

Chris Tosswill
  • 187
  • 5
  • 11
  • Thanks for this. It wasn't obvious to me at first (though it was as soon as I thought about it for a second) that DPI would have a big impact on font size – oneWorkingHeadphone Mar 28 '19 at 12:36
  • This also fixed the minuscule text size issue for me. It's a bit odd though that the default `dpi` would render such tiny text. I wonder what the motivation for that is. Anyway, setting dpi to 1000 seems to make the text readable for me. – DaniG2k Aug 04 '19 at 09:03
3

I had the same issue and, I could fix it by adding lowquality: true to wicked_pdf config file.
In config/wicked_pdf.rb file

WickedPdf.config = {
  #cross enviroment configs
}

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

Credits & Reference: Issue #754

Charith H
  • 345
  • 1
  • 13
-2

You can add CSS class in your view template to increase the Font Size like normal HTML.

Hard Developer
  • 309
  • 1
  • 3
  • 12
  • please read the original Post. The User Dharmesh already wrote that he used a very large font size. The dpi-setting in wicked_pdf options seems to do the job ;-) – Chilian Aug 13 '19 at 12:57