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文件转 ...
随机推荐
- python_Day1_基础知识开篇
一.python安装 1)windows上同时安装python2.0和python3.0配置 (1)在python官网下载windows版本python2.0和python3.0安装包 官网地址:ht ...
- iproute-2.6.32
iproute之tc命令翻译地址,man tc的翻译 http://blog.csdn.net/ysdaniel/article/details/7905879
- Q5: Remove Duplicates from Sorted Array
问题描述: Given a sorted array, remove the duplicates in place such that each element appear only once a ...
- Storm0.9.4安装 - OPEN 开发经验库
Storm0.9.4安装 - OPEN 开发经验库 bin/zkServer.sh start /home/guym/down/kafka_2.8.0-0.8.0/config/zookeeper.p ...
- AngularJS_对象数组-filter-orderBy
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 基于HDInsight 3.4 HBase集群规划参考
基于linux 创建HDInsight HBase集群,选择最小配置,zk(3).NN(2).WN(2),集群节点默认组件服务规划如下 NN0: Active NameNode /HDFS ZKFai ...
- eclipse debug小技巧
测试 Expressions 代码 public static void main(String[] args) { int x=100; System.out.println("----& ...
- [Hibernate] - Query Select
测试了常用的一些HQL查询方法,具体HQL的强大可以参考: http://docs.jboss.org/hibernate/orm/3.5/reference/zh-CN/html/queryhql. ...
- 05 Linux下开发JSP项目(Hello world)
测试环境: 主机系统:Win 7 虚拟机:VMware workstation 11.1.0 虚拟机OS: centos 6.5 64位 Kernel 2.6.32-431-e16.x86_64 My ...
- Winform退出程序
1.this.Close(); 只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application.Exit(); 强制所有消息中止,退 ...