Reputation: 6476
I'm trying to use the gem combine_pdf
in order to combine a number of PDFs in my app. They are located in assets/forms/packages/1.pdf 2.pdf 3.pdf
.
I'm trying to following the gem's guide but the code yields an error:
@pdfForms = CombinePDF.new
@pdfForms << CombinePDF.new('assets/forms/packages/1.pdf')
I get a runtime error:
root is unknown - cannot determine if file is Encrypted
Any help is much appreciated, or another way to merge pdfs. The gem pdf-merge
fails with my app due to its dependency on rjb
.
Thanks!
Upvotes: 1
Views: 3609
Reputation: 19221
Try using CombinePDF.load
instead of CombinePDF.new
.
new
will try both loading the file and parsing the string - so you won't see the file loading exceptions.
It could be that the file path is wrong and CombinePDF is trying to parse 'assets/forms/packages/1.pdf' as if it were the content of a PDF file.
Your code should look like this:
@pdfForms = CombinePDF.new
@pdfForms << CombinePDF.load('assets/forms/packages/1.pdf')
Upvotes: 0
Reputation: 3803
Try to open a file by using
File.open("assets/forms/packages/1.pdf")
If this is not working then your file path is wrong. If this pdf file is in your app/assets folder of your application then you can access it by using:
file_path = Rails.root.join("app", "assets", "forms", "packages","1.pdf")
File.open(file_path)
Upvotes: 2