Reputation: 27
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
Upvotes: 0
Views: 780
Reputation: 2409
Try this:
CombinePDF.load("your_file.pdf", unsafe: true, allow_optional_content: true)
Source: https://github.com/boazsegev/combine_pdf/issues/28#issuecomment-1376413479
Upvotes: 3
Reputation: 830
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).
Upvotes: 2