生成PDF并下载。
2024-10-19 13:30:42
例子是生成一个pdf格式的证书:
需要引用itextsharp.dll
//创建Document
Document document = null;
//为该Document创建一个Writer实例
PdfWriter writer = null;
//段(内容)
Paragraph p = null;
//字体
BaseFont baseFont = BaseFont.CreateFont(Server.MapPath("Configuration/STZHONGS.TTF"), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = null;
//内存流
document = new Document(PageSize.A4.Rotate(), , , , ); //为该Document创建一个Writer实例
writer = PdfWriter.GetInstance(document, new FileStream(filepath + strCerId + ".pdf", FileMode.Create));
//writer.SetEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.ALLOW_PRINTING);
//打开
document.Open(); //指定位置添加图片
PdfContentByte pcb1 = writer.DirectContent;
iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(Server.MapPath("Configuration/1.png"));
image1.SetAbsolutePosition(, );
image1.ScaleAbsolute(, );
pcb1.AddImage(image1); font = new Font(baseFont, , Font.BOLD);
p = new Paragraph("\n\n“标题", font);
p.Alignment = Element.ALIGN_CENTER;
document.Add(p); font = new Font(baseFont, , Font.BOLD);
p = new Paragraph("标题", font);
p.Alignment = Element.ALIGN_CENTER;
document.Add(p); font = new Font(baseFont, , Font.NORMAL);
p = new Paragraph("\n 正文。", font);
p.Alignment = Element.ALIGN_LEFT;
document.Add(p); font = new Font(baseFont, , Font.NORMAL);
p = new Paragraph("\n署名", font);
p.Alignment = Element.ALIGN_RIGHT;
document.Add(p); font = new Font(baseFont, , Font.NORMAL);
p = new Paragraph("2016年6月22日", font);
p.Alignment = Element.ALIGN_RIGHT;
document.Add(p);
//关闭目标文件
document.Close();
writer.Close();
document = null;
//关闭写入流
writer = null;
图片:
最新文章
- H5常用代码:适配方案4
- Hadoop:Windows 7 32 Bit 编译与运行
- String的两个API,判断指定字符串是否包含另一字符串,在字符串中删除指定字符串。
- POJ --- 3613 (K步最短路+矩阵快速幂+floyd)
- java学习多线程之卖票示例
- mysql加入�管理员
- 执行计划之CONCATENATION
- C#Redis列表List
- POP音原因
- ActiveMQ基本详解与总结
- 安装php扩展 ffmpeg-php
- django+mysql的使用
- [Swift]LeetCode980. 不同路径 III | Unique Paths III
- hibernate框架的简单入门
- 版本管理工具小乌龟TortoiseGit的安装和使用(1)
- QWaitConditioin的思考1
- 函数式编程之 Python
- ASP.NET:Forms身份验证和基于Role的权限验证
- Hdu1163 Eddy's digitai Roots(九余数定理)
- 一段js的思考