zoukankan      html  css  js  c++  java
  • 用C#打开一个pdf文件

    http://www.o2sol.com/public/webui/samples.shtml  
      下载XpdfRasterizer.dll,XpdfRasterizerNet.dll,引用即可用  
      如  
      using   XpdfRasterizerNet;  
       
      protected   System.Web.UI.WebControls.Button   Button1;  
      protected   System.Web.UI.HtmlControls.HtmlInputFile   File1;  
      protected   System.Web.UI.WebControls.Label   Label1;  
      protected   System.Web.UI.WebControls.PlaceHolder   PlaceHolder1;  
      private   void   Page_Load(object   sender,   System.EventArgs   e)  
      {  
      this.Label1.Text="";  
      }  
       
      #region   Web   Form   Designer   generated   code  
      override   protected   void   OnInit(EventArgs   e)  
      {  
      //  
      //   CODEGEN:   This   call   is   required   by   the   ASP.NET   Web   Form   Designer.  
      //  
      InitializeComponent();  
      base.OnInit(e);  
      }  
       
      ///   <summary>  
      ///   Required   method   for   Designer   support   -   do   not   modify  
      ///   the   contents   of   this   method   with   the   code   editor.  
      ///   </summary>  
      private   void   InitializeComponent()  
      {          
      this.Button1.Click   +=   new   System.EventHandler(this.Button1_Click);  
      this.Load   +=   new   System.EventHandler(this.Page_Load);  
       
      }  
      #endregion  
       
      private   string   GetFilePath()  
      {  
      //4/19/2005   5:44:28   PM  
      string   time=System.DateTime.Now.ToString();  
      time=time.Replace("/","");  
      time=time.Replace("   ","");  
      time=time.Replace(":","");  
      //time+=".pdf";  
      string   path=Server.MapPath("PDF2JPG.aspx");  
      path=path.Replace("PDF2JPG.aspx",@"Files\"+time);  
      return   path;  
      }  
      private   void   Button1_Click(object   sender,   System.EventArgs   e)  
      {  
      //upload  
      int   len=File1.PostedFile.FileName.Length;  
      string   filetype=File1.PostedFile.FileName.Substring(len-3,3);  
      if(filetype.ToLower()!="pdf")  
      {  
      this.Label1.Text="Please   select   pdf   file";  
      return   ;  
      }  
      else  
      this.Label1.Text="";  
      string   fileName=GetFilePath();  
      string   pdffile=fileName+".pdf";  
      if   (File1.PostedFile   !=   null)    
      {  
      try    
      {  
      File1.PostedFile.SaveAs(pdffile);  
      }  
      catch  
      {  
      Response.Write("Upload   fail...");  
      }  
      }  
      //convert   to   jpg  
       
      double   dpi=120;  
      XpdfRasterizerNet.XpdfRasterizerClass       rast=new   XpdfRasterizerNet.XpdfRasterizerClass();  
      rast.loadFile(pdffile);  
      for(int   page=1;page<=rast.numPages   ;page++)  
      {  
      string   jpgfile=fileName+page.ToString()+".bmp";  
      try  
      {  
      rast.writePageBitmap(page,dpi,rast.imageRGB,rast.imageFileBMP,jpgfile);  
      System.Web.UI.WebControls.Image     image=new   System.Web.UI.WebControls.Image();  
      image.ImageUrl=jpgfile;  
      this.PlaceHolder1.Controls.Add(image);  
      }  
      catch  
      {  
      Response.Write("Convert   fail...:");  
      }  
      }  
      rast.closeFile();  
       
      }
  • 相关阅读:
    Leetcode 811. Subdomain Visit Count
    Leetcode 70. Climbing Stairs
    Leetcode 509. Fibonacci Number
    Leetcode 771. Jewels and Stones
    Leetcode 217. Contains Duplicate
    MYSQL安装第三步报错
    .net 开发WEB程序
    JDK版本问题
    打开ECLIPSE 报failed to load the jni shared library
    ANSI_NULLS SQL语句
  • 原文地址:https://www.cnblogs.com/xianyin05/p/1447314.html
Copyright © 2011-2022 走看看