原創(chuàng)|其它|編輯:郝浩|2012-10-18 15:05:16.000|閱讀 1930 次
概述:大多數(shù)時候,都是使用WebBrowser空間,將網頁截圖,然后插入PDF文件,另外也可以將網頁先保存為Word文件,然后再從Word轉PDF。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
中轉方式:
大多數(shù)時候,都是使用WebBrowser空間,將網頁截圖,然后插入PDF文件,另外也可以將網頁先保存為Word文件,然后再從Word轉PDF。
PDF虛擬打印機:
還有一種方式,就是使用虛擬打印機,安裝一個PDF虛擬打印機,將它設置成默認打印機,比如PDF-XChange,將它打印到文件,打印的效果很好,但沒法代碼控制,始終會彈出一個打印對話框。
HTML2PDF:
另外,還可以使用HTML2PDF-X Pilot,下面是介紹:
HTML2PDF-X Pilot is a library that helps you easily create PDF reports with the help of HTML and perform HTML to PDF conversion. You can integrate the library into your application or you may use it as a standalone product.
下載地址:
使用很簡單,只需要給一個URL,下面是實例代碼:
VB
' Create HTML2PDF instance: Set html2pdf_obj = CreateObject("html2pdfx.HTML2PDFX") ' Initiate engine: html2pdf_obj.StartHTMLEngine "demo", "demo" ' Set PDF filename: html2pdf_obj.OutputFileName = "URL_to_PDF.pdf" ' Set page margins: html2pdf_obj.MarginLeft = 10 html2pdf_obj.MarginRight = 10 html2pdf_obj.MarginTop = 50 html2pdf_obj.MarginBottom = 50 html2pdf_obj.SetCustomPaperSize 420,594 ' After PageTimeout (in sec) loading will stop and conversion will proceed ' with loaded content: html2pdf_obj.PageTimeout = 40 ' Start PDF generation: html2pdf_obj.BeginDoc ' Define base URL for resolving relative links: html2pdf_obj.BaseURL = "//www.baidu.com" ' Load URL: html2pdf_obj.LoadURL "//www.baidu.com" ' Perform conversion: html2pdf_obj.ConvertAll ' Finish PDF generation: html2pdf_obj.EndDoc Set html2pdf_obj = nothing
也可以添加引用到ASP.NET項目中使用。
使用該軟件,需要購買授權,否則生成的PDF文件會有一個版權說明:
ABCpdf.NET是一個能夠很方便生成pdf的.net組件,能夠運行在以下操作系統(tǒng)中:Windows 2000, Windows XP, Windows Server 2003, Windows Vista, and Windows Server 2008.官方建議運行環(huán)境安裝IE6或者以上版本。對應不同的系統(tǒng),它有32位和64位的版本,使用時注意版本的選用。
ABCpdf的功能比較多,比如可以讀word、excel等文件,可以保存pdf、xps、swf等格式文件。本文主要介紹其生成pdf的方法。使用時,需要ABCpdf.DLL和ABCpdfCE7.DLL支持。其中ABCpdf.DLL(.net調用接口)需要引用到項目中,ABCpdfCE7.DLL(核心驅動)放在ABCpdf.DLL的同一目錄下即可。
在使用的時候,需要注冊,注冊后,需要重啟計算機。
下面是一段ASP.NET實例代碼:
[csharp]
Doc theDoc = new Doc(); //創(chuàng)建一個Doc對象 theDoc.Rect.Inset(24, 48); //Rect默認是文檔整個頁面大小, 這里的Inset表示將Rect左右留出24的空白,上下留出48的空白 int theID = theDoc.AddImageUrl("具體的網頁地址"); while (true) { if (!theDoc.Chainable(theID)) break; theDoc.Page = theDoc.AddPage(); theID = theDoc.AddImageToChain(theID); } theDoc.Save(Server.MapPath("1.pdf"));
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:Bluedoctor的專欄——CSDN