-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null Byte #9
Comments
Thanks for opening the issue. Because you mentioned the code is working fine on your mac (but not on Heroku), I'd like to try a few things before I start looking into the code on my end. I would like to start with changing the file access code, removing the temporary files and using the CombinePDF.parse to read the raw data (instead of CombinePDF.new that accepts filenames). I suggest this change because normally Heroku acts up when using file writing permissions (slugs are read-only, that's also why sqlite cannot be used on Heroku). Also, you were passing the CombinePDF.new method the PDF's content (instead of a file name). The last reason for which I recommend avoiding tmp files (aside of performance), is the issue of simultaneous access... It's just safer to avoid a system resource that might be in use by a parallel request. Have a look at this, try it out and let me know how it works: require 'open-uri'
def pdf(number)
# loading the logo seems fine, as we are only reading from a file
company_logo = CombinePDF.new("logo.pdf").pages[0]
# I changed the CombinePDF.new(filename) to CombinePDF.parse(pdf_stream),
# so there's no need to save a tmp file.
pdf = CombinePDF.parse open("http://patentimages.storage.googleapis.com/pdfs/#{number}.pdf").read
# stamping each page would work if the parsing actually worked
pdf.pages.each {|page| page << company_logo}
# saving in Heroku WILL **PROBABLY** FAIL(!), so this is just for testing:
pdf.save "#{number}.pdf" unless ENV['DYNO']
# as an alternative to saving the file, try sending the raw PDF stream:
pdf.to_pdf
end In case the issue persists, could you attach the whole of the error message? - I'd like to know which method raises the exception. |
PERFECT! Idk why I didn't think to try parse. Fyi for Heroku the saving wasn't an issue. Here's my final code for future reference for any future googlers who maybe have the same issue..
|
Thanks for the update, I'm happy it worked out :) |
So I'm pulling down a remote PDF file on Heroku. I want to add a watermark on it. This works perfect locally on Mac, but in production on Heroku it's failing. This is how I'm doing it
So I'm pulling down a remote PDF file on Heroku. I want to add a watermark on it. This works perfect locally on Mac, but in production on Heroku it's failing. This is how I'm doing it
def pdf(number)
require 'open-uri'
company_logo = CombinePDF.new("logo.pdf").pages[0]
open("#{number}.pdf", 'wb') do |file|
file << open("http://patentimages.storage.googleapis.com/pdfs/#{number}.pdf").read
end
pdf = CombinePDF.new open("#{number}.pdf").read
pdf.pages.each {|page| page << company_logo}
pdf.save "#{number}.pdf"
end
However this line is failing:
pdf = CombinePDF.new contents
With this:
ArgumentError: string contains null byte
Also before the error I see this:
PDF 1.5 Object streams found - they are not fully supported! attempting to extract objects.
Again this works perfectly locally on Mac without any changes in code. What am I missing?
Btw,
number
in this case is"US5409533"
The text was updated successfully, but these errors were encountered: