Reputation: 745
In my task
table I can access pdf file @task&.assignable&.pdf_file
that is stored on s3 bucket.
I can access to its url using @task&.assignable&.pdf_file.file.url
I want to add a new page in the same pdf file so I am using combine_pdf gem. It is getting path of file1
that I have generated with wicked_pdf
but on line
pdf << CombinePDF.load(@task&.assignable&.pdf_file.file.url)
It is showing error:
No such file or directory @ rb_sysopen - https://patientiq1.s3-us-east-2.amazonaws.com/uploads/ < hashed_path >.pdf? < access_key >
file1_path = Rails.root.join('tmp', filename)
pdf = WickedPdf.new.pdf_from_string(
render_to_string('patient_engagements/signed_page', layout: 'pdf', locals: { :@signed_pdf => @signed_pdf })
)
File.open(file1_path, 'wb') do |file|
file << pdf
end
pdf = CombinePDF.new
pdf << CombinePDF.load(file1_path) # one way to combine, very fast.
pdf << CombinePDF.load(@task&.assignable&.pdf_file.file.url)
pdf.save "combined.pdf"
Upvotes: 0
Views: 1773
Reputation: 10564
You can not use load with remote files, use parse instead
require 'combine_pdf'
require 'net/http'
url = "https://example.com/my.pdf"
pdf = CombinePDF.parse Net::HTTP.get_response(URI.parse(url)).body
Extracted from Loading and parsing DPF data at CombinePDF docs.
Upvotes: 4