summaryrefslogtreecommitdiff
path: root/gs/toolbin/pdf_info.ps
blob: c35fbbd6b4459718cc3f7282f8bdc244cf7e3c2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
%!PS
% Copyright (C) 2007 Artifex Software, Inc.  All rights reserved.
% 
% This software is provided AS-IS with no warranty, either express or
% implied.
% 
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
% 
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA  94903, U.S.A., +1(415)492-9861.
%
% $Id: pdf_info.ps 6300 2005-12-28 19:56:24Z alexcher $

% 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 pdfpagecount def
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 /DescendantFonts knownoget {
            exch pop 0 get oforce
          } if
       	  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
{
  (\nFont or CIDFont resources used:) =
  getPDFfonts { = } forall
} if

() =

quit