posts - 200,  comments - 1420,  trackbacks - 6
using System;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
public class field_merge
{
    
    
private static void  usage()
    {
        
        System.Console.Out.WriteLine(
"Field merging and flattening");
        System.Console.Out.WriteLine(
"usage: field_merge [-f] infile_pdf outfile_pdf [[name1=value1][namex=valuex]]");
        System.Console.Out.WriteLine(
"    -f - flatten the fields");
    }
    

    [STAThread]
    
public static void  Main(string[] args)
    {
        
if (args.Length < 2)
        {
            usage();
            
return ;
        }
        
int idx = 0;
        
if (args[0].Equals("-f"))
            
++idx;
        
if (args.Length - idx < 2)
        {
            usage();
            
return ;
        }
        
string in_pdf = args[idx];
        
string out_pdf = args[idx + 1];
        
try
        {
            PdfReader reader 
= new PdfReader(in_pdf);
            PdfStamper stamp 
= new PdfStamper(reader, new FileStream(out_pdf, FileMode.Create));
            AcroFields form 
= stamp.AcroFields;
            
for (int k = idx + 2; k < args.Length; ++k)
            {
                
string t = args[k];
                
int x = t.IndexOf((System.Char) '=');
                
if (x > 0)
                {
                    
string field = t.Substring(0, (x) - (0));
                    
string value_Renamed = t.Substring(x + 1);
                    form.SetField(field, value_Renamed);
                }
            }
            
if (idx > 0)
                stamp.FormFlattening
=(true);
            stamp.Close();
            System.Console.Out.WriteLine(
"Done.");
        }
        
catch (System.Exception e)
        {
            System.Console.Error.WriteLine(e.Message);
        }
    }
}
posted on 2006-07-18 09:29 RubyPDF 阅读(1758) 评论(1)  编辑 收藏 网摘 所属分类: iTextSharp(iText#)

FeedBack:
2009-03-16 14:41 | 追忆似水流年      
楼主你好,我在填充PDF模板文件时,里面有几个CheckBox勾选的框,如何只勾选其中的一个呢?查了好多资料,好像都是提到填充TextField的值,对于勾选框如果进行勾选呢?
  回复  引用  查看    



发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 453494




相关文章:

相关链接:
<2006年7月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

与我联系

搜索

 

常用链接

我参与的团队

我的标签

随笔分类(176)

PDF

最新随笔

积分与排名

  • 积分 - 451211
  • 排名 - 70

最新评论

阅读排行榜

评论排行榜