Reputation: 3029
I'm currently working on a Rails 5.2 application using the combine pdf gem. I'm trying to merge two PDF files but somehow I'm unable to load files from the public
directory.
In the controller I have the following method:
def pdf_download
pdf = CombinePDF.new
pdf << CombinePDF.load("#{Rails.root}/public/pdfs/1.pdf")
pdf << CombinePDF.load("#{Rails.root}/public/pdfs/1.pdf")
pdf.save "combined.pdf"
send_data combined_file.to_pdf, filename: "combined.pdf", type: "application/pdf"
end
I have tried many posts on StackOverflow without success such as using Rails.root. But I still get the same error:
Errno::ENOENT (No such file or directory @ rb_sysopen - app/public/pdfs/1.pdf):
Is there any additional configuration I have to do to load files from public
? and if these PDF shouldn't be in public
where should I store them?
Upvotes: 2
Views: 1886
Reputation: 11
This fixed it for me:
pdf << CombinePDF.load("./public/pdfs/1.pdf")
Upvotes: 1
Reputation: 3029
This fixed it for me:
def pdf_download
pdf = CombinePDF.new
pdf << CombinePDF.load(Rails.root.join("public", "pdfs/1.pdf").to_s)
pdf << CombinePDF.load(Rails.root.join("public", "pdfs/2.pdf").to_s)
# pdf.save "combined.pdf"
send_data pdf.to_pdf, filename: "combined.pdf", type: "application/pdf"
end
Upvotes: 1