1 % Copyright (C) 1994, 1995, 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: pdf2dsc.ps,v 1.7 2002/03/30 23:39:15 raph Exp $
18 % read pdf file and produce DSC "index" file.
20 % Input file is named PDFname
21 % Output file is named DSCname
24 % gs -dNODISPLAY -sPDFname=pdffilename -sDSCname=tempfilename pdf2dsc.ps
25 % Then display the PDF file with
28 % Modified by Geoff Keating <geoffk@ozemail.com.au> 21/12/98:
29 % Add DocumentMedia, PageMedia comments
30 % Use inherited BoundingBox and Orientation
31 % Reformat, add new macro 'puts', generally clean up
32 % Modified by Johannes Plass <plass@dipmza.physik.uni-mainz.de> 1996-11-05:
33 % Adds BoundingBox and Orientation if available.
34 % Modified by rjl/lpd 9/19/96
35 % Updates for compatibility with modified pdf_*.ps code for handling
36 % page ranges (i.e., partial files) better.
37 % Modified by Geoff Keating <Geoff.Keating@anu.edu.au> 7/3/96:
38 % include Title and CreationDate DSC comments (these are displayed by
40 % reduce the size of typical output files by a factor of about 3.
41 % Modified by L. Peter Deutsch 3/18/96:
42 % Removes unnecessary and error-prone code duplicated from pdf_main.ps
43 % Modified by L. Peter Deutsch for GS 3.33
44 % Originally by Russell Lang 1995-04-26
46 /PDFfile PDFname (r) file def
47 /DSCfile DSCname (w) file def
48 systemdict /.setsafe known { .setsafe } if
50 /puts { DSCfile exch writestring } bind def
51 /DSCstring 255 string def
52 /MediaTypes 10 dict def
54 % (str1) (str2) concatstr (str1str2)
56 2 copy length exch length add string
57 dup dup 5 2 roll copy length
58 % stack: newstring newstring str2 str1-length
66 /FirstPage where { pop } { /FirstPage 1 def } ifelse
67 /LastPage where { pop } { /LastPage pdfpagecount def } ifelse
69 % scan through for media sizes, keep them in the dictionary
70 FirstPage 1 LastPage {
71 pdfgetpage /MediaBox pget pop % MediaBox is a required attribute
73 3 -1 roll sub 3 1 roll exch sub exch
75 aload 3 1 roll 10 string cvs exch 10 string cvs
76 (x) exch concatstr concatstr cvn
77 MediaTypes 3 1 roll exch put
80 % write header and prolog
81 (%!PS-Adobe-3.0\n) puts
82 Trailer /Info knownoget
90 /CreationDate knownoget
92 (%%CreationDate: ) puts
98 % This is really supposed to be sorted by frequency of usage...
103 (y) puts dup 1 get DSCstring cvs puts
104 (x) puts dup 0 get DSCstring cvs puts
105 ( ) puts dup 0 get DSCstring cvs puts
106 ( ) puts 1 get DSCstring cvs puts
107 ( 70 white ()\n) puts
113 LastPage FirstPage sub 1 add DSCstring cvs puts
114 (\n%%EndComments\n) puts
115 (%%BeginProlog\n) puts
116 (/Page null def\n/Page# 0 def\n/PDFSave null def\n) puts
117 (/DSCPageCount 0 def\n) puts
118 (/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n) puts
119 (GS_PDF_ProcSet begin\npdfdict begin\n) puts
121 (%%BeginSetup\n) puts
122 DSCfile PDFname write==only
123 ( \(r\) file { DELAYSAFER { .setsafe } if } stopped pop\n) puts
124 ( pdfopen begin\n) puts
127 FirstPage 1 LastPage {
129 dup DSCstring cvs puts
131 dup DSCstring cvs puts
135 dup /MediaBox pget pop
136 (%%PageMedia: y) puts
137 aload pop 3 -1 roll sub DSCstring cvs puts
138 (x) puts exch sub DSCstring cvs puts
141 (%%PageBoundingBox: ) puts
142 {DSCfile exch write=only ( ) puts} forall
146 (%%PageOrientation: ) puts
147 90 div cvi 4 mod dup 0 lt {4 add} if
148 [(Portrait) (Landscape) (UpsideDown) (Seascape)] exch get puts
152 DSCfile exch DSCstring cvs writestring
161 (currentdict pdfclose\nend\nend\nend\n) puts
163 % close output file and exit