⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdf_main.ps

📁 GhostScript的源代码
💻 PS
📖 第 1 页 / 共 2 页
字号:

% Close a PDF file.
/pdfclose		% <dict> pdfclose -
 { begin
   PDFfile closefile
   end
 } bind def

% ======================== Page accessing ======================== %

% Get a (possibly inherited) attribute of a page.
/pget			% <pagedict> <key> pget <value> -true-
			% <pagedict> <key> pget -false-
 { 2 copy knownoget
    { exch pop exch pop true
    }
    { exch /Parent knownoget
       { exch pget }
       { pop false }
      ifelse
    }
   ifelse
 } bind def

% Get the value of a resource on a given page.
/rget {			% <resname> <pagedict> <restype> rget <value> -true-
			% <resname> <pagedict> <restype> rget -false-
  LocalResources 1 index knownoget {
     3 index knownoget
  } {
    false
  } ifelse {
    exch pop exch pop exch pop true
  } {
    exch /Resources pget {
      exch knownoget { exch knownoget } { pop false } ifelse
    } {
      pop pop false
    } ifelse
  } ifelse
} bind def

% Get the total number of pages in the document.
/pdfpagecount		% - pdfpagecount <int>
 { Trailer /Root oget /Pages oget /Count oget
 } bind def

% Find the N'th page of the document by iterating through the Pages tree.
% The first page is numbered 1.
/pdffindpage		% <int> pdffindpage <pagedict>
 { dup Trailer /Root oget /Pages oget
    {		% We should be able to tell when we reach a leaf
		% by finding a Type unequal to /Pages.  Unfortunately,
		% some files distributed by Adobe lack the Type key
		% in some of the Pages nodes!  Instead, we check for Kids.
      dup /Kids knownoget not { exit } if
      exch pop null
      0 1 3 index length 1 sub
       { 2 index exch oget
	 dup /Kids known { dup /Count oget } { 1 } ifelse
		% Stack: index kids null node count
	 dup 5 index ge { pop exch pop exit } if
	 5 -1 roll exch sub 4 1 roll pop
       }
      for exch pop
      dup null eq { pop pop 1 null exit } if
    }
   loop
		% Stack: index countleft node
   1 index 1 ne { pop pop /pdffindpage cvx /rangecheck signalerror } if
   exch pop
   PageIndex 2 index 1 sub 2 index put
   PageNumbers 1 index 3 index put
   exch pop
 } bind def

% Find the N'th page of the document.
% The first page is numbered 1.
/pdfgetpage		% <int> pdfgetpage <pagedict>
 { PageIndex 1 index 1 sub get dup null ne
    { exch pop }
    { pop pdffindpage }
   ifelse
 } bind def

% Find the page number of a page object (inverse of pdfgetpage).
/pdfpagenumber		% <pagedict> pdfpagenumber <int>
 {	% We use the simplest and stupidest of all possible algorithms....
   PageNumbers 1 index .knownget
    { exch pop
    }
    { 1 1 PageCount 1 add	% will give a rangecheck if not found
       { dup pdfgetpage oforce 2 index eq { exit } if pop
       }
      for exch pop
    }
   ifelse
 } bind def

% Display a given page.
/boxrect		% [<llx> <lly> <urx> <ury>] boxrect <x> <y> <w> <h>
 { aload pop exch 3 index sub exch 2 index sub
 } bind def
/resolvedest {		% <name|string|other> resolvedest <other|null>
  dup type /nametype eq {
    Trailer /Root oget /Dests oget exch knownoget not { null } if
  } {
    dup type /stringtype eq {
      Trailer /Root oget /Names oget /Dests knownoget {
	exch nameoget
      } {
	pop null
      } ifelse
    } if
  } ifelse
} bind def
/linkdest {		% <link|outline> linkdest
			%   ([/Page <n>] /View <view> | ) <link|outline>
  dup /Dest knownoget
    { resolvedest
      dup type /dicttype eq { /D get } if
      dup null eq
       { pop }
       { dup 0 oget
	 dup null eq
	  { pop }
	  { dup type /integertype ne { pdfpagenumber } if
	    /Page exch 4 -2 roll
	  }
	 ifelse
	 dup length 1 sub 1 exch getinterval /View exch 3 -1 roll
       }
      ifelse
    }
   if
} bind def
% <pagedict> mark ... -proc- -
/namedactions 8 dict dup begin
  /FirstPage {
    /Page 1 3 -1 roll
  } def
  /LastPage {
    counttomark 2 add index pdfpagecount /Page exch 3 -1 roll
  } def
  /NextPage {
    counttomark 2 add index pdfpagenumber 1 add /Page exch 3 -1 roll
  } def
  /PrevPage {
    counttomark 2 add index pdfpagenumber 1 sub /Page exch 3 -1 roll
  } def
