{oapdf_gg}
List 6. Create a form object Table t = new Table (3,2);
t.setBorderColor (new Color (220, 255, 100)); t.setPadding (5); t.setSpacing (5); t.setBorderWidth (1); Cell c1 = new Cell ( "header1"); c1.setHeader (true); t.addCell (c1); c1 = new Cell ( "Header2"); t.addCell (c1); c1 = new Cell ( "Header3"); t.addCell (c1); t.endHeaders (); t.addCell ( "1.1"); t.addCell ( "1.2"); t.addCell ( "1.3"); section1.add (t); In the above code, creates a form object, t, it has three, two lines. And then set the table border color. Filling the cell to set the interval between the Chinese text as well as the borders of the cell. Interval refers to the inter-adjacent cell borders. Next, create three target cells, each cell is different text. Next, add them to the table. Add them to the first line, from the beginning of the first column, the same line to the next column. Once created it will add the next cell to the next line in the first column. Can only provide the text of the cell will be added to the table cell, for example, t.addCell ( "1.1");. Finally, the object will be added to the section table object. Finally, we look at how to add them to the PDF document. List contains a certain number of ListItem. Can be carried out on the list of numbers can not code. Will be the first parameter set to true to indicate that would like to create a numbered list. List of 7. To create a list of objects List l = new List (true, false, 10);
l.add (new ListItem ( "First item of list "));< br/> l.add (new ListItem ( "Second item of list "));< br/> section1.add (l); Chapter1 object we have to add the necessary objects. Therefore, there is no need to add other elements to chapter1, and now can be added to the chapter1 in the main document. Examples of applications in the same done to close the document object at this time. 8 list. Add to the main sections of the document document.add (chapter1);
document.close (); Run sample applications Download sample application, j-itextsample.jar (see download). In a directory extract j-itextsample.jar. For example, if you extract it to C: \ temp, it would be a source and class files into C: \ temp \ com \ itext \ test directory. Open a command prompt, change directory to C: \ temp. In the command prompt, type in the path of the system. Will be C: \ temp \ itext-1.3.jar included in the system classpath. In Windows? On the implementation of the command set classpath = C: \ temp \ itext-1.3.jar;% classpath%. Use the command to run java com.itext.test.ITextTest applications. Procedures in C: \ directory under the document generate a ITextTest.pdf. The following PDF document shows the second page of the screen map. Figure 3. PDF document screen map Conclusion You have seen some of the basic elements to generate PDF. The beauty of iText is the same as the syntax element can be written for different types of uses. Also, write the output can be redirected to the console (when the write type is XML and HTML, when), servlet output stream (in the PDF document response to Web requests) or other types of OutputStream. When the same response, but with the request type is PDF, RTF, HTML or XML document and have not at the same time, the use of iText is very convenient. iText allows users to create a watermark, encryption of documents and other output settings details. |