Code Monkey home page Code Monkey logo

Comments (10)

caioagiani avatar caioagiani commented on May 20, 2024 8

Try this:

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

from combine_pdf.

boazsegev avatar boazsegev commented on May 20, 2024 4

Some PDF files are designed to display different content according to the media on which they are displayed.

For example, a PDF file might display one way when viewed on screen and it might replace some images or text when printed on paper... Just like some websites use the CSS media query.

These PDF file required very specific instructions inside their structure. Ignoring these instructions might produce corrupted files or files that look very different than what you wanted them to look like.

Because of the issues related with this structure, these files are not supported for now and cannot be merged with other PDF files.

On Sep 3, 2015, at 05:04, cw6365 [email protected] wrote:

i get the following runtime error "Optional Content PDF files aren't supported and their pages cannot be safely extracted", this is a one off error and doesn't normally happen so looks to be pdf specific.

I've had a look at the code but can you quickly clarify the issue here for me please. Thanks.


Reply to this email directly or view it on GitHub.

from combine_pdf.

joelw avatar joelw commented on May 20, 2024 4

Thanks for your quick response (and for the gem!) I've put something together and will create a PR :)

from combine_pdf.

chrisconcepcion avatar chrisconcepcion commented on May 20, 2024 1

Ran into this issue and found an odd solution using the libreconv gem. Essentially you convert the pdf to a pdf with libreoffice and this will make the pdf compatible with combinepdf. Hope this helps someone, took me hours to figure this out.

Libreconv.convert(document_path, document_path)

from combine_pdf.

andyrue avatar andyrue commented on May 20, 2024

What's the best way to rescue from this error? I tried wrapping my CombinePDF.load command in a begin, rescue but it hangs upon running.

from combine_pdf.

boazsegev avatar boazsegev commented on May 20, 2024

@andyrue , could you post your code you tried?

The following should work (I think, I don't have a file to test with):

filename  = 'file.pdf'
begin
   pdf = CombinePDF.load filename
rescue => e
   puts "Couldn't load #{filename}: #{e.message}"
end

from combine_pdf.

andyrue avatar andyrue commented on May 20, 2024

Seems there was some ruby process stuck. I killed it with activity monitor and the begin rescue works now. Thanks for your quick response!

from combine_pdf.

joelw avatar joelw commented on May 20, 2024

Would you support a PR to add an option to ignore this error? For my use case I'd be happier with potentially weird output than no output at all, and when I've tested commenting out the raise my test PDFs look just terrific!

from combine_pdf.

boazsegev avatar boazsegev commented on May 20, 2024

Hi Joel,

Thanks for asking.

If the PR allowed this as a non-default option, yeah sure.

I think it's better if the default would fail then to risk quite failures (missing data), but I definitely understand that different implementations might prefer a different behavior.

P.S.

If you're writing in a option flag to the existing API (i.e. CombinePDF.load file_name, unsafe: true), it might be better to use a hash then a simple argument, allowing for future features and alterations.

from combine_pdf.

mackermedia avatar mackermedia commented on May 20, 2024

Ran into this issue and found an odd solution using the libreconv gem. Essentially you convert the pdf to a pdf with libreoffice and this will make the pdf compatible with combinepdf. Hope this helps someone, took me hours to figure this out.

Libreconv.convert(document_path, document_path)

@chrisconcepcion - I'm struggling to get Libreconv.convert to work with a .pdf to. .pdf. Getting an error about source file could not be loaded. However, it works if I test with a .txt file to a .pdf.
Do you have any other tips you have for getting around this issue?

from combine_pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.