Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I tell the resolution of scanned PDF from within a shell script?
    primarykey
    data
    text
    <p>I have a large collection of documents scanned into PDF format, and I wish to write a shell script that will convert each document to <a href="http://djvuzone.org/" rel="noreferrer">DjVu</a> format. Some documents were scanned at 200dpi, some at 300dpi, and some at 600dpi. Since DjVu is a pixel-based format, I want to be sure I use the same resolution in the target DjVu file as was used for the scan.</p> <p>Does anyone know what program I can run, or how I can write a program, to determine what resolution was used to produce a scanned PDF? (Number of pixels might work too as almost all documents are 8.5 by 11 inches.)</p> <hr> <p>Clarification after responses: I'm aware of the difficulties highlighted by Breton, and I'm willing to concede that the problem in general is ill-posed, but I'm not asking about <em>general</em> PDF documents. My particular documents came out of a scanner. They contain one scanned image per page, same resolution each page. If I convert the PDF to PostScript I can poke around by hand and find pixel dimensions easily; I could probably find image sizes with more work. And if in desperate need I could modify the dictionary stack that <code>gs</code> is using; long ago, I wrote an interpreter for PostScript Level 1.</p> <p>All of that is what I'm trying to avoid. </p> <hr> <p>Thanks to help received, I've posted an answer below:</p> <ol> <li>Extract the bounding box from the PDF using <code>identify</code>, taking only the output for the first page, and understanding that the units will be PostScript points, of which there are 72 to an inch.</li> <li>Extract images from the first page using <code>pdfimages</code>.</li> <li>Get height and width of image. This time <code>identify</code> will give number of pixels.</li> <li>Add the total <em>areas</em> of the images to get the number of dots squared.</li> <li>To get resolution, compute areas of bounding box in inches squared, divide dots squared by inches squared, take the square root, and round to the nearest multiple of 10.</li> </ol> <p>Full answer with script is below. I'm using it in live fire and it works great. Thanks Harlequin for <code>pdfimages</code> and Spiffeah for the alert about multiple images per page (it's rare, but I've found some).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload