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();  
       
      }
  • 相关阅读:
    Python排序算法(一)——快速排序
    jupyter运行py文件(py文件和ipynb文件互转)
    Jupyter notebook工具栏隐藏和jupyter notebook主题更改
    Python中print和return的区别
    500 : Internal Server Error(jupyter)
    PEP8 python规范神器
    Python分析微信好友性别比例和省份城市分布比例
    xpath 的使用
    scrapy实验1 爬取中国人寿官网新闻,保存为xml
    数据可视化matplotlib、seaborn、pydotplus
  • 原文地址:https://www.cnblogs.com/xianyin05/p/1447314.html
Copyright © 2011-2022 走看看