Advertisement
Guest User

Untitled

a guest
May 27th, 2014
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1.         #region Initialize
  2.  
  3.         public override void Initialize()
  4.         {
  5.             // define our routine for preparing to show a page.  
  6.             // This writes out some tags which we capture in the
  7.             // callback to obtain the page size and orientation.
  8.             this.Execute(string.Format(@"
  9.                /GSNETViewer_PDFpage {{
  10.                     ({0}) print dup == flush
  11.                     pdfgetpage /Page exch store
  12.                    Page /MediaBox pget
  13.                    {{ ({1}) print == flush  }}
  14.                     if
  15.                    Page /CropBox pget
  16.                     {{ ({2}) print == flush }}
  17.                     if
  18.                    Page /Rotate pget not {{ 0 }} if
  19.                     ({3}) print == flush
  20.                }} def", PDF_PAGE_TAG, PDF_MEDIA_TAG, PDF_CROP_TAG, PDF_ROTATE_TAG));
  21.  
  22.             // put these in userdict so we can write to them later
  23.             this.Execute(@"
  24.                    /Page null def
  25.                    /Page# 0 def
  26.                    /PDFSave null def
  27.                    /DSCPageCount 0 def
  28.                ");
  29.  
  30.             // open PDF support dictionaries
  31.             this.Execute(@"
  32.                    GS_PDF_ProcSet begin
  33.                    pdfdict begin");
  34.         }
  35.  
  36.         #endregion
  37.  
  38.         #region Open
  39.  
  40.         public override void Open(string filePath)
  41.         {          
  42.             // open PDF file
  43.             this.Execute(string.Format("({0}) (r) file pdfopen begin", filePath.Replace("\\", "/")));
  44.  
  45.             this.Execute("/FirstPage where { pop FirstPage } { 1 } ifelse");
  46.             this.Execute("/LastPage where { pop LastPage } { pdfpagecount } ifelse");
  47.  
  48.             // flush stdout and then send PDF page marker to stdout where we capture the page numbers via callback
  49.             this.Execute(string.Format("flush ({0}) print exch =only ( ) print =only (\n) print flush", PDF_PAGES_TAG));
  50.         }
  51.  
  52.         #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement