7

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.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Vladimir
  • 103
  • 1
  • 9

6 Answers6

5

You could run this command on pdf files and check if anything raster exists on the file:

  grep -c -i "/image" thisfile.pdf
Yeak
  • 2,470
  • 9
  • 45
  • 71
1

You could convert the image to EPS format, and search if "/ImageType" exists. The "/ImageType" means the following object is a raster image. If it doesn't exist in the whole EPS file, this EPS is a vector file.

SuperBerry
  • 1,193
  • 1
  • 12
  • 28
  • This answer was most helpful to me using Windows (no grep function). I was able to drop the EPS file into a text editor and search for /ImageType to confirm the file was indeed a raster image. – Kyle Jul 23 '20 at 12:19
1

If you are a Linux user, you can use the Poppler utilities to obtain a list of the raster elements within the PDF:

pdfimages -list filename.pdf

This will return a table containing information for each raster: pdfimages_output

It should be relatively straightforward to parse this information programmatically from the console. For example, in Python you can use the subprocess module:

out = subprocess.check_output('pdfimages -list filename.pdf', shell=True)
StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
0

You can search for DeviceRGB in EPS/AI files

0

The presence of 'DisplayImage' seems to be an indication that an EPS file is made from a raster image. The 'DeviceRGB' and '/ImageType' solutions dis not work on my EPS files (these directives were not present in an EPS file I made from a PNG file with 'convert').

-3

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.

johannes
  • 7,262
  • 5
  • 38
  • 57
  • 2
    This may be correct in some form of theoretical way which I do not grasp, but it bothers me that it sits as the accepted answer to a question still valid. Since an EPS can be opened and rendered, of course it is possible to determine if it contains raster elements or not. Adobe Illustrator does it every time I open an EPS file, possible or not. – Culme Sep 22 '17 at 07:40
  • It is not possible to prove that a program terminates, in general. That does not mean that you cannot prove specific programs terminate. In fact, most programs are simple enough that you can prove they terminate. Just rendering the PS file proves it terminates. – Cris Luengo Aug 02 '20 at 14:46