asp.net使用ABCpdf写pdf并下载的方法
2015-12-24 17:22
691 查看
1.安装ABCPdf
下载地址
2.在项目中添加引用
3.using namespace
4.写pdf
5.横向pdf
6.写中文
7.下载pdf
参考
下载地址
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);
参考
相关文章推荐
- asp.net WebPages 速记4
- ASP.NET MVC4/5 - Ajax 防止 CSRF攻击
- 如何自动更新-CMD
- asp.net生成csv文件
- ASPX页面加载C#报错
- asp.net mvc杂项收集
- 避开WebForm天坑,拥抱ASP.Net MVC吧
- asp.net WebPages 速记3
- 避开WebForm天坑,拥抱ASP.Net MVC吧
- ASP.NET html转图片
- ASP.NET 对象的使用
- asp分页技术的实现
- Resharper让我们的asp.net开发效率提高三分之一
- asp.net WebPages 速记2
- asp.net WebPages 速记1
- kali攻防第12章 Metasploit之服务器蓝屏攻击
- 盘点PHP和ASP.NET的10大对比!
- ASP.NET MVC4(Razor)从客户端中检测到有潜在危险的 Request.Form 值
- ASP.NET中最保险最环保的返回404的方法
- 盘点PHP和ASP.NET的10大对比!