Find size of a PDF without margins
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Write a command-line program which runs on linux.

Input: PDF filename (Example: abc/example.pdf)

Output: Size of the PDF in inches, excluding margins. (Example: 8x9.23)

awarded to dekkard
Tags
pdf

Crowdsource coding tasks.

1 Solution

Winning solution

You'll need Ghostscript for this.

Here's the command that calculates the Bounding Box for a PDF (replace input.pdf with your file name):

gs -dNOPAUSE -dBATCH -sDEVICE=bbox input.pdf 2>&1 | awk 'BEGIN{ppi=72; i=1;} /%BoundingBox/{ printf("Page %d: ",i); print ($4-$2)/ppi,"x",($5-$3)/ppi; i=i+1; }'

Sample output:

Page 1: 7.375 x 10.5694
Page 2: 7.33333 x 10.5694
Page 3: 7.33333 x 10.5694

The sizes are in inches.

Great, per-page output is also fine.
vanceza 4 years ago