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. unity, 由5.2.1f1升级到5.3.5f1,2d物理不正常解法

    由5.2.1f1升级到5.3.5f1,物理不正常. 最后发现问题出在我的游戏中的下面一段代码:   Vector2 targetPosition=...;   Vector2 targetVeloci ...

  2. Collection+JSON 文档

    Collection+JSON 文档 对于这个设计,我们不再以可能的状态和转移为起点,相反,我们将从一个集合状态响应中可能元素的顶层布局开始.从这一点入手,其他细节可以随着设计向超媒体类型最底层属性的 ...

  3. es6语法重构react代码

    1.使用React.Component创建组件,需要通过在constructor中调用super()将props传递给React.Component.另外react 0.13之后props必须是不可变 ...

  4. redis的启动与停止

    启动: redis-server /etc/redis/6379.conf 停止:进入src文件目录 redis-cli -a 数据库密码 shutdown

  5. HDP2.4安装(二):Centos7配置

    Centos7 Minimal Install 安装完成后是不支持上网的,并且大部分常用的软件也未安装,首先要解决的问题就是网络配置.当网络配通后,即可通过Xshell或其它工具来远程进行操作与管理, ...

  6. C++中的空类与空结构体大小

    今天面试遇到了一个很有意思的问题,即空结构体在C++中所占的内存大小是多少?参见如下代码: #include <iostream> struct S0 { }; int main() { ...

  7. Eclipse的中文字体设置

    打开eclipse中文字体很小,简直难以辨认.在网上搜索发现这是由于Eclipse 用的字体是 Consolas,显示中文的时候默认太小了.解决方式有两种:一.把字体设置为Courier New  操 ...

  8. android学习笔记八——SeekBar

    SeekBar——拖动条 拖动条(SeekBar)组件与ProgressBar水平形式的显示进度条类似,不过其最大的区别在于,拖动条可以由用户自己进行手工的调节,例如当用户需要调整播放器音量或者电影的 ...

  9. android如何播放资源文件夹raw中的视频

    转自这里 videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/&qu ...

  10. 287. Find the Duplicate Number

    Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), pro ...