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 ));
Required Fields form = stamp. Required Fields;
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 );
}
}
}