Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:   namespace iTextSharp.tutorial.Chap13
8:   {
9:       /// <summary>
10:       /// Chap13_form ժҪ˵
11:       /// </summary>
12:       public class Chap13_form
13:       {
14:           public Chap13_form()
15:           {
16:          Console.WriteLine("Chapter 13: a form with some text");
17:  
18:           // step 1: creation of a document-object
19:           Document document new Document(PageSize.A450505050);
20:           try {
21:               // step 2: we create a writer that listens to the document
22:               PdfWriter writer PdfWriter.GetInstance(document,  new FileStream("Chap13_form.pdf"FileMode.Create));
23:               PdfAcroForm acroForm writer.AcroForm;
24:               // step 3: we open the document
25:               document.Open();
26:               // step 4: we add some content
27:               BaseFont helv BaseFont.CreateFont(BaseFont.HELVETICABaseFont.WINANSIBaseFont.NOT_EMBEDDED);
28:               float fontSize 12;
29:               acroForm.AddSingleLineTextField("name""your name"helvfontSize171800350820);
30:               acroForm.AddMultiLineTextField("msg""Hello iText!\nThis is a Test\nThere are multiple lines in this textfield"helvfontSize171730350790);
31:               acroForm.AddSingleLinePasswordField("password"""helvfontSize171700350720);
32:               acroForm.AddHtmlPostButton("btn""SUBMIT""noValue""Chap13.php"helvfontSize355700420725);
33:               acroForm.AddResetButton("reset""RESET"nullhelvfontSize430700495725);
34:               acroForm.AddCheckBox("CB1""Food"true180685190695);
35:               acroForm.AddCheckBox("CB2""Drinks"false180645210675);
36:               PdfFormField radiogroup acroForm.GetRadioGroup("CreditCard""Visa"true);
37:               acroForm.AddRadioButton(radiogroup"Visa"180625195640);
38:               acroForm.AddRadioButton(radiogroup"MasterCard"200625215640);
39:               acroForm.AddRadioButton(radiogroup"American"220625235640);
40:               acroForm.AddRadioGroup(radiogroup);
41:               String[] colors = {"Red""Green""Blue"};
42:               String[,] colorvalues = {{"#FF0000""Red"}, {"#00FF00""Green"}, {"#0000FF""Blue"}};
43:               acroForm.AddSelectList("list1"colors"Green"helvfontSize171550300600);
44:               acroForm.AddSelectList("list2"colorvalues"#0000FF"helvfontSize315550450600);
45:               acroForm.AddComboBox("combo1"colors"Green"truehelvfontSize171440300490);
46:               acroForm.AddComboBox("combo2"colorvalues"#0000FE"falsehelvfontSize315440450490);
47:               PdfContentByte cb new PdfContentByte(null);
48:               cb.SetRGBColorStroke(0x000x000x00);
49:               cb.SetRGBColorFill(0xFF0x000x00);
50:               cb.Arc(001001000360);
51:               cb.FillStroke();
52:               cb.SetRGBColorStroke(0x000x000x00);
53:               cb.SetRGBColorFill(0xFF0xFF0xFF);
54:               cb.Arc(202080800360);
55:               cb.FillStroke();
56:               cb.SetRGBColorStroke(0x000x000x00);
57:               cb.SetRGBColorFill(0xFF0x000x00);
58:               cb.Arc(404060600360);
59:               cb.FillStroke();
60:               cb.SetRGBColorFill(0x000x000x00);
61:               cb.Arc(484852520360);
62:               cb.Fill();
63:               acroForm.AddMap("map"null"Chap13.php"cb171300271400);
64:               acroForm.AddHiddenField("hidden""secret");
65:           }
66:           catch(DocumentException de
67:           {
68:               Console.Error.WriteLine(de.Message);
69:           }
70:           catch(IOException ioe
71:           {
72:               Console.Error.WriteLine(ioe.Message);
73:           }
74:  
75:           // step 5: close the document
76:           document.Close();
77:           }
78:       }
79:   }