summaryrefslogtreecommitdiff
path: root/gs/lib/pdf2dsc.ps
blob: 3028cd23c6360b1c30bc006e4c996595cf5914f6 (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
118
119
120
121
%    Copyright (C) 1994, 1995, 1996, 1997 Aladdin Enterprises.  All rights reserved.
% 
% This file is part of Aladdin Ghostscript.
% 
% Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
% or distributor accepts any responsibility for the consequences of using it,
% or for whether it serves any particular purpose or works at all, unless he
% or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
% License (the "License") for full details.
% 
% Every copy of Aladdin Ghostscript must include a copy of the License,
% normally in a plain ASCII text file named PUBLIC.  The License grants you
% the right to copy, modify and redistribute Aladdin Ghostscript, but only
% under certain conditions described in the License.  Among other things, the
% License requires that the copyright notice and this notice be preserved on
% all copies.

% $Id$
% pdf2dsc.ps
% read pdf file and produce DSC "index" file.
%
% Input  file is named PDFname
% Output file is named DSCname
%
% Run using:
%  gs -dNODISPLAY -sPDFname=pdffilename -sDSCname=tempfilename pdf2dsc.ps
% Then display the PDF file with
%  gs tempfilename
%
% Modified by Johannes Plass <plass@dipmza.physik.uni-mainz.de> 1996-11-05:
%	Adds BoundingBox and Orientation if available.
% Modified by rjl/lpd 9/19/96
%	Updates for compatibility with modified pdf_*.ps code for handling
%	  page ranges (i.e., partial files) better.
% Modified by Geoff Keating <Geoff.Keating@anu.edu.au> 7/3/96:
%	include Title and CreationDate DSC comments (these are displayed by
%	  Ghostview);
%	reduce the size of typical output files by a factor of about 3.
% Modified by L. Peter Deutsch 3/18/96:
%	Removes unnecessary and error-prone code duplicated from pdf_main.ps
% Modified by L. Peter Deutsch for GS 3.33
% Originally by Russell Lang  1995-04-26

/DSCfile DSCname (w) file def
/DSCstring 255 string def
   GS_PDF_ProcSet begin
   pdfdict begin
   PDFname (r) file
   pdfopen begin
% setup for loop  (init increment limit)
   /FirstPage where { pop FirstPage } { 1 } ifelse
   1
   /LastPage where { pop LastPage } { pdfpagecount } ifelse
% write header and prolog
DSCfile (%!PS-Adobe-3.0\n) writestring
Trailer /Info knownoget
 {
   dup /Title knownoget
    {
      DSCfile (%%Title: ) writestring
      DSCfile exch write==
    }
   if
   /CreationDate knownoget
    {
      DSCfile (%%CreationDate: ) writestring
      DSCfile exch write==
    }
   if
 }
if
DSCfile (%%Pages: ) writestring
DSCfile 1 index 3 index sub 1 add DSCstring cvs writestring
DSCfile (\n%%EndComments\n) writestring
DSCfile (%%BeginProlog\n) writestring
DSCfile (/Page null def\n/Page# 0 def\n/PDFSave null def\n/DSCPageCount 0 def\n) writestring
DSCfile (/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n) writestring
DSCfile (GS_PDF_ProcSet begin\npdfdict begin\n) writestring
DSCfile (%%EndProlog\n) writestring
DSCfile (%%BeginSetup\n) writestring
DSCfile PDFname write==only
DSCfile ( \(r\) file pdfopen begin\n) writestring
DSCfile (%%EndSetup\n) writestring
% process each page
    {
DSCfile (%%Page: ) writestring
DSCfile 1 index DSCstring cvs writestring
DSCfile ( ) writestring
DSCfile 1 index DSCstring cvs writestring
DSCfile (\n) writestring

%BEGIN ##jp##
dup pdfgetpage /CropBox knownoget { % file maxpage pageno cropbox
  DSCfile (%%PageBoundingBox: ) writestring
  {DSCfile exch write=only DSCfile ( ) writestring} forall
  DSCfile (\n) writestring
} if
dup pdfgetpage /Rotate knownoget { % file maxpage pageno angle
  DSCfile (%%PageOrientation: ) writestring
  90 div cvi 4 mod dup 0 lt {4 add} if
  [(Portrait) (Landscape) (UpsideDown) (Seascape)] exch get
  DSCfile exch writestring
  DSCfile (\n) writestring
} if
%END ##jp##

DSCfile exch DSCstring cvs writestring
DSCfile ( DoPDFPage\n) writestring
    } for
   currentdict pdfclose
   end
   end
   end
% write trailer
DSCfile (%%Trailer\n) writestring
DSCfile (currentdict pdfclose\nend\nend\nend\n) writestring
DSCfile (%%EOF\n) writestring
% close output file and exit
DSCfile closefile
quit
% end of pdf2dsc.ps