CombinePDF.parse is unable to process some PDF files

79 views Asked by At

Tech Stack used

Ruby 2.5.8, Rails 5.0.7, Ruby Gems: combine_pdf

Here is my sample code that is working for most of the PDF Urls hosted in S3, except one PDF.

@pdf = CombinePDF.new
@pdf << CombinePDF.parse(Net::HTTP.get_response(URI.parse(s3_pdf_url)).body)
@pdf = @pdf.to_pdf

Above code is working as expected for 90% of the PDF files, there is one file that is not working for me. I don't see any exceptions generated and not sure how to debug it.

CombinePDF do generates the final pdf and it is blank as shown in this screenshot_link.

Any feedback would be appreciated.

Here is my another example code. I'm writing original S3 PDF into the Tempfile and using CombinePDF.load() to combine the PDF which is there inside tempfile. But still this PDF is not combined and no exception generated. When I opened tempfile(MyPDF20220921-21580-1qzgy1u.pdf) I can see and access PDF.

path = s3_pdf_url
t = Tempfile.new(["MyPDF", '.pdf'])
t.write(open(path).read.force_encoding(Encoding::UTF_8))
t.close
@pdf = CombinePDF.load t.path
@pdf = @pdf.to_pdf
0

There are 0 answers