3
votes

I am using wickedpdf gem for generating pdf's in my rails application. Every thing runs normally, except for few requests on production fail, with the following error log.

Error: Failed to execute: ["/usr/local/bin/wkhtmltopdf", "-q", "--page-size", "A4", "--margin-top", "20", "--margin-bottom", "25", "--margin-left", "0", "--margin-right", "0", "--footer-spacing", "5", "--footer-html", "file:////tmp/wicked_footer_pdf20160714-2229-1bb7qcg.html", "file:////tmp/wicked_pdf20160714-2229-18kjik5.html", "/tmp/wicked_pdf_generated_file20160714-2229-1t66b4y.pdf"] Error: PDF could not be generated! Command Error: terminate called after throwing an instance of 'std::bad_alloc'

I am not able to reproduce this on my local/staging.

The following is my setup: Production server running on Centos 7 on AWS-EC2. Copied wkhtmltopdf binary for linux 64-bit from http://wkhtmltopdf.org/downloads.html to /usr/local/bin/wkhtmltopdf with version 0.12.0. Added initializer for Wickedpdf to point to wkhtmltopdf.

2

2 Answers

1
votes

We had the same issue with wkhtmltopdf-0.12.2.1. Also PDFs were rendering very slow

wkhtmltopdf v0.12.0-0.12.2 uses high resolution (about 1200dpi) to print PDFs which caused slow rendering issue. In the version 0.12.3 the resolution was dropped to 72dpi which fixed the performance issue (See this issue for the details)

Upgrade to v0.12.4.0 fixed the Command Error: terminate called after throwing an instance of 'std::bad_alloc' either

0
votes

I had the same problem and with @Hirurg103 answer's I had an idea of workaround: I set the dpi attribute for my pdf and it worked

  respond_to do |format|
    format.html
    format.pdf do
      render pdf: "my-report, dpi: 75
    end
  end