home *** CD-ROM | disk | FTP | other *** search
/ swCHIP 1991 January / swCHIP_95-1.bin / utility / gsview13 / src / pdf2dsc.ps < prev    next >
Text File  |  1995-12-09  |  2KB  |  70 lines

  1. %!
  2. % pdf2dsc.ps
  3. % read pdf file and produce DSC "index" file.
  4. % by Russell Lang  1995-05-15
  5. %
  6. % modified from runpdf in gs 3.33 pdf_main.ps by Aladdin Enterprises.
  7. %
  8. % Input  file is named PDFname
  9. % Output file is named DSCname
  10. %
  11. % Run using:
  12. %  gs -dNODISPLAY -sPDFname=pdffilename -sDSCname=tempfilename pdf2dsc.ps
  13. % Then display the PDF file with
  14. %  gs tempfilename
  15.  
  16. /DSCfile DSCname (w) file def
  17. /DSCstring 255 string def
  18. % put these in userdict so we can write to them later
  19.    /Page# null def
  20.    /Page null def
  21.    /PDFSave null def
  22. %
  23.    GS_PDF_ProcSet begin
  24.    pdfdict begin
  25.    PDFname (r) file
  26.    pdfopen begin
  27. % setup for loop  (init increment limit)
  28.    /FirstPage where { pop FirstPage } { 1 } ifelse
  29.    1
  30.    /LastPage where { pop LastPage } { pdfpagecount } ifelse
  31. % write header and prolog
  32. DSCfile (%!PS-Adobe-3.0\n) writestring
  33. DSCfile (%%Pages: ) writestring
  34. DSCfile 1 index 3 index sub 1 add DSCstring cvs writestring
  35. DSCfile (\n%%EndComments\n) writestring
  36. DSCfile (%%BeginProlog\n) writestring
  37. DSCfile (/Page null def\n/PDFSave null def\n) writestring
  38. DSCfile (GS_PDF_ProcSet begin\npdfdict begin\n) writestring
  39. DSCfile (%%EndProlog\n) writestring
  40. DSCfile (%%BeginSetup\n) writestring
  41. DSCfile PDFname write==only
  42. DSCfile ( \(r\) file pdfopen begin\n) writestring
  43. DSCfile (%%EndSetup\n) writestring
  44. % process each page
  45.     { dup /Page# exch store
  46. DSCfile (%%Page: ) writestring
  47. DSCfile 1 index DSCstring cvs writestring
  48. DSCfile ( ) writestring
  49. DSCfile 1 index DSCstring cvs writestring
  50. DSCfile (\n) writestring
  51. DSCfile exch DSCstring cvs writestring
  52. DSCfile ( pdfgetpage /Page exch store\n) writestring
  53. DSCfile (save /PDFSave exch store\n) writestring
  54. DSCfile (Page pdfshowpage\n) writestring
  55. DSCfile (PDFSave restore\n) writestring
  56.     } for
  57.    currentdict pdfclose
  58.    end
  59.    end
  60.    end
  61. % write trailer
  62. DSCfile (%%Trailer\n) writestring
  63. DSCfile (currentdict pdfclose\nend\nend\nend\n) writestring
  64. DSCfile (%%EOF\n) writestring
  65. % close output file and exit
  66. DSCfile closefile
  67. quit
  68. % end of pdf2dsc.ps
  69.  
  70.