home *** CD-ROM | disk | FTP | other *** search
/ jppd.dyndns.org / jppd.dyndns.org.tar / jppd.dyndns.org / QUERYPRO / Impressora_PDF / converter.exe / GPLGS / pdf2dsc.ps < prev    next >
Text File  |  2002-03-31  |  5KB  |  167 lines

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