当前位置: 首页 > 工具软件 > ABCpdf > 使用案例 >

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

颜镜
2023-12-01

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);

参考



 类似资料: