ruby-on-railsrubypdfexceptioncombine-pdf

Ignore a CombinePdf exception


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

Solution

  • Try this:

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

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