I am trying to create a pdf file from an html page using wicked_pdf (version 1.1) and wkhtmltopdf-binary gems. My html page contains an emoji calendar that displays well in the browser any font that I use
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv='content-type' content='text/html; charset=utf-8' /> <style> unicode { font-family: 'OpenSansEmoji', sans-serif; } @font-face { font-family: 'OpenSansEmoji'; src: url(data:font/truetype;charset=utf-8;base64,<-- encoded_font_base64_string-->) format('truetype'); } </style> </head> <body> <div><unicode>📅</unicode></div> </body> </html>
However, when I try to generate a PDF using the WickedPdf.new.pdf_from_html_file method for gem in the rails console,
File.open(File.expand_path('~/<--pdf_filename-->.pdf'), 'wb+') {|f| f.write WickedPdf.new.pdf_from_html_file('<--absolute_path_of_html_file-->')}
I get the following result:
PDF result with unknown character
As you can see, the icon of the first calendar is displayed correctly, but there is a second symbol that is displayed, we do not know where it comes from.
I explored using coding in UTF-8 and UTF-16 and a surrogate pair, as suggested by this related entry, https://stackoverflow.com/a/464939/ ... , and examined this problem wkhtmltopdf_git_issue , but this character still cannot disappear!
If you have any tips, this is more than welcome.
Thanks in advance for your help!
EDIT
Following the comments of Eric Duminil and petkov.np, I can confirm that the above code works correctly for me on Linux. This seems to be a Linux issue against MacOS. Can anyone suggest that the kernel of the problem is tied to MacOS and can it be fixed?
ruby ruby-on-rails unicode wkhtmltopdf wicked-pdf
rico1892
source share