I need to convert PDF files to EPS.. Then I need to strip all text and images.. So far this works

pdftocairo -f 1 -l 1 -eps test.pdf - | sed '/BT/,/ET/ d' | sed '/^8 dict dup begin$/,/^Q$/ c Q' > no_text_and_images.eps

But how to check if the EPS file even contains vector? I need to do some OCR on the output - but only if vector is present in the file.. If it only contains text and images I don't want to use resources to run it through a OCR process

Sample file: http://docdro.id/yJZTGBt

  • I have an idea, but I'd have to test it. Do you have a sample of a document that contains pages that contain the various permutations of {has,does not have} {vector,text,image}? – hackerb9 Mar 16 '18 at 12:23
  • By the way, you may want to change the title from EPS to PDF since that's what you actually want. (And the solution may be easier from a PDF since there are more tools). – hackerb9 Mar 16 '18 at 12:24
  • @hackerb9, sorry didn't see your comments.. have added a link to a sample pdf file :) – clarkk Mar 20 '18 at 11:53

You can use ImageMagick. The '-trim' option crops an image as small as possible and will tell you if your image is completely empty:

$ convert -trim no_text_images.eps foo.jpg
convert-im6.q16: geometry does not contain image [...]

Because the convert command does not return an error code for this warning, your shell script will need to grep the stderr.

if ! convert -trim no_text_images.eps foo.png 2>&1 |
     grep 'does not contain image'; then
    [ there's an image, so process it ]
    [ there's no image ]

However, now that I see what you're working on I may have a simpler solution for you. Why not try using ocrmypdf? Just sudo apt install ocrmypdf to install it on your Debian box.

I ran it on the PDF you gave me and, even though I have my tesseract set to English, it got a reasonable rendering of the vector you have at the top of the form:

$ ocrmypdf  --force-ocr  --oversample 150  084.pdf  foo.pdf
$ pdftotext foo.pdf -  |  less
Otto M¢nsteds


Muller Vinhandel


Aalbors SV- Tlf. 98 18 50 99- E-mail: vin@smv.dk- www. smv. dk
53 92 79 12- Nordjyske Bank 7450- 2038354

2- 9200



Import, salg as distribution if Vin cg spiritus
Eneiurhandler i Danmark af

udsIgte vine fra hale verden.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.