home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 February / INTERNET88.ISO / pc / software / windows / bits / pdf995 / data1.cab / Program_Executable_Files / res / pdf2dsc.ps < prev    next >
Encoding:
Text File  |  2001-12-08  |  5.3 KB  |  168 lines

  1. %    Copyright (C) 1994, 1995, 1996, 1997, 1998 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of GNU Ghostscript.
  3. % GNU Ghostscript is distributed in the hope that it will be useful, but
  4. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  5. % to anyone for the consequences of using it or for whether it serves any
  6. % particular purpose or works at all, unless he says so in writing.  Refer
  7. % to the GNU General Public License for full details.
  8. % Everyone is granted permission to copy, modify and redistribute GNU
  9. % Ghostscript, but only under the conditions described in the GNU General
  10. % Public License.  A copy of this license is supposed to have been given
  11. % to you along with GNU Ghostscript so you can know your rights and
  12. % responsibilities.  It should be in a file named COPYING.  Among other
  13. % things, the copyright notice and this notice must be preserved on all
  14. % copies.
  15.  
  16. % $RCSfile: pdf2dsc.ps,v $ $Revision: 1.2.2.2 $
  17. % pdf2dsc.ps
  18. % read pdf file and produce DSC "index" file.
  19. %
  20. % Input  file is named PDFname
  21. % Output file is named DSCname
  22. %
  23. % Run using:
  24. %  gs -dNODISPLAY -sPDFname=pdffilename -sDSCname=tempfilename pdf2dsc.ps
  25. % Then display the PDF file with
  26. %  gs tempfilename
  27. %
  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
  39. %      Ghostview);
  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
  45.  
  46. /DSCfile DSCname (w) file def
  47. systemdict /.setsafe known { .setsafe } if
  48.  
  49. /puts { DSCfile exch writestring } bind def
  50. /DSCstring 255 string def
  51. /MediaTypes 10 dict def
  52.  
  53. % (str1) (str2)  concatstr  (str1str2)
  54. /concatstr {
  55.   2 copy length exch length add string
  56.   dup dup 5 2 roll copy length
  57. % stack: newstring newstring str2 str1-length
  58.   exch putinterval
  59. } bind def
  60.  
  61.    GS_PDF_ProcSet begin
  62.    pdfdict begin
  63.    PDFname (r) file
  64.    pdfopen begin
  65.    /FirstPage where { pop } { /FirstPage 1 def } ifelse
  66.    /LastPage where { pop } { /LastPage pdfpagecount def } ifelse
  67.  
  68. % scan through for media sizes, keep them in the dictionary
  69.    FirstPage 1 LastPage {
  70.       pdfgetpage /MediaBox pget pop   % MediaBox is a required attribute
  71.       aload pop 
  72.       3 -1 roll sub 3 1 roll exch sub exch
  73.       2 array astore 
  74.       aload 3 1 roll 10 string cvs exch 10 string cvs
  75.       (x) exch concatstr concatstr cvn
  76.       MediaTypes 3 1 roll exch put
  77.    } for
  78.  
  79. % write header and prolog
  80.    (%!PS-Adobe-3.0\n) puts
  81.    Trailer /Info knownoget
  82.     {
  83.       dup /Title knownoget
  84.        {
  85.          (%%Title: ) puts
  86.          DSCfile exch write==
  87.        }
  88.       if
  89.       /CreationDate knownoget
  90.        {
  91.          (%%CreationDate: ) puts
  92.          DSCfile exch write==
  93.        }
  94.       if
  95.     }
  96.    if
  97.    % This is really supposed to be sorted by frequency of usage...
  98.    (%%DocumentMedia: )
  99.    MediaTypes { 
  100.       exch pop
  101.       1 index puts
  102.       (y) puts dup 1 get DSCstring cvs puts
  103.       (x) puts dup 0 get DSCstring cvs puts 
  104.       ( ) puts dup 0 get DSCstring cvs puts
  105.       ( ) puts 1 get DSCstring cvs puts 
  106.       ( 70 white ()\n) puts
  107.       pop (%%+ )
  108.    } forall
  109.    pop
  110.  
  111.    (%%Pages: ) puts
  112.    LastPage FirstPage sub 1 add DSCstring cvs puts
  113.    (\n%%EndComments\n) puts
  114.    (%%BeginProlog\n) puts
  115.    (/Page null def\n/Page# 0 def\n/PDFSave null def\n) puts
  116.    (/DSCPageCount 0 def\n) puts
  117.    (/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n) puts
  118.    (GS_PDF_ProcSet begin\npdfdict begin\n) puts
  119.    (%%EndProlog\n) puts
  120.    (%%BeginSetup\n) puts
  121.    DSCfile PDFname write==only
  122.    ( \(r\) file pdfopen begin\n) puts
  123.    (%%EndSetup\n) puts
  124.    % process each page
  125.    FirstPage 1 LastPage {
  126.        (%%Page: ) puts
  127.        dup DSCstring cvs puts
  128.        ( ) puts
  129.        dup DSCstring cvs puts
  130.        (\n) puts
  131.  
  132.        dup pdfgetpage
  133.        dup /MediaBox pget pop
  134.          (%%PageMedia: y) puts
  135.      aload pop 3 -1 roll sub DSCstring cvs puts
  136.      (x) puts exch sub DSCstring cvs puts
  137.      (\n) puts
  138.        dup /CropBox pget {
  139.          (%%PageBoundingBox: ) puts
  140.          {DSCfile exch write=only ( ) puts} forall
  141.          (\n) puts
  142.        } if
  143.        /Rotate pget {
  144.          (%%PageOrientation: ) puts
  145.          90 div cvi 4 mod dup 0 lt {4 add} if
  146.          [(Portrait) (Landscape) (UpsideDown) (Seascape)] exch get puts
  147.          (\n) puts
  148.        } if
  149.  
  150.        DSCfile exch DSCstring cvs writestring
  151.        ( DoPDFPage\n) puts
  152.     } for
  153.    currentdict pdfclose
  154.    end
  155.    end
  156.    end
  157. % write trailer
  158. (%%Trailer\n) puts
  159. (currentdict pdfclose\nend\nend\nend\n) puts
  160. (%%EOF\n) puts
  161. % close output file and exit
  162. DSCfile closefile
  163. quit
  164. % end of pdf2dsc.ps
  165.