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合并的更多相关文章

  1. java根据模板HTML动态生成PDF

    原文:https://segmentfault.com/a/1190000009160184 一.需求说明:根据业务需要,需要在服务器端生成可动态配置的PDF文档,方便数据可视化查看. 二.解决方案: ...

  2. pdf 使用模板下载

    //根据模板下载模板 /** * * 政策5-8条的创建的pdf的模板 */public String createPdfCashTemplate(PdfCashParam pdfCashParam) ...

  3. iTextSharp生成pdf含模板(二)---C#代码部分

    参考地址:https://www.cnblogs.com/ibeisha/p/itextsharp-pdf.html 一.先在程序中使用Nuget安装iTextSharp(我是创建的控制台程序) 二. ...

  4. 使用pdf文本域模板生成对应的pdf

    第一步: 下载jar包 <!-- itext的pdf的依赖--> <dependency> <groupId>com.itextpdf</groupId> ...

  5. 【PDF】java使用Itext生成pdf文档--详解

    [API接口]  一.Itext简介 API地址:javadoc/index.html:如 D:/MyJAR/原JAR包/PDF/itext-5.5.3/itextpdf-5.5.3-javadoc/ ...

  6. 【强大的PDF格式转换工具】Lighten PDF Converter OCR for Mac 6.2.0

    [简介] Lighten PDF Converter OCR 是一款Mac上强大的PDF格式转换工具,可以将PDF文档快速批量的转换为Office (Word, Excel, PowerPoint), ...

  7. Word转pdf,再转图片插入PDF

    WORD转PDF所需jar包: https://yangtaotao.lanzous.com/ice1jlc PDF转图片所需jar包: https://yangtaotao.lanzous.com/ ...

  8. 插件Spire.PDF帮你高效搞定PDF打印

    Spire.PDF介绍 Spire.PDF是一个专业的PDF组件,能够独立地创建.编写.编辑.操作和阅读PDF文件,支持 .NET.Java.WPF和Silverlight.Spire.PDF的PDF ...

  9. 【使用Itext处理PDF文档(新建PDF文件、修改PDF文件、PDF中插入图片、将PDF文件转换为图片)】

    iText简介 iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成PDF或rtf的文档,而且可以将XML.Html文件转 ...

随机推荐

  1. ID3算法 决策树的生成(1)

    # coding:utf-8 import matplotlib.pyplot as plt import numpy as np import pylab def createDataSet(): ...

  2. 阿里云安装nginx 和 php-fpm

    yum install yum-priorities -y rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-releas ...

  3. linux设置系统日期时间

    设置当前日期: date -s 08/06/2015 设置当前时间:date -s 10:03:00 写入BIOS: clock -w 显示当前日期时间: date

  4. java 实现mysql数据库导出

    package com.zbb.util; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStre ...

  5. HttpClient简介 post get -转自ibm

    HttpClient简介 HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.虽然在 JDK 的 jav ...

  6. MySQL Binlog 【ROW】和【STATEMENT】选择(转)

    前言:       二进制日记录了数据库执行更改的操作,如Insert,Update,Delete等.不包括Select等不影响数据库记录的操作,因为没有对数据进行修改.二进制主要的功能有:复制(Re ...

  7. eclipse中java文件报错:The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

    问题:The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class fi ...

  8. java生成随机字符串uuid

    GUID是一个128位长的数字,一般用16进制表示.算法的核心思想是结合机器的网卡.当地时间.一个随即数来生成GUID.从理论上讲,如果一台机器每秒产生10000000个GUID,则可以保证(概率意义 ...

  9. OC—设计模式-通知的使用

    通知 通知(广播) 可以一对多的发送通知(一个发送者 多个观察者) 特别注意:在发送者 发送通知的时候,必须有观察者 发送者,就是注册一个通知中心,以他为中心,发送消息 通过通知的名字,来判断是哪个通 ...

  10. SPOJ #500. Turbo Sort

    Sorting is not an out-dated topic. My own in-place qsort got TLE... so, I simply called stl::sort() ...