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文件转 ...
随机推荐
- 视图缩放、移动、旋转--ios
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; view.backgroundColor=[UICo ...
- MySQL执行计划显示与执行过程不符合一例
一 建表和现象的过程如下 CREATE TABLE t1 (id1 INT, a1 INT, b1 INT, PRIMARY KEY(id1));CREATE TABLE t3 (id3 INT UN ...
- $.browser.msie 报错 null
jQuery 1.9 移除了 $.browser 的替代方法 January 16th, 2013FwolfLeave a commentGo to comments 授权方式:署名,非商业用途,保持 ...
- 递归函数练习:输出菲波拉契(Fibonacci)数列的前N项数据
/*====================================================================== 著名的菲波拉契(Fibonacci)数列,其第一项为0 ...
- wikioi 2235 机票打折 【考查浮点数四舍五入的技巧】
/*======================================================================== 2235 机票打折 题目描述 Descriptio ...
- android模拟器不能用键盘
android模拟器不能用键盘?咋整啊?
- LINQ to SQL语句
http://kb.cnblogs.com/page/42477/2/ 本系列文章导航 LINQ to SQL语句(1)之Where LINQ to SQL语句(2)之Select/Distinct ...
- C++ Socket编程步骤 【转】
sockets(套接字)编程有三种,流式套接字(SOCK_STREAM),数据报套接字(SOCK_DGRAM),原始套接字(SOCK_RAW):基于TCP的socket编程是采用的流式套接字. 服务器 ...
- zend studio一些常用配置
zend studio 常用 配置 1.zend中添加注释是ctrl+slash,这个slash在哪里?如何来取消注释 slash是斜杠'/'那个键,就是在,.之后的那个. 进行注释是 ctrl+'/ ...
- 剑指offer系列49--求1+2+...+N的和
[题目]求1+2+3+…+n, * 要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). package com.exe10.offer ...