Form_radio: Example code of Early Access iText
Last Update:2018-12-08
Source: Internet
Author: User
Using System;
Using iTextSharp. text;
Using iTextSharp.text.pdf;
Using System. IO;
Public class form_radio
{
[STAThread]
Public static void Main (string [] args)
{
Document document = new Document (PageSize. A4, 50, 50, 50, 50 );
Try
{
// Creation of the different writers
Using writer = Using writer. GetInstance (document, new FileStream (@ "e: \ java \ form_radio.Pdf", FileMode. Create ));
Document. Open ();
Required contentbyte cb = writer. DirectContent;
Cb. MoveTo (0, 0 );
PdfFormField radio = PdfFormField. CreateRadioButton (writer, true );
Paiappearance tpOff = cb. CreateAppearance (20, 20 );
Export appearance tpOn = cb. CreateAppearance (20, 20 );
TpOff. Circle (10, 10, 9 );
TpOff. Stroke ();
TpOn. Circle (10, 10, 9 );
TpOn. Stroke ();
TpOn. Circle (10, 10, 3 );
TpOn. FillStroke ();
Radio. FieldName = ("CreditCard ");
Radio. ValueAsName = ("MasterCard ");
PdfFormField radio1 = PdfFormField. CreateEmpty (writer );
Radio1.SetWidget (new Rectangle (100,700,120,720), PdfAnnotation. HIGHLIGHT_INVERT );
Radio1.AppearanceState = ("MasterCard ");
Radio1.SetAppearance (PdfAnnotation. APPEARANCE_NORMAL, "Off", tpOff );
Radio1.SetAppearance (PdfAnnotation. APPEARANCE_NORMAL, "MasterCard", tpOn );
Radio. AddKid (radio1 );
PdfFormField radio2 = PdfFormField. CreateEmpty (writer );
Radio2.SetWidget (new Rectangle (100,660,120,680), PdfAnnotation. HIGHLIGHT_INVERT );
Radio2.AppearanceState = ("Off ");
Radio2.SetAppearance (PdfAnnotation. APPEARANCE_NORMAL, "Off", tpOff );
Radio2.SetAppearance (PdfAnnotation. APPEARANCE_NORMAL, "Visa", tpOn );
Radio. AddKid (radio2 );
PdfFormField radio3 = PdfFormField. CreateEmpty (writer );
Radio3.SetWidget (new Rectangle (100,620,120,640), PdfAnnotation. HIGHLIGHT_INVERT );
Radio3.AppearanceState = ("Off ");
Radio3.SetAppearance (PdfAnnotation. APPEARANCE_NORMAL, "Off", tpOff );
Radio3.SetAppearance (PdfAnnotation. APPEARANCE_NORMAL, "American", tpOn );
Radio. AddKid (radio3 );
Writer. AddAnnotation (radio );
Document. Close ();
System. Console. Out. WriteLine ("FIM .");
}
Catch (System. Exception de)
{
System. Console. Error. WriteLine (de. Message );
}
}
}