PDF按模板出力,多个PDF合并
const string TEMP_PREXFIX = "Temp_"; | ||||||||||||||||
string _tempfilename01; | ||||||||||||||||
PdfReader _pdfReader = null; | ||||||||||||||||
BaseFont _baseFont = null; | ||||||||||||||||
PdfStamper _pdfStamper = null; | ||||||||||||||||
string _sourcefilename01 = ".\\PDF\\faxcre01.pdf"; | ||||||||||||||||
string _targetfilename01 = ".\\PDF\\faxcre01_生成.pdf"; | ||||||||||||||||
string fileName01 = Path.GetFileName(_targetfilename01); | ||||||||||||||||
string path = Path.GetDirectoryName(_targetfilename01); | ||||||||||||||||
_tempfilename01 = path + @"\TEMP\" + TEMP_PREXFIX + fileName01; | ||||||||||||||||
_baseFont = BaseFont.CreateFont(@"c:\windows\fonts\msmincho.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); | ||||||||||||||||
BaseFont bfTimes = BaseFont.CreateFont(@"c:\windows\fonts\msmincho.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); | ||||||||||||||||
iTextSharp.text.Font times = new Font(bfTimes, 12, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.RED); | ||||||||||||||||
Font palatino = FontFactory.GetFont(@"c:\windows\fonts\msmincho.ttc,0", BaseFont.CP1252, BaseFont.EMBEDDED, 10, Font.ITALIC, BaseColor.GREEN); | ||||||||||||||||
//--------------------template1-------------------- | ||||||||||||||||
FileStream ReadPdf = new FileStream(_tempfilename01, FileMode.Create); | ||||||||||||||||
//pdf reader | ||||||||||||||||
_pdfReader = new PdfReader(_sourcefilename01); | ||||||||||||||||
_pdfStamper = new PdfStamper(_pdfReader, ReadPdf); | ||||||||||||||||
_pdfStamper.AcroFields.AddSubstitutionFont(_baseFont); | ||||||||||||||||
////set field: MSゴシック | ||||||||||||||||
//_pdfStamper.AcroFields.SetFieldProperty("f_print_date", "textfont", _baseFont, null); | ||||||||||||||||
//_pdfStamper.AcroFields.SetFieldProperty("f_print_time", "textfont", _baseFont, null); | ||||||||||||||||
//_pdfStamper.AcroFields.SetFieldProperty("f_jusyo_kana", "textfont", _baseFont, null); | ||||||||||||||||
//_pdfStamper.AcroFields.SetFieldProperty("f_hoken_syurui", "textfont", _baseFont, null); | ||||||||||||||||
//_pdfStamper.AcroFields.SetFieldProperty("f_sfx_info1", "textfont", _baseFont, null); | ||||||||||||||||
//_pdfStamper.AcroFields.SetFieldProperty("f_sfx_info2", "textfont", _baseFont, null); | ||||||||||||||||
//Font font = FontFactory.GetFont(FontFactory.COURIER, 8f, iTextSharp.text.Font.BOLD); | ||||||||||||||||
////_pdfStamper.AcroFields.SetFieldProperty("f_sfx_info2", "textfont", font.BaseFont, null); | ||||||||||||||||
//_pdfStamper.AcroFields.SetFieldProperty("f_sfx_info2", "textfont", times.ToString(), null); | ||||||||||||||||
Font font = new Font(_baseFont, 8f, iTextSharp.text.Font.BOLD); | ||||||||||||||||
FontFactory.Register(@"c:\windows\fonts\msmincho.ttc,0", "myFont"); | ||||||||||||||||
//FontFactory.GetFont(FontFactory.GetFont("myFont").ToString(), 28,iTextSharp.text.BaseColor.RED); | ||||||||||||||||
Font myFont = FontFactory.GetFont("myFont"); | ||||||||||||||||
//Font myFont = FontFactory.GetFont("myFont", 56, Font.BOLD); | ||||||||||||||||
BaseFont bf = myFont.BaseFont; | ||||||||||||||||
_pdfStamper.AcroFields.SetFieldProperty("f_print_date", "textfont", bf, null); | ||||||||||||||||
_pdfStamper.AcroFields.SetFieldProperty("f_print_time", "textfont", bf, null); | ||||||||||||||||
_pdfStamper.AcroFields.SetFieldProperty("f_jusyo_kana", "textfont", bf, null); | ||||||||||||||||
_pdfStamper.AcroFields.SetFieldProperty("f_hoken_syurui", "textfont", bf, null); | ||||||||||||||||
_pdfStamper.AcroFields.SetFieldProperty("f_sfx_info1", "textfont", bf, null); | ||||||||||||||||
_pdfStamper.AcroFields.SetFieldProperty("f_sfx_info2", "textfont", _baseFont, null); | ||||||||||||||||
_pdfStamper.AcroFields.SetField("f_print_date", "2016/7/07"); | ||||||||||||||||
_pdfStamper.AcroFields.SetField("f_print_time", "13:21"); | ||||||||||||||||
_pdfStamper.AcroFields.SetField("f_jikoseiribango", "1332658-9"); | ||||||||||||||||
_pdfStamper.AcroFields.SetField("f_karino", "040A0001664"); | ||||||||||||||||
//編集不可設定 | ||||||||||||||||
_pdfStamper.FormFlattening = true; | ||||||||||||||||
_pdfStamper.Close(); | ||||||||||||||||
_pdfReader.Close(); | ||||||||||||||||
ReadPdf.Close(); | ||||||||||||||||
// 合成pdf文件 | ||||||||||||||||
string _targetfilename = "faxcre_000.pdf"; | ||||||||||||||||
string _tempfilename = path + @"\TEMP\" + TEMP_PREXFIX + _targetfilename; | ||||||||||||||||
PdfReader reader01; | ||||||||||||||||
Document document = new Document(); | ||||||||||||||||
PdfSmartCopy copy = new PdfSmartCopy(document, new FileStream(_tempfilename, FileMode.Create)); | ||||||||||||||||
document.Open(); | ||||||||||||||||
reader01 = new PdfReader(_tempfilename01); | ||||||||||||||||
copy.AddDocument(reader01); | ||||||||||||||||
reader01.Close(); | ||||||||||||||||
if (File.Exists(_tempfilename01)) | ||||||||||||||||
{ | ||||||||||||||||
File.Delete(_tempfilename01); | ||||||||||||||||
} | ||||||||||||||||
_pdfStamper.Dispose(); | ||||||||||||||||
_pdfReader.Dispose(); | ||||||||||||||||
ReadPdf.Dispose(); | ||||||||||||||||
document.Close(); | ||||||||||||||||
PDF按模板出力,多个PDF合并的更多相关文章
- java根据模板HTML动态生成PDF
原文:https://segmentfault.com/a/1190000009160184 一.需求说明:根据业务需要,需要在服务器端生成可动态配置的PDF文档,方便数据可视化查看. 二.解决方案: ...
- pdf 使用模板下载
//根据模板下载模板 /** * * 政策5-8条的创建的pdf的模板 */public String createPdfCashTemplate(PdfCashParam pdfCashParam) ...
- iTextSharp生成pdf含模板(二)---C#代码部分
参考地址:https://www.cnblogs.com/ibeisha/p/itextsharp-pdf.html 一.先在程序中使用Nuget安装iTextSharp(我是创建的控制台程序) 二. ...
- 使用pdf文本域模板生成对应的pdf
第一步: 下载jar包 <!-- itext的pdf的依赖--> <dependency> <groupId>com.itextpdf</groupId> ...
- 【PDF】java使用Itext生成pdf文档--详解
[API接口] 一.Itext简介 API地址:javadoc/index.html:如 D:/MyJAR/原JAR包/PDF/itext-5.5.3/itextpdf-5.5.3-javadoc/ ...
- 【强大的PDF格式转换工具】Lighten PDF Converter OCR for Mac 6.2.0
[简介] Lighten PDF Converter OCR 是一款Mac上强大的PDF格式转换工具,可以将PDF文档快速批量的转换为Office (Word, Excel, PowerPoint), ...
- Word转pdf,再转图片插入PDF
WORD转PDF所需jar包: https://yangtaotao.lanzous.com/ice1jlc PDF转图片所需jar包: https://yangtaotao.lanzous.com/ ...
- 插件Spire.PDF帮你高效搞定PDF打印
Spire.PDF介绍 Spire.PDF是一个专业的PDF组件,能够独立地创建.编写.编辑.操作和阅读PDF文件,支持 .NET.Java.WPF和Silverlight.Spire.PDF的PDF ...
- 【使用Itext处理PDF文档(新建PDF文件、修改PDF文件、PDF中插入图片、将PDF文件转换为图片)】
iText简介 iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成PDF或rtf的文档,而且可以将XML.Html文件转 ...
随机推荐
- Nginx-SSI
<a href="<!--#include file="/$SERVER_NAME.shtml"-->">点击</a> a
- $.ajax提交,后台接受到的值总是乱码?明天再总结
//首先说明,我的服务器和页面编码都是GBK,所以尝试了很多种GBK的方式前台:function printFunction(){ window.print(); $.ajax({ url : '/t ...
- xUtils3的简单介绍
xUtils3的简介 xUtils是基于Afinal开发的目前功能比较完善的一个Android开源框架,最近又发布了xUtil3.0,在增加新功能的同时又提高了框架的性能. 1.xUtils包含了很多 ...
- linux nginx 配置ssl证书访问
http://www.linuxidc.com/Linux/2013-08/88271.htm 一.什么是 SSL 证书,什么是 HTTPSSSL 证书是一种数字证书,它使用 Secure Socke ...
- 在EDIUS中调整素材颜色的方法
EDIUS是一款非线性编辑软件,有很强大的视频剪辑功能,很受学习视频剪辑的同学欢迎.本EDIUS教程今天的主要目的就是分享自己学习经验写了一篇EDIUS入门教程文章,希望能给学习EDIUS的小伙伴带来 ...
- 009. C#中的WebBrowser控件的属性、方法及操作演示代码(转)
本文转自 http://www.open-open.com/code/view/1430559996802 0.常用方法 Navigate(string urlString):浏览urlString表 ...
- Java语言编码规范(Java Code Conventions)
Java语言编码规范(Java Code Conventions) 名称 Java语言编码规范(Java Code Conventions) 译者 晨光(Morning) 简介 本文档讲述了Java语 ...
- mysql-master-ha
https://code.google.com/p/mysql-master-ha/wiki/TableOfContents?tm=6 http://www.cnblogs.com/gomysql/c ...
- 关于iis站点无法读取 服务器共享目录的问题
也是权限问题,具体解决方法如下: 1. 找到该站点所在的应用程序池>>高级设置>>进程模型>>设置标志账号,如下图所示 2. 设置账号之后,找到该共享目录>& ...
- 黄聪:VPS实现自动定时备份网站数据以及Mysql数据库到百度云同步盘
建站多了,备份成了头疼的问题,因为你不知道你的VPS什么时候会宕机或者服务商跑路,一旦网站数据丢失,那么相当于前功尽弃了,所以自己研究出了一套自动备份的方法. 需要的东西: 1.一个VPS(虚拟空间没 ...