用c语言怎样将swf转化为pdf,利用ABCpdf.NET将网页转换成PDF的方法小结

中转方式:

大多数时候,都是使用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 = "http://www.baidu.com"

' Load URL:

html2pdf_obj.LoadURL "http://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组件,能够运行在以下操作系统中:Windows 2000, Windows XP, Windows Server 2003, Windows Vista, and Windows Server 2008.官方建议运行环境安装IE6或者以上版本。对应不同的系统,它有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(); //创建一个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"));

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至hey@evget.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值