1
votes

I am trying to make a flyer creator app and am having a hard time getting the page to save as a pdf.

After doing a bit of googling I found a couple options and landed on pdfkit. The rails casts video made it look very simple, then like always, being on a windows machine, I found it didn't exactly apply. I have tried a ton of tutorials but am still unable to get my local environment working.

I eventually would like to deploy this solution to heroku and that seams to also require some extra steps.

My gems include,

gem "pdfkit"

my application.rb includes

config.middleware.use "PDFKit::Middleware", :print_media_type => true

I have in my /config/initializers I have pdfkit.rb that contains

PDFKit.configure do |config|
  config.wkhtmltopdf = 'C:/wkhtmltopdf/bin/wkhtmltopdf.exe'
  config.default_options = {
    :page_size => 'Legal',
    :print_media_type => true
  }
end

Is there anything else needed I may have missed?

I have seen the gem "wkhtmltopdf-binary" referenced in some tutorials, do I need this gem? what is it doing?

I have installed the wkhtmltopdf application all over my computer at this point, I saw one tutorial that placed the install in the actual root of the app, in the root of my C: drive and elsewhere. Even when I think I got this part right at best I got the message

"Exit with code 1 due to network error: ContentNotFoundError"

I would really like some help getting PDFKit to work on my local environment, and then deploy that solution to heroku. Can anyone help?

I can show any code snippets needed I am just unsure what would be helpful.

In case it helps anyone here is a link to my work in progress site / an example page that I would like turned into a pdf.

http://www.easyflyerceator.com/carpet_cleaning_flyers/1/carpet_cleaning1s/4

1
Can't help locally but as for deployment you might need a build pack for that. I use pdftk with heroku and it requires a custom build pack to actually create the application on the server. Also you might want to look at wicked_pdf I have heard good things when converting html to a pdf. Finally have you tried dropping the C: portion of the path because / means root.engineersmnky

1 Answers

1
votes

Problem is with wkhtmltopdf.exe path in pdfkit.rb, move your binary file to bin folder of the project(Create one, if it’s not there. You can create any other folder too but then remember to change the path in the initializers.) and then specify same path in pdfkit.rb as follow:

PDFKit.configure do |config|
  config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf').to_s
  config.default_options = {
    :page_size => 'Legal',
    :print_media_type => true
  }
end

You can refer Converting HTML to PDF.