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);
}
}
}
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);
}
}
}
分类:
2..NET新手区,
iTextSharp(iText#)\\
本文转自
RubyPdf 的中文博客博客园博客,原文链接:
http://www.cnblogs.com/hardrock/archive/2006/07/18/453494.html
/,如需转载请自行联系原作者