0

I want to only skip the CombinePdf::ParsingError (Optional Content PDF files aren't supported and their pages cannot be safely extracted.) when i upload a pdf file inside my begin/rescue but it's not working, how can i do ?

begin
  FileManager::PdfValidation.new(uploaded_files)
rescue ParsingError => e
end
Steph
  • 27
  • 4
  • 1
    I don't know combine-pdf, but if what you write is true, it should be `rescue CombinePdf::ParsingError`. Or do I miss something? – user1934428 Jun 15 '22 at 13:14

2 Answers2

1

If you look at the code of combine_pdf you see that it is possible to parse files with optional content.

Also, the README states:

Sometimes the CombinePDF will raise an exception even if the PDF could be parsed (i.e., when PDF optional content exists)... I find it better to err on the side of caution, although for optional content PDFs an exception is avoidable using CombinePDF.load(pdf_file, allow_optional_content: true).

You could try that.

Alternatively, depending on what your use case is, you can try pdf-reader (if you just wanna read something from the PDF) or HexaPDF (which is a fully-featured PDF library; n.b. I'm the author of HexaPDF).

gettalong
  • 735
  • 3
  • 10
1

Try this:

CombinePDF.load("your_file.pdf", unsafe: true, allow_optional_content: true)

Source: https://github.com/boazsegev/combine_pdf/issues/28#issuecomment-1376413479

Bruno De Freitas Barros
  • 2,199
  • 2
  • 17
  • 16