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(); }
public void Verify_PDF_To_RTF_File_CanBeCreated() { var rtfFilePath = Path.Combine(TestUtils.GetOutputFolder(), $"{nameof(Verify_PDF_To_RTF_File_CanBeCreated)}.rtf"); var document = new Document(); var fileStream = new FileStream(rtfFilePath, FileMode.Create); RtfWriter2.GetInstance(document, fileStream); document.AddAuthor(TestUtils.Author); document.Open(); var font = FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD); var parTitle = new Paragraph("This is a new document", font); document.Add(parTitle); document.Close(); fileStream.Dispose(); }
//public void PDModel2Html(PDModel m) //{ // Export(m, ExportTyep.HTML); //} private void Export(IList <PDTable> tableList, string title, ExportTyep exportType) { Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20); DocWriter w; switch (exportType) { case ExportTyep.PDF: w = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; case ExportTyep.RTF: w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; case ExportTyep.HTML: w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; default: break; } doc.Open(); doc.NewPage(); //IList<PDTable> tableList = m.AllTableList; //Chapter cpt = new Chapter(m.Name, 1); Chapter cpt = new Chapter(title, 1); Section sec; //doc.AddTitle(m.Name); doc.AddTitle(title); doc.AddAuthor("Kalman"); doc.AddCreationDate(); doc.AddCreator("Kalman"); doc.AddSubject("PDM数据库文档"); foreach (PDTable table in tableList) { sec = cpt.AddSection(new Paragraph(string.Format("{0}[{1}]", table.Name, table.Code), font)); if (string.IsNullOrEmpty(table.Comment) == false) { Chunk chunk = new Chunk(table.Comment, font); sec.Add(chunk); } t = new Table(9, table.ColumnList.Count); //t.Border = 15; //t.BorderColor = Color.BLACK; //t.BorderWidth = 1.0f; t.AutoFillEmptyCells = true; t.CellsFitPage = true; t.TableFitsPage = true; t.Cellpadding = 3; //if (exportType == ExportTyep.PDF) t.Cellspacing = 2; t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE; t.SetWidths(new int[] { 200, 200, 150, 50, 50, 50, 50, 50, 300 }); t.AddCell(BuildHeaderCell("名称")); t.AddCell(BuildHeaderCell("代码")); t.AddCell(BuildHeaderCell("数据类型")); t.AddCell(BuildHeaderCell("长度")); t.AddCell(BuildHeaderCell("精度")); t.AddCell(BuildHeaderCell("主键")); t.AddCell(BuildHeaderCell("外键")); t.AddCell(BuildHeaderCell("可空")); t.AddCell(BuildHeaderCell("注释")); foreach (PDColumn column in table.ColumnList) { t.AddCell(BuildCell(column.Name)); t.AddCell(BuildCell(column.Code)); t.AddCell(BuildCell(column.DataType)); t.AddCell(BuildCell(column.Length == 0 ? "" : column.Length.ToString())); t.AddCell(BuildCell(column.Precision == 0 ? "" : column.Precision.ToString())); t.AddCell(BuildCell(column.IsPK ? " √" : "")); t.AddCell(BuildCell(column.IsFK ? " √" : "")); t.AddCell(BuildCell(column.Mandatory ? "" : " √")); t.AddCell(BuildCell(column.Comment)); } sec.Add(t); } doc.Add(cpt); doc.Close(); }
private List <SOTable> Export(DbSchema schema, SODatabase db, List <SOTable> tableList, ExportTyep exportType) { if (schema == null) { throw new ArgumentException("参数schema不能为空", "schema"); } if (db == null) { throw new ArgumentException("参数dbName不能为空", "dbName"); } Document doc = new Document(PageSize.A4.Rotate(), 20, 20, 20, 20); DocWriter w; switch (exportType) { case ExportTyep.PDF: w = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; case ExportTyep.RTF: w = RtfWriter2.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; case ExportTyep.HTML: w = HtmlWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create, FileAccess.Write)); break; default: break; } doc.Open(); doc.NewPage(); if (tableList == null) { tableList = schema.GetTableList(db); } Chapter cpt = new Chapter(db.Name, 1); Section sec; #region if (exportType != ExportTyep.HTML) { doc.AddTitle(db.Name); doc.AddAuthor("Kalman"); doc.AddCreationDate(); doc.AddCreator("Kalman"); doc.AddSubject("数据库文档"); } foreach (SOTable table in tableList) { sec = cpt.AddSection(new Paragraph(table.Name, font)); if (string.IsNullOrEmpty(table.Comment) == false) { Chunk chunk = new Chunk(table.Comment, font); sec.Add(chunk); } List <SOColumn> columnList = schema.GetTableColumnList(table); t = new Table(7, columnList.Count); t.AutoFillEmptyCells = true; t.CellsFitPage = true; t.TableFitsPage = true; t.Cellpadding = 3; //if (exportType == ExportTyep.PDF) t.Cellspacing = 2; t.DefaultVerticalAlignment = Element.ALIGN_MIDDLE; t.SetWidths(new int[] { 200, 150, 50, 50, 50, 100, 300 }); t.AddCell(BuildHeaderCell("名称")); t.AddCell(BuildHeaderCell("数据类型")); t.AddCell(BuildHeaderCell("主键")); t.AddCell(BuildHeaderCell("标志")); t.AddCell(BuildHeaderCell("可空")); t.AddCell(BuildHeaderCell("默认值")); t.AddCell(BuildHeaderCell("注释")); foreach (SOColumn column in columnList) { t.AddCell(BuildCell(column.Name)); t.AddCell(BuildCell(GetDbColumnType(column))); t.AddCell(BuildCell(column.PrimaryKey ? " √" : "")); t.AddCell(BuildCell(column.Identify ? " √" : "")); t.AddCell(BuildCell(column.Nullable ? " √" : "")); t.AddCell(BuildCell(column.DefaultValue == null ? "" : column.DefaultValue.ToString())); t.AddCell(BuildCell(column.Comment)); } sec.Add(t); } doc.Add(cpt); doc.Close(); #endregion return(tableList); }