Search code examples
phpimage-processingvectorraster

Check if a file contains raster or vector elements? (pdf, eps, ai)


Is there a way to check if a file has raster elements in it? I would be interested to do this for the .pdf, .eps and .ai formats.

If the file is only vector I am converting it to .svg and if it has some raster elements I have to convert it to .png file.

I am working in PHP but I can utilize any command line tools as well. For instance I am considering using Inkscape to do the actual conversion.


Solution

  • No there is not.

    The following is a theoretical computer science proof for eps which proofs, that the asked property can not be computed.

    PostScript(ps) and also Encapsulated PostScript(eps) are turing complete programming language. In Theoretical Computer Science there exists proofs which say that certain properties of programs written in turing complete languages can not be computed. Such a property is for example, whether a given program ever terminates. So we know that there exists a PostScript Program where we can not tell whether it terminates. If we take this Program remove all raster objects from it and insert only a single raster object which will only be printed on the document if and only if the program terminates. We do this by inserting this raster printing step as last step on every program part which could lead to termination (directly before every quit command (if such a command exists) and at the end of the main). Now we have a PostScript Program for which we can not tell whether it includes printing a raster object or not. It indeed can not be told, since if we knew whether it does include printing it we also know whether it terminates and we already know, that we can not compute this property. q.e.d.