您的位置:首页 > 编程语言 > ASP

asp.net使用ABCpdf写pdf并下载的方法

2015-12-24 17:22 691 查看
1.安装ABCPdf

下载地址

2.在项目中添加引用

ABCpdf.dll
ABCpdf10-32.dll / ABCpdf10-64.dll
PrintHook32.dll / PrintHook64.dll


3.using namespace

using WebSupergoo.ABCpdf10;
using WebSupergoo.ABCpdf10.Objects;
using WebSupergoo.ABCpdf10.Atoms;
using WebSupergoo.ABCpdf10.Operations;


4.写pdf

Doc theDoc = new Doc();
theDoc.FontSize = 96;
theDoc.AddText("Hello World");
theDoc.Save(Server.MapPath("simple.pdf"));//保存到相对路径
theDoc.Clear();


5.横向pdf

Doc theDoc = new Doc();
double w = theDoc.MediaBox.Width;
double h = theDoc.MediaBox.Height;
double l = theDoc.MediaBox.Left;
double b = theDoc.MediaBox.Bottom;
theDoc.Transform.Rotate(90, l, b);
theDoc.Transform.Translate(w, 0);
// rotate our rectangle
theDoc.Rect.Width = h;
theDoc.Rect.Height = w;
// add some text
theDoc.Rect.Inset(10, 10);//设置边距
theDoc.Rect.SetRect(340,220, 200, 200);//SetRect(Left,Bottom,width,height)
theDoc.FontSize = 40;
theDoc.AddText("Hello“);


6.写中文

theDoc.Font = theDoc.EmbedFont("微软雅黑", LanguageType.ChineseS);//设置字体和语言
theDoc.AddText("你好");


7.下载pdf

byte[] buffer = theDoc.GetData();
Response.Buffer = false;
Response.AddHeader("Connection", "Keep-Alive");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=MyPDF.PDF");
Response.AddHeader("Content-Length", buffer.Length.ToString());
Response.BinaryWrite(buffer);


参考
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: