boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
734 stars 155 forks source link

CombinePDF::ParsingError Exception: Unknown PDF parsing error - malformed PDF file? error #189

Closed adnanmirza1 closed 3 years ago

adnanmirza1 commented 3 years ago

Hey, i'm facing the issue. i'm trying to parse PDF stored in my active storage. with url_for and facing this error CombinePDF::ParsingError Exception: Unknown PDF parsing error - malformed PDF file?

i'm using following syntax: url = url_for(Candidate.last.pdf) pdf = CombinePDF.parse(Net::HTTP.get_response(URI.parse(url)).body)

adnanmirza1 commented 3 years ago

Hey! so i solved it myself by using temp file. Like this: @cans.pdf_doc.open(tmpdir: "app/assets/pdfs") do |file| pdf = CombinePDF.new a = File.basename(file) pdf << CombinePDF.load("app/assets/pdfs/#{a}") pdf.save "combined.pdf" end