end readonly def
% <pagedict> <annotdict> -proc- -
/annottypes 5 dict dup begin
  /Text {
    mark exch
     { /Rect /Open /Contents }
     { 2 copy knownoget { 3 -1 roll } { pop } ifelse }
    forall pop /ANN pdfmark
  } bind def
  /Link {
    mark exch
     { /Rect /Border }
     { 2 copy knownoget { 3 -1 roll } { pop } ifelse }
    forall dup /A knownoget {
      dup /D knownoget {
	exch pop exch dup length dict copy dup /Dest 4 -1 roll put
      } {
	/N knownoget {		% Assume /S /Named
	  namedactions exch .knownget { exec } if
	} if
      } ifelse
    } if
    linkdest pop /LNK pdfmark
  } bind def
end readonly def

/pdfshowpage		% <pagedict> pdfshowpage -
 { dup /Page exch store
   pdfshowpage_init 
   pdfshowpage_setpage 
   save /PDFSave exch store
   (before exec) VMDEBUG
     pdfshowpage_finish
   (after exec) VMDEBUG
   PDFSave restore
 } bind def

/pdfpagecontents	% <pagedict> pdfpagecontents <contents>
 { } bind def

/pdfshowpage_init 	% <pagedict> pdfshowpage_init <pagedict>
 { gsave
   /DSCPageCount DSCPageCount 1 add store
 } bind def

/pdfshowpage_setpage	% <pagedict> pdfshowpage_setpage <pagedict>
 { 
   3 dict	% for setpagedevice
	% Stack: pagedict setpagedict
	% We want to look at Rotate for displays, but not for printers.
	% The following is a hack, but we don't know a better way to do this.
   currentpagedevice /OutputFile known
    { dup /Orientation 3 index /Rotate pget not { 0 } if 90 idiv
	% Rotate specifies *clockwise* rotation!
      neg 3 and put
    }
   if
	% Stack: pagedict setpagedict
   1 index /MediaBox pget
    {			% Set the page size.
      boxrect [ 2 index 5 index sub 2 index 5 index sub ]
	% Stack: pagedict setpagedict llx lly urx ury pagesize
      5 index exch /PageSize exch put
	% Stack: pagedict contents setpagedict llx lly urx ury
      pop pop
      neg exch neg exch
      [ 3 1 roll ]
	% Stack: pagedict setpagedict pageoffset
      1 index exch /PageOffset exch put
    }
   if
	% Stack: pagedict setpagedict
   setpagedevice
 } bind def

/pdfshowpage_finish	% <pagedict> pdfshowpage_finish -
 {
	% Copy crop box.
   dup /CropBox pget
    { boxrect rectclip
      dup /CropBox knownoget { mark /CropBox 3 -1 roll /PAGE pdfmark } if
    }
   if

	% Copy annotations and links.
   dup /Annots knownoget
    { 0 1 2 index length 1 sub
       { 1 index exch oget
         dup /Subtype oget annottypes exch .knownget { exec } { pop } ifelse
       }
      for pop
    }
   if

	% Display the actual page contents.
   2 dict begin
   /BXlevel 0 def
   matrix currentmatrix beginpage setmatrix
   /Contents knownoget not { 0 array } if
   dup type /arraytype ne { 1 array astore } if
    { oforce false resolvestream pdfopdict .pdfrun } forall
   endpage
   end			% scratch dict
   grestore
 } bind def

end			% pdfdict
.setglobal

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -