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

本文介绍了如何在ASP.NET项目中使用ABCPdf库来创建PDF文件,并详细讲解了从下载ABCPdf到引用、编写代码生成PDF,最后实现PDF文件的下载步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

参考



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值