Field_merge: Example code of Early Access iText (how to fill PDF form with iTextSharp)

Source: Internet
Author: User
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 );
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.