Skip to content

Instantly share code, notes, and snippets.

@jackie-do
Last active December 5, 2018 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackie-do/83f2e191207b64d998fd9653909a08f0 to your computer and use it in GitHub Desktop.
Save jackie-do/83f2e191207b64d998fd9653909a08f0 to your computer and use it in GitHub Desktop.
wicked-pdf on Amazon Linux Image and Japanese
  1. Install gem wicked-pdf
  2. Install gems to allow generate pdf from html (using wkhtmltopdf library)

wkhtmltopdf-binary ~ for general

wkhtmltopdf-binary-edge ~ for MacOS and Ubuntu/CentOS

'wkhtmltopdf-binary-aml', git: 'https://github.com/insphire/wkhtmltopdf-binary-aml' ~ for Amazon Linux (use this one)

  1. Set UTF-8 in HTML
<meta  http-equiv="content-type"  content="text/html; charset=UTF-8"  />
# or
<meta charset="UTF-8">
  1. Install Japanse fonts into AMI
# Download fonts
wget "http://jaist.dl.sourceforge.jp/mix-mplus-ipa/59021/migmix-2p-20130617.zip"

unzip migmix-2p-20130617.zip

# Copy font to new folder '/usr/share/fonts/japanese/TrueType/'
sudo mv -i migmix-2p-20130617/*ttf /usr/share/fonts/japanese/TrueType/
# load new folder
ls /usr/share/fonts/japanese/TrueType/
# output: migmix-2p-bold.ttf  migmix-2p-regular.ttf

# Clear font cache
fc-cache -fv

# check new fonts loaded or not
fc-list | grep Mig
# output: MigMix 2P:style=Bold        MigMix 2P:style=Regular
  1. Optional: config in 'wicked_pdf.rb' for load executable file 'wkhtmltopdf'
# base on gem
Gem.bin_path('wkhtmltopdf-binary-edge', 'wkhtmltopdf')
# or
"#{Gem.loaded_specs['wkhtmltopdf-binary'].full_gem_path}/bin/wkhtmltopdf"

# base on file in system
if File.exist?(File.expand_path('~/.rbenv/shims/wkhtmltopdf'))
  File.expand_path('~/.rbenv/shims/wkhtmltopdf')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment