ABCpdf.NET 使用介绍
戴俊-2010-1-7
一、 ABCpdf.NET 简单介绍
ABCpdf.NET 是一个能够很方便生成 pdf 的.net 组件,能够运行在以下操作系统中:
Windows 2000, Windows XP, Windows Server 2003, Windows Vista, and Windows Server
2008.官方建议运行环境安装 IE6 或者以上版本。对应不同的系统,它有 32 位和 64 位的版
本,使用时注意版本的选用。如果在 64(32)位系统使用 32(64)位版本,则可能发生不
可预料的错误,使用时请根据运行环境选择正确的版本。二者的使用方法都是一样的。
ABCpdf 的功能比较多,比如可以读 word、excel 等文件,可以保存 pdf、xps、swf 等
格式文件。本文主要介绍其生成 pdf 的方法。使用时,需要 ABCpdf.DLL 和 ABCpdfCE7.DLL
支持。其中 ABCpdf.DLL(.net 调用接口)需要引用到项目中,ABCpdfCE7.DLL(核心驱动)
放在 ABCpdf.DLL 的同一目录下即可。
ABCpdf 的坐标系采用 Adobe PDF 标准坐标系,原点在屏幕的左下角(非 windows 默认
坐标系的左上角),采用 72DPI,我们显示器用的通常是 96DPI,在计算大小时注意转换(如
果需要 PDF 里面的页面大小和 HTML 显示的一致),网页面上的 96px 相当于 ABCpdf 里面 72px。
二、 入门,生成第一个 pdf 文件
这一节将通过实例来展示如何用 ABCpdf.NET 生成 pdf 文件。在使用前需要引入
ABCpdf.DLL,在代码中引用名空间:
using WebSupergoo.ABCpdf7;
通常情况下只需要引入这个
名空间就可以了。
Code:
private void GeneratePdfTest1()
{
using (Doc theDoc = new Doc())
{
theDoc.Rect.Inset(24, 48);
//Rect默认是文档整个页面大小, 这里的Inset表示将Rect左右留出24的空白,上下留出
48的空白
theDoc.Color.String = "32,48,117";
theDoc.FrameRect();//为当前rect添加边框
theDoc.MediaBox.String = "0 0 590 840";//设置添加新页面时,页面的大小
theDoc.Rect.String = "14 14 576 770";//当前输出区间
theDoc.Color.String = "192,48,117";
theDoc.FrameRect();
theDoc.FontSize = 12;
theDoc.AddText("Hello World");
theDoc.Font = theDoc.AddFont("宋体", "ChineseS");
theDoc.FontSize = 16;
theDoc.Flatten();//合并pdf各个layer,减少pdf大小
theDoc.Save(Server.MapPath("simple.pdf"));
theDoc.Clear();
}
评论0
最新资源