abcpdf.dll html 轉pdf(二)

接上一篇

   根據虛擬路徑生成PDF

  1. public void CreatePDF(string name,string virtualPath)  
  2.  {  
  3.      Doc theDoc = new Doc();  
  4.      theDoc.TopDown = true;  
  5.      theDoc.Rect.String = "22 15 820 580";//控制顯示的大小205 300 632 895  
  6.      theDoc.MediaBox.String = "0 0 842 595";//控制頁面的大小  
  7.      string path = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + VirtualPathUtility.ToAbsolute(virtualPath);  
  8.      int theID = theDoc.AddImageUrl(path);  
  9.      while (true)  
  10.      {  
  11.          if (!theDoc.Chainable(theID))  
  12.              break;  
  13.          theDoctheDoc.Page = theDoc.AddPage();  
  14.          theID = theDoc.AddImageToChain(theID);  
  15.      }  
  16.      byte[] theData = theDoc.GetData();  
  17.      FileCreate(name, theData);  
  18.      if (File.Exists(HttpContext.Current.Server.MapPath(name + ".pdf")))  
  19.      {  
  20.          HttpContext.Current.Response.Write(string.Format("<a target='_blank' href='{0}'>下載</a>", name + ".pdf"));  
  21.      }  
  22.  } 

調用方法: 

CreatePDF("software", "~/硬件試產發佈單/HPTrialRelease.aspx");

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章