Wicked PDF gem works locally but displays different font when deployed - ruby-on-rails

I’m trying to generate PDFs in a Rails 4.2 app using the Wicked PDF gem and everything works fine locally. However, when deployed to other environments the PDF renders but most* of the text is displayed as what appears to be characters from “Cursor Font” which I've never seen before but it appears to be something bundled with X11.
*I say "most" because some of the PDF text renders normally if enclosed in certain html tags. For example, if I change p-tags to h1 tags, normal font is displayed, but obviously I don't want the entire document to look like one big header.
I checked the logs; no errors are being generated.
I’ve tried various combinations of Wicked gem versions and wkhtmltopdf binaries. Currently using gem 'wicked_pdf'and gem 'wkhtmltopdf-binary-edge'.
I’ve closely followed the Wicked PDF set-up documentation to include
PDF mime type, a wicked_pdf.rb initializer file, precompiled
assets, and absolute asset paths. Currently using (although have tried many variations) stylesheet_link_tag wicked_pdf_asset_base64("pdf.css.scss") and javascript_include_tag wicked_pdf_asset_base64("application")
Any ideas/advice on why this is happening is greatly appreciated!

Related

IMGKit gem generate unexpected values in image

I'm using imgkit gem to create JPGs and PNGs from HTML, it is working fine in development, but in production server it does not showing text in images instead showing boxes other than text.
Example can be seen here

Mixed orientations in wicked pdf

Currently I am using wicked_pdf gem to create pdf in my ROR (ruby on rails application).
My pdf have 4 pages. In which 1 is chart. I need that page alone to be landscape dynamically.
Is it possible using wicked_pdf or any other gem?
PS: I tried to generated each pdf and combining them but the image
changes pages based on the content of the previous pages.
wicked_pdf is a plugin that relies on the wkhtmltopdf project to generate the actual PDFs. wkhtmltopdf does not yet implement this feature, so until that is complete there is no easy way to get mixed-orientation PDF files.
There is an outstanding feature request to implement this, so watch that issue for any updates. It appears that at this time there is some work being done on this issue but it will take time for it to both make it into wkhtmltopdf and be picked up by wicked_pdf.
In the meantime there is a workaround that some people have attempted involving CSS rotations and media selection stylesheets.
Others have attempted to generate multiple PDFs separately and stitch them together with some programs like ghostscript. See the above workaround page for more details.

Prawn + WickedPDF: Using Prawn on wkhtmltopdf/WickedPDF generated PDF's

I am working on a Rails project with both WickedPDF and Prawn. I am using WickedPDF to convert some HTML into a PDF and then using Prawn to add content to that PDF.
When I add content to an uploaded PDF (one that I do not create), Prawn is able to add content without any issues. When I create a PDF using WickedPDF, Prawn has issues when it adds content to the the new WickedPDF generated PDF. It adds the content, but the content seems to be scaled down... a lot (it's barely visible). If I open that same PDF from another program (Gimp, LibreDraw, etc.) and export as PDF, the new PDF works on Prawn as well. So I'm positive it has something to do with the formatting of the WickedPDF generated PDF's. I need Prawn to edit the PDF's that are being generated by WickedPDF, or to be able to generate PDF's that are editable by Prawn.
I searched for other solutions, and found Prawnto (no longer exists), PDFKit (gem installers did nothing), PDFcrowd (I can't pay for it), and am now running out of ideas. I'll be looking through the wkhtmltopdf source code to see if I can further understand the underlying issue (I doubt it, don't know enough about PDF file structure/formatting), but would be very happy if someone has encountered this and has any other ideas.
EDIT 1: Same results occur after creating a PDF from wkhtmltopdf. The issue is not with WickedPDF but with the library it uses. Still haven't found the cause.
EDIT 2: Another interesting result. The text is not only getting scaled down. I just multiplied the font size of the text that Prawn is inserting by 128 so I could see the text. Turns out it is also being flipped upside-down (about the x-axis). Something sinister is happening.
I've just started looking into PDF generators. On this forum, one post mentions that he had scaling issues while using gems that relied on wkhtmltopdf, but didn't experience the problems if he called that library directly.
Hope this helps! I'll update this answer once I get started if I have the same issue but am able to resolve it. Cheers!

serving a static page built with skel on Rails

I found a nice template online and want to use it for my rails app homepage. I decided to use the high voltage gem and read through its readme. I managed to get the routing right but I could not find the appropriate path/folder for the numerous asset (css, js, svgs and sass) files which come inside the template zip file, and which obviously make it look nice.
I tried putting them into the assets folder of my rails app, which got some of the "features" working, but svgs and images didn't display... and it screwed my existing pages. Reading through the Rails documentation I then tried storing the template assets into the vendor folder, which did not work either.
Where should I store the assets for my template-inspired homepage for them not to screw the appearance of my normal/app pages? Which paths should I use in my html to call them?
If you have troubles with images, take a look at image references in the template source. You can see a reference to image like this :
background-image: url('images/top-1280.svg')
which would not serve this image in Rails.
I would suggest to find and replace all the image references in your css (or scss) files.
Try this :
background-image: url(image-path('top-1280.svg'));
which is the proper way for Rails 4.
The differences:
in Rials you have a helper method "image-path" and you do not prefix the image file with directory name.
It is important to check in your "app/assets/stylesheets/appilcation.css" if there are lines like:
*= require_tree .
*= require_self
Now about Font Awesome : I see that in this theme you are about to use Font Awesome. I would suggest using the gem for Rails:
In your Gemfile:
gem 'font-awesome-sass'
I think the theme you have chosen is very nice. Thank you for sharing it, it will be useful for my current project.

wicked_pdf, wkhtmltopdf not working with SVG on Heroku

I have a Ruby on Rails 3.2 app using the wicked_pdf gem and wkhtmltopdf 0.9.9 library to produce PDFs on my local machine, which is a MAC OSX 10.7.5 Lion. The app successfully renders HTML pages (that include SVG images) as PDF files, which is the exact behavior we're aiming for the app to accomplish.
On local, we had to use wkhtmltopdf 0.9.9 due to a bug on the 11.0.0 version for OSX.
The problem is that when the app is pushed to production on Heroku, it has to use a different binary: wkhtmltopdf-0.9.9 Linux Static Binary (amd64) and the SVG rendering seems to fall apart. A PDF is produced, but the SVG images are not rendered properly. They are simply blank or square "shells" where the images should be.
We tried using the wkhtmltopdf-heroku gem, but kept getting a "Broken Pipe" error.
There is no error message related to this issue and we don't know where the problem lies with the Linux versions. Any ideas out there?
This is our code in the config/initializers/wicked_pdf.rb file:
if Rails.env.staging? || Rails.env.production?
exe_path = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
else
exe_path = Rails.root.join('bin', 'wkhtmltopdf').to_s
end
There is an easy way that works without having to do heavy tinkering and configuration – Base64-encode the SVG file and include it inline in your HTML:
<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGF...>
I use this method for embedding fonts in CSS, but it works with SVG and other image formats as well.

Resources