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;
Doc theDoc = new Doc();
theDoc.FontSize = 96;
theDoc.AddText("Hello World");
theDoc.Save(Server.MapPath("simple.pdf"));//保存到相对路径
theDoc.Clear();
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“);
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);