星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. % Copyright (C) 1994, 1995, 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This software is provided AS-IS with no warranty, either express or
  4. % implied.
  5. %
  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.
  9. %
  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.
  15. % $Id: pdf2dsc.ps 8546 2008-02-25 05:48:45Z alexcher $
  16. % pdf2dsc.ps
  17. % read pdf file and produce DSC "index" file.
  18. %
  19. % Input file is named PDFname
  20. % Output file is named DSCname
  21. %
  22. % Run using:
  23. % gs -dNODISPLAY -sPDFname=pdffilename -sDSCname=tempfilename pdf2dsc.ps
  24. % Then display the PDF file with
  25. % gs tempfilename
  26. %
  27. % Modified by Jason McCarty, bug 688071
  28. % Add PageLabels support.
  29. % Modified by Geoff Keating <geoffk@ozemail.com.au> 21/12/98:
  30. % Add DocumentMedia, PageMedia comments
  31. % Use inherited BoundingBox and Orientation
  32. % Reformat, add new macro 'puts', generally clean up
  33. % Modified by Johannes Plass <plass@dipmza.physik.uni-mainz.de> 1996-11-05:
  34. % Adds BoundingBox and Orientation if available.
  35. % Modified by rjl/lpd 9/19/96
  36. % Updates for compatibility with modified pdf_*.ps code for handling
  37. % page ranges (i.e., partial files) better.
  38. % Modified by Geoff Keating <Geoff.Keating@anu.edu.au> 7/3/96:
  39. % include Title and CreationDate DSC comments (these are displayed by
  40. % Ghostview);
  41. % reduce the size of typical output files by a factor of about 3.
  42. % Modified by L. Peter Deutsch 3/18/96:
  43. % Removes unnecessary and error-prone code duplicated from pdf_main.ps
  44. % Modified by L. Peter Deutsch for GS 3.33
  45. % 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
  49. /puts { DSCfile exch writestring } bind def
  50. /DSCstring 255 string def
  51. /MediaTypes 10 dict def
  52. GS_PDF_ProcSet begin
  53. pdfdict begin
  54. PDFfile
  55. pdfopen begin
  56. /FirstPage where { pop } { /FirstPage 1 def } ifelse
  57. /LastPage where { pop } { /LastPage pdfpagecount def } ifelse
  58. % scan through for media sizes, keep them in the dictionary
  59. FirstPage 1 LastPage {
  60. pdfgetpage /MediaBox pget pop % MediaBox is a required attribute
  61. aload pop
  62. 3 -1 roll sub 3 1 roll exch sub exch
  63. 2 array astore
  64. aload 3 1 roll 10 string cvs exch 10 string cvs
  65. (x) 3 -1 roll concatstrings concatstrings cvn
  66. MediaTypes 3 1 roll exch put
  67. } for
  68. % write header and prolog
  69. (%!PS-Adobe-3.0\n) puts
  70. Trailer /Info knownoget
  71. {
  72. dup /Title knownoget
  73. {
  74. (%%Title: ) puts
  75. DSCfile exch write==
  76. }
  77. if
  78. /CreationDate knownoget
  79. {
  80. (%%CreationDate: ) puts
  81. DSCfile exch write==
  82. }
  83. if
  84. }
  85. if
  86. % This is really supposed to be sorted by frequency of usage...
  87. (%%DocumentMedia: )
  88. MediaTypes {
  89. exch pop
  90. 1 index puts
  91. (y) puts dup 1 get DSCstring cvs puts
  92. (x) puts dup 0 get DSCstring cvs puts
  93. ( ) puts dup 0 get DSCstring cvs puts
  94. ( ) puts 1 get DSCstring cvs puts
  95. ( 70 white ()\n) puts
  96. pop (%%+ )
  97. } forall
  98. pop
  99. (%%Pages: ) puts
  100. LastPage FirstPage sub 1 add DSCstring cvs puts
  101. (\n%%EndComments\n) puts
  102. (%%BeginProlog\n) puts
  103. (/Page null def\n/Page# 0 def\n/PDFSave null def\n) puts
  104. (/DSCPageCount 0 def\n) puts
  105. (/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n) puts
  106. (GS_PDF_ProcSet begin\npdfdict begin\n) puts
  107. (%%EndProlog\n) puts
  108. (%%BeginSetup\n) puts
  109. DSCfile PDFname write==only
  110. ( \(r\) file { DELAYSAFER { .setsafe } if } stopped pop\n) puts
  111. ( pdfopen begin\n) puts
  112. ( copy_trailer_attrs\n) puts
  113. (%%EndSetup\n) puts
  114. /.hasPageLabels false def % see "Page Labels" in the PDF Reference
  115. Trailer /Root knownoget {
  116. /PageLabels knownoget {
  117. /PageLabels exch def
  118. /.pageCounter 1 def
  119. /.pageCounterType /D def
  120. /.pagePrefix () def
  121. % (TEXT) .ToLower (text) -- convert text to lowercase -- only letters!
  122. /.ToLower {
  123. dup length 1 sub -1 0 {
  124. 1 index exch 2 copy get 2#00100000 or put
  125. } for
  126. } def
  127. % int .CvAlpha (int in alphabetic base 26) -- convert a positive
  128. % integer to base 26 in capital letters, with 1=A; i.e. A..Z, AA..AZ, ...
  129. /.CvAlpha { % using cvrs seems futile since this isn't zero-based ...
  130. [ exch % construct an array of ASCII values, in reverse
  131. { % the remainder stays on the top of stack
  132. dup 0 eq { pop exit } if % quit if the value is zero
  133. dup 26 mod dup 0 eq { 26 add } if % so that the division is correct
  134. dup 64 add 3 1 roll sub 26 idiv % save the ASCII value and iterate
  135. } loop ]
  136. dup length dup string 3 1 roll
  137. dup -1 1 { % put the letters in a string
  138. 4 copy sub exch 4 -1 roll 1 sub get put
  139. } for pop pop
  140. } def
  141. % int .CvRoman (int in capital Roman numerals)
  142. % convert a positive integer to capital Roman numerals
  143. % return a decimal string if >= 4000
  144. /.CvRoman {
  145. dup DSCstring cvs % start with the decimal representation
  146. exch 4000 lt { % convert only if Roman numerals can represent this
  147. dup length
  148. [ [ () (I) (II) (III) (IV) (V) (VI) (VII) (VIII) (IX) ]
  149. [ () (X) (XX) (XXX) (XL) (L) (LX) (LXX) (LXXX) (XC) ]
  150. [ () (C) (CC) (CCC) (CD) (D) (DC) (DCC) (DCCC) (CM) ]
  151. [ () (M) (MM) (MMM) ] ] % Roman equivalents
  152. () % append the Roman equivalent of each decimal digit to this string
  153. 2 index -1 1 {
  154. 2 index 1 index 1 sub get
  155. 5 index 5 index 4 -1 roll sub get
  156. 48 sub get concatstrings
  157. } for
  158. 4 1 roll pop pop pop
  159. } if
  160. } def
  161. /PageToString <<
  162. /D { DSCstring cvs }
  163. /R { .CvRoman }
  164. /r { .CvRoman .ToLower }
  165. /A { .CvAlpha }
  166. /a { .CvAlpha .ToLower }
  167. >> def
  168. /.hasPageLabels true def
  169. } if
  170. } if
  171. % process each page
  172. FirstPage 1 LastPage {
  173. (%%Page: ) puts
  174. .hasPageLabels {
  175. dup 1 sub PageLabels exch numoget dup null ne {
  176. % page labels changed at this page, reset the values
  177. dup /S known { dup /S get } { null } ifelse
  178. /.pageCounterType exch def
  179. dup /P known { dup /P get } { () } ifelse
  180. /.pagePrefix exch def
  181. dup /St known { /St get } { pop 1 } ifelse
  182. /.pageCounter exch def
  183. } { pop } ifelse
  184. % output the page label
  185. (\() .pagePrefix
  186. .pageCounterType //null ne dup {
  187. PageToString .pageCounterType known and
  188. } if { % format the page number
  189. .pageCounter dup 0 gt { % don't try to format nonpositive numbers
  190. PageToString .pageCounterType get exec
  191. } {
  192. DSCstring cvs
  193. } ifelse
  194. } { () } ifelse
  195. (\)) concatstrings concatstrings concatstrings puts
  196. /.pageCounter .pageCounter 1 add def
  197. } {
  198. dup DSCstring cvs puts
  199. } ifelse
  200. ( ) puts
  201. dup DSCstring cvs puts
  202. (\n) puts
  203. dup pdfgetpage
  204. dup /MediaBox pget pop
  205. (%%PageMedia: y) puts
  206. aload pop 3 -1 roll sub DSCstring cvs puts
  207. (x) puts exch sub DSCstring cvs puts
  208. (\n) puts
  209. dup /CropBox pget {
  210. (%%PageBoundingBox: ) puts
  211. {DSCfile exch write=only ( ) puts} forall
  212. (\n) puts
  213. } if
  214. /Rotate pget {
  215. (%%PageOrientation: ) puts
  216. 90 div cvi 4 mod dup 0 lt {4 add} if
  217. [(Portrait) (Landscape) (UpsideDown) (Seascape)] exch get puts
  218. (\n) puts
  219. } if
  220. DSCfile exch DSCstring cvs writestring
  221. ( DoPDFPage\n) puts
  222. } for
  223. currentdict pdfclose
  224. end
  225. end
  226. end
  227. % write trailer
  228. (%%Trailer\n) puts
  229. (currentdict pdfclose\nend\nend\nend\n) puts
  230. (%%EOF\n) puts
  231. % close output file and exit
  232. DSCfile closefile
  233. quit
  234. % end of pdf2dsc.ps