I have added a PDF output function using the gems wicked_pdf
and wkhtmltopdf-binary
, but the following error occurs in the production environment although it works well in the development environment.
Rails version is 4.2.
RuntimeError (Failed to execute:
["/var/www/~~~/shared/bundle/ruby/2.4.0/gems/wkhtmltopdf-binary-0.12.6.3/bin/wkhtmltopdf", "--encoding", "UTF-8", "--page-size", "A4", "file:////tmp/wicked_pdf20201007-11835-gppxfs.html", "/tmp/wicked_pdf_generated_file20201007-11835-j83wu8.pdf"]
Error: PDF could not be generated!
Command Error: /var/www/~~~/shared/bundle/ruby/2.4.0/gems/wkhtmltopdf-binary-0.12.6.3/bin/wkhtmltopdf_centos_7_amd64: error while loading shared libraries: libpng15.so.15: cannot open shared object file: No such file or directory
):
It seems that there is no library called libpng15.so.15
, but I searched the net for the same error and tried various things, but it did not solve.
This is an article from 2016, but the following was helpful. https://qiita.com/s-mori/items/00aef46e6a10499f8254 https://qiita.com/yaboojp/items/526c9397070ca5d05256
wkhtmltopdf-binary
doesn't seem to support Amazon Linux,
It worked fine using wkhtmltopdf-binary-aml
, which is compatible with Amazon Linux.
Gemfile before modification
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary-aml'
Modified Gemfile
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary-aml', git: 'https://github.com/insphire/wkhtmltopdf-binary-aml'
wicked_pdf
before modification
config/initializers/wicked_pdf.rb
WickedPdf.config = {
:exe_path => "#{Gem.loaded_specs['wkhtmltopdf-binary'].full_gem_path}/bin/wkhtmltopdf"
}
Modified wicked_pdf
config/initializers/wicked_pdf.rb
WickedPdf.config = {
:exe_path => "#{Gem.loaded_specs['wkhtmltopdf-binary-aml'].full_gem_path}/bin/wkhtmltopdf"
}
I did bundle install so that the version of Bundler wouldn't change.
$ bundle _1.16.1_ install
When deploying to the production environment, Japanese was not displayed. So install the IPA font on the production server.
cd /usr/share/fonts
$ yum install -y ipa-gothic-fonts ipa-mincho-fonts
Since the layout was broken by changing the font, I was able to complete the receipt function by adjusting the CSS etc.
By changing to a Gem compatible with Amazon Linux, an error will occur in the development environment this time.
RuntimeError - PDF could not be generated!
Command Error: /Users/~~~/vendor/bundle/ruby/2.4.0/bundler/gems/wkhtmltopdf-binary-aml-e5340ed88aa8/bin/wkhtmltopdf:15:in `exec': Bad CPU type in executable - /Users/~~~/vendor/bundle/ruby/2.4.0/bundler/gems/wkhtmltopdf-binary-aml-e5340ed88aa8/libexec/wkhtmltopdf-darwin-x86 (Errno::E086)
To do it well in both development and production environments, you can use ʻif Rails.env.production?Etc. to separate
wicked_pdf.rb`.
You can do this by switching the Gemfile for each environment as follows.
group :development do
gem 'wkhtmltopdf-binary'
end
gem 'wkhtmltopdf-binary', group: :development
Recommended Posts