{oapdf_gg}
Part II Other Document FormatChapter VII XML and (X) HTMLthis chapter introduces how to use iText to generate XLM documents and controls (X) HTML document, but we are not interested in them, it only introduced in this chapter will be referred to XML to PDF. in the first chapter, we step 5 to produce a PDF file, an XML document in order to convert the PDF file, just rewrite the paragraphs 3 and 4 Step 5 Step automatic processing by the parser. //Step 3:Create a resolver and set the document handler: iTextHandler h = new iTextHandler (document); //step 4, conversion of the document: h.Parse ( "Chap0701.xml "); sample code, see sample code 0702 Chapter VIII RTF documentRTF packageRTF package is based on the expansion pack by iText, iText In addition to allow the generation of PDF documents can also be output RTF file, in addition to the package in RTF does not support the features, most features PDF documents can be used. create a RTF documentcreate an RTF document and create a PDF document is the same as are the basic step 5, the only difference is that Step 2 instead of RtfWriter with PdfWriter, see sample code 0801. Step 1 to create a instance of the iTextSharp.text.Document object: Document document = new Document (); Step 2 of RtfWriter create a document will be written into the document output stream of your choice: RtfWriter.getInstance (document, new FileStream ( "Chap0801.rtf"), FileMode.Create); Step 3 Open the document: document.Open (); Step 4 Add content to the document document.Add (new Paragraph ( "Hello World ")); Step 5 Close document document.Close (); on how to create and add other objects in the document, please refer to the contents of other chapters. characteristics do not support
RTF in expansion of the header and footerRTF can notwrite a new page in the beginning before the setHeader method to change the header or footer files, there are two ways to solve this problem.
u use RtfHeaderFooters type Step 1 to create a RtfHeaderFooters category: RtfHeaderFooters headers = new RtfHeaderFooters (); Step 2 Add HeaderFooter object headers.Add (RtfHeaderFooters.LEFT_PAGES, new HeaderFooter (new Phrase ( "This header is only on left hand pages "))); headers.Add (RtfHeaderFooters.RIGHT_PAGES, new HeaderFooter (new Phrase ( "This header is only on right hand pages "))); Step 3 the same as the use of the use of header footer RtfHeaderFooters document.Header = headers; constant RtfHeaderFooters.add (...) to use:
there is one thing very important:If you use LEFT_PAGES or to set up RIGHT_PAGES header or footer, and then use ALL_PAGES, both headers and footers will not work. Form 0804 results, see the sample code. |