[gs-cvs] rev 7777 - trunk/gs/toolbin
ray at ghostscript.com
ray at ghostscript.com
Fri Mar 9 12:41:25 PST 2007
Author: ray
Date: 2007-03-09 12:41:25 -0800 (Fri, 09 Mar 2007)
New Revision: 7777
Added:
trunk/gs/toolbin/pdf_info.ps
Log:
Add a utility to dump out information about PDF files. Fix
for customer #259.
DETAILS:
This is intended as an example since most customers will want
specific info, but it also is slightly handy.
We may want to do 'pdf_info' scripts and .bat files in lib/
but these can be added later.
usage: gs -dNODISPLAY -q -sFile=____.pdf [ options ] toolbin/pdf_info.ps
where "options" are:
-dDumpMediaSizes MediaBox and CropBox for each page
-dDumpFontsUsed List fonts used
-dShowEmbeddedFonts only meaningful with -dDumpFontsUsed
Sample 'full' output looks like:
examples/annots.pdf has 6 pages.
Title: Microsoft Word - Links.doc
Author: August D. Coby
Creator: ADOBEPS4.DRV Version 4.24
Producer: Acrobat Distiller 4.0 for Windows
CreationDate: D:20000420231130Z
ModDate: D:20040413162329-07'00'
Page 1 MediaBox: [ 612 792 ] CropBox: [ 612 792 ]
Page 2 MediaBox: [ 612 792 ] CropBox: [ 612 792 ]
Page 3 MediaBox: [ 612 792 ] CropBox: [ 612 792 ]
Page 4 MediaBox: [ 612 792 ] CropBox: [ 612 792 ]
Page 5 MediaBox: [ 612 792 ] CropBox: [ 612 792 ]
Page 6 MediaBox: [ 612 792 ] CropBox: [ 612 792 ]
Fonts Used:
ArialMT
IBKJPF+ArialMT
JBAHHI+ArialMT
Added: trunk/gs/toolbin/pdf_info.ps
===================================================================
--- trunk/gs/toolbin/pdf_info.ps 2007-03-08 17:24:28 UTC (rev 7776)
+++ trunk/gs/toolbin/pdf_info.ps 2007-03-09 20:41:25 UTC (rev 7777)
@@ -0,0 +1,98 @@
+% Dump some info from a PDF file
+
+% usage: gs -dNODISPLAY -q -sFile=____.pdf [-dDumpMediaSizes] [-dDumpFontsUsed [-dShowEmbeddedFonts] ] toolbin/pdf_info.ps
+
+/File where not {
+ (\n *** Missing input file name \(use -sFile=____.pdf\)\n) =
+ ( usage: gs -dNODISPLAY -q -sFile=____.pdf [ options ] toolbin/pdf_info.ps\n) =
+ ( where "options" are:) =
+ ( -dDumpMediaSizes MediaBox and CropBox for each page) =
+ ( -dDumpFontsUsed List fonts used) =
+ ( -dShowEmbeddedFonts only meaningful with -dDumpFontsUsed) =
+ () =
+ flush
+ quit
+} if
+pop % discard the dict from where
+
+/QUIET true def % in case they forgot
+
+() =
+File dup (r) file runpdfbegin
+/PDFPageCount exch def pop
+print ( has ) print PDFPageCount =print ( pages.) =
+flush
+
+% Print out the "Info" dictionary if present
+Trailer /Info knownoget {
+ dup /Title knownoget { (Title: ) print = flush } if
+ dup /Author knownoget { (Author: ) print = flush } if
+ dup /Subject knownoget { (Subject: ) print = flush } if
+ dup /Keywords knownoget { (Keywords: ) print = flush } if
+ dup /Creator knownoget { (Creator: ) print = flush } if
+ dup /Producer knownoget { (Producer: ) print = flush } if
+ dup /CreationDate knownoget { (CreationDate: ) print = flush } if
+ dup /ModDate knownoget { (ModDate: ) print = flush } if
+ dup /Trapped knownoget { (Trapped: ) print = flush } if
+} if % if Info known
+
+systemdict /DumpMediaSizes known
+{
+() =
+% Print out the Page Size info for each page.
+ 1 1 PDFPageCount {
+ dup (Page ) print =print
+ pdfgetpage dup
+ /MediaBox pget {
+ aload pop exch 4 1 roll exch sub 3 1 roll sub
+ ( MediaBox: [ ) print =print ( ) print =print ( ]) print
+ } if
+ /CropBox pget {
+ aload pop exch 4 1 roll exch sub 3 1 roll sub
+ ( CropBox: [ ) print =print ( ) print =print ( ]) print
+ } if
+ () = flush
+ } for
+} if
+
+
+
+/getPDFfonts { % (filename) getPDFfonts array_of_font_names
+ /FontsUsed 1000 dict def % this will increase if needed
+ mark
+ 1 1 PDFPageCount {
+ pdfgetpage % get pagedict
+ /Resources pget {
+ /Font knownoget {
+ { exch pop oforce
+ dup
+ /FontDescriptor knownoget
+ {
+ dup /FontFile known 1 index /FontFile2 known or exch /FontFile3 known or
+ /ShowEmbeddedFonts where { pop pop false} if {
+ pop % skip embedded fonts
+ } {
+ /BaseFont knownoget pop % not embedded
+ } ifelse
+ } {
+ /BaseFont knownoget pop % no FontDescriptor, not embedded
+ } ifelse
+ counttomark 0 gt { FontsUsed exch null put } if % stick it in the dict
+ } forall % traverse the dictionary
+ } if
+ } if
+ } for
+ % Now dump the FontsUsed dict into an array so we can sort it.
+ [ FontsUsed { pop } forall ]
+ { 100 string cvs exch 100 string cvs exch lt } .sort
+} bind def
+
+systemdict /DumpFontsUsed known
+{
+ (\nFonts Used:) =
+ getPDFfonts { = } forall
+} if
+
+() =
+
+quit
More information about the gs-cvs
mailing list