public void XmlToRtf(string xmlDoc, string strFilename) { Document document = new Document(); MemoryStream ms = new MemoryStream(); Phrase headerPhrase; Phrase footerPhrase; // iTextSharp RtfWriter2 writer = RtfWriter2.GetInstance(document, ms); footerPhrase = new Phrase("", new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8)); RtfHeaderFooter footer = new RtfHeaderFooter(footerPhrase); footer.SetAlignment("center"); writer.Footer = footer; AssemblyName an = this.GetType().Assembly.GetName(); headerPhrase = new Phrase( "Use Case Maker " + an.Version.ToString(3), new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 8)); RtfHeaderFooter header = new RtfHeaderFooter(headerPhrase); header.SetAlignment("right"); writer.Header = header; StringReader sr = new StringReader(xmlDoc); XmlTextReader reader = new XmlTextReader(sr); ITextHandler xmlHandler = new ITextHandler(document); try { xmlHandler.Parse(reader); } catch (Exception e) { ms.Close(); throw e; } finally { reader.Close(); sr.Close(); } //Write output file FileStream fs = new FileStream(strFilename, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(ms.ToArray()); bw.Close(); fs.Close(); ms.Close(); }
/** * Constructs a RtfHeaderFooter as a copy of an existing RtfHeaderFooter. * For internal use only. * * @param doc The RtfDocument this RtfHeaderFooter belongs to * @param headerFooter The RtfHeaderFooter to copy * @param displayAt The display location of this RtfHeaderFooter */ protected internal RtfHeaderFooter(RtfDocument doc, RtfHeaderFooter headerFooter, int displayAt) : base(new Phrase(""), false) { this.document = doc; this.content = headerFooter.GetContent(); this.displayAt = displayAt; for (int i = 0; i < this.content.Length; i++) { if (this.content[i] is IElement) { try { this.content[i] = this.document.GetMapper().MapElement((IElement) this.content[i])[0]; } catch (DocumentException) { } } if (this.content[i] is IRtfBasicElement) { ((IRtfBasicElement) this.content[i]).SetInHeader(true); } } }
/** * Set a HeaderFooter to be displayed at a certain position * * @param headerFooter The HeaderFooter to set * @param displayAt The display location to use */ public void SetHeaderFooter(HeaderFooter headerFooter, int displayAt) { this.mode = MODE_MULTIPLE; switch (displayAt) { case RtfHeaderFooter.DISPLAY_ALL_PAGES: headerAll = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt); break; case RtfHeaderFooter.DISPLAY_FIRST_PAGE: headerFirst = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt); break; case RtfHeaderFooter.DISPLAY_LEFT_PAGES: headerLeft = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt); break; case RtfHeaderFooter.DISPLAY_RIGHT_PAGES: headerRight = new RtfHeaderFooter(this.document, headerFooter, this.type, displayAt); break; } }
/** * Set a RtfHeaderFooter to be displayed at a certain position * * @param headerFooter The RtfHeaderFooter to display * @param displayAt The display location to use */ public void SetHeaderFooter(RtfHeaderFooter headerFooter, int displayAt) { this.mode = MODE_MULTIPLE; headerFooter.SetRtfDocument(this.document); headerFooter.SetType(this.type); headerFooter.SetDisplayAt(displayAt); switch (displayAt) { case RtfHeaderFooter.DISPLAY_ALL_PAGES: headerAll = headerFooter; break; case RtfHeaderFooter.DISPLAY_FIRST_PAGE: headerFirst = headerFooter; break; case RtfHeaderFooter.DISPLAY_LEFT_PAGES: headerLeft = headerFooter; break; case RtfHeaderFooter.DISPLAY_RIGHT_PAGES: headerRight = headerFooter; break; } }
/** * Set that this RtfHeaderFooterGroup should have a title page. If only * a header / footer for all pages exists, then it will be copied to the * first page aswell. */ public void SetHasTitlePage() { if (this.mode == MODE_SINGLE) { this.mode = MODE_MULTIPLE; headerFirst = new RtfHeaderFooter(this.document, headerAll, RtfHeaderFooter.DISPLAY_FIRST_PAGE); headerFirst.SetType(this.type); } }
/** * Set that this RtfHeaderFooterGroup should have facing pages. If only * a header / footer for all pages exists, then it will be copied to the left * and right pages aswell. */ public void SetHasFacingPages() { if (this.mode == MODE_SINGLE) { this.mode = MODE_MULTIPLE; this.headerLeft = new RtfHeaderFooter(this.document, this.headerAll, RtfHeaderFooter.DISPLAY_LEFT_PAGES); this.headerLeft.SetType(this.type); this.headerRight = new RtfHeaderFooter(this.document, this.headerAll, RtfHeaderFooter.DISPLAY_RIGHT_PAGES); this.headerRight.SetType(this.type); this.headerAll = null; } else if (this.mode == MODE_MULTIPLE) { if (this.headerLeft == null && this.headerAll != null) { this.headerLeft = new RtfHeaderFooter(this.document, this.headerAll, RtfHeaderFooter.DISPLAY_LEFT_PAGES); this.headerLeft.SetType(this.type); } if (this.headerRight == null && this.headerAll != null) { this.headerRight = new RtfHeaderFooter(this.document, this.headerAll, RtfHeaderFooter.DISPLAY_RIGHT_PAGES); this.headerRight.SetType(this.type); } this.headerAll = null; } }
/** * Constructs a RtfHeaderGroup for a certain HeaderFooter * * @param doc The RtfDocument this RtfHeaderFooter belongs to * @param headerFooter The HeaderFooter to display * @param type The typ of RtfHeaderFooterGroup to create */ public RtfHeaderFooterGroup(RtfDocument doc, HeaderFooter headerFooter, int type) : base(new Phrase(""), false) { this.document = doc; this.type = type; this.mode = MODE_SINGLE; headerAll = new RtfHeaderFooter(doc, headerFooter, type, RtfHeaderFooter.DISPLAY_ALL_PAGES); headerAll.SetType(this.type); }
/** * Constructs a RtfHeaderFooterGroup by copying the content of the original * RtfHeaderFooterGroup * * @param doc The RtfDocument this RtfHeaderFooter belongs to * @param headerFooter The RtfHeaderFooterGroup to copy * @param type The type of RtfHeaderFooterGroup to create */ public RtfHeaderFooterGroup(RtfDocument doc, RtfHeaderFooterGroup headerFooter, int type) : base(new Phrase(""), false) { this.document = doc; this.mode = headerFooter.GetMode(); this.type = type; if (headerFooter.GetHeaderAll() != null) { this.headerAll = new RtfHeaderFooter(this.document, headerFooter.GetHeaderAll(), RtfHeaderFooter.DISPLAY_ALL_PAGES); } if (headerFooter.GetHeaderFirst() != null) { this.headerFirst = new RtfHeaderFooter(this.document, headerFooter.GetHeaderFirst(), RtfHeaderFooter.DISPLAY_FIRST_PAGE); } if (headerFooter.GetHeaderLeft() != null) { this.headerLeft = new RtfHeaderFooter(this.document, headerFooter.GetHeaderLeft(), RtfHeaderFooter.DISPLAY_LEFT_PAGES); } if (headerFooter.GetHeaderRight() != null) { this.headerRight = new RtfHeaderFooter(this.document, headerFooter.GetHeaderRight(), RtfHeaderFooter.DISPLAY_RIGHT_PAGES); } SetType(this.type); }