middkidd
middkidd

Reputation: 1051

Generating file with PDFKit on Heroku - No such file or directory

I'm using PDFKit to create pdfs of from a given url within a Resque job on Heroku Cedar. My code looks like:

kit = PDFKit.new(url)
pdf = kit.to_file("/tmp/#{SecureRandom.hex}.pdf")

I then upload the file using fog to S3 for permanent storage. This job usually works, but also fails maybe a third of the time with:

No such file or directory - /tmp/a05c165fc80878b75fd15c447695de71.pdf

Manually running through the code in console will produce the same error.

According to the Heroku docs, I should be able to write a temporary file anywhere in the app's directory on Cedar. I've tried creating the tmp directory first (in console) but that didn't seem to change anything. Neither did saving to "#{Rails.root}/tmp/#{SecureRandom.hex}.pdf".

Any ideas would be greatly appreciated.

UPDATE

The full error in console is:

Error: Failed loading page http://grist.org/living/you-look-great-in-green-clothing-industry-gets-a-makeover-maybe.html
(sometimes it will work just to ignore this error with --load-error-handling ignore)
Errno::ENOENT: No such file or directory - /tmp/55a1d418074736decfd4e123d8e2bba2.pdf

It seems that maybe this is an error coming from wkhtmltopdf, however, I'm not sure where to add this flag if I'm using wkhtmltopdf via PDFkit.

Upvotes: 1

Views: 3230

Answers (1)

middkidd
middkidd

Reputation: 1051

Looks like the solution, as the error I posted second suggested, was to ignore the load error. I did this with:

PDFKit.configure do |config|
  config.default_options[:load_error_handling] = 'ignore'
end

I wasn't seeing this warning at first because Resque was only showing me the final error. Thanks @ctshryock, your question made me think a little more about exactly where this error was coming from.

Upvotes: 2

Related Questions