/// <summary> /// Gets the RTF document content base list. /// </summary> /// <param name="rtfHtmlNodeList">The RTF HTML node list.</param> /// <returns></returns> private static RtfDocumentContentBase[] GetRtfDocumentContents(List <RtfHtmlNode> rtfHtmlNodeList) { RtfDocumentContentBase[] rtfDocumentContents = new RtfDocumentContentBase[rtfHtmlNodeList.Count]; for (int nodeCount = 0; nodeCount < rtfHtmlNodeList.Count; nodeCount++) { RtfHtmlNode rtfHtmlNode = rtfHtmlNodeList[nodeCount]; RtfParagraphFormat rtfParagraphFormat = new RtfParagraphFormat(FontSize, string.IsNullOrEmpty(rtfHtmlNode.RtfParagraphFormat) ? RtfTextAlign.Justified : GetRtfTextAlign(rtfHtmlNode.RtfParagraphFormat)); RtfFormattedParagraph rtfFormattedParagraph = new RtfFormattedParagraph(rtfParagraphFormat); foreach (var rtfHtmlItem in rtfHtmlNode.RtfHtmlItem) { //Add text in paragraph if (!string.IsNullOrEmpty(rtfHtmlItem.HtmlText)) { rtfFormattedParagraph.AppendText(new RtfFormattedText(rtfHtmlItem.HtmlText, rtfHtmlItem.RtfFormattedText)); } //Add image in paragraph if (rtfHtmlItem.HtmlImage != null) { RtfImage rtfImage = new RtfImage(rtfHtmlItem.HtmlImage, RtfImageFormat.Wmf, rtfHtmlItem.ImageHeight, rtfHtmlItem.ImageWidth); rtfFormattedParagraph.AppendText(rtfImage); } } rtfFormattedParagraph.Formatting.SpaceAfter = TwipConverter.ToTwip(10F, MetricUnit.Point); rtfDocumentContents[nodeCount] = rtfFormattedParagraph; } return(rtfDocumentContents); }
public void StartNewParagraph(int fontIndex, float fontSize, RtfTextAlign alignment, int colorIndex, float spaceAfterPoints) { CloseCurrentParagraph(); RtfParagraphFormatting formatting = new RtfParagraphFormatting(fontSize, alignment); m_currParagraph = new RtfFormattedParagraph(formatting); m_currParagraph.Formatting.FontIndex = fontIndex; m_currParagraph.Formatting.TextColorIndex = colorIndex; m_currParagraph.Formatting.SpaceAfter = TwipConverter.ToTwip(spaceAfterPoints, MetricUnit.Point); }
/// <summary> /// Initializes a new instance of ESCommon.Rtf.RtfTableCell class. /// </summary> /// <param name="width">Cell width in centimeters.</param> public RtfTableCell(float width) { Initialize(); _definition.Width = TwipConverter.ToTwip(width, MetricUnit.Centimeter); }
/// <summary> /// Initializes a new instance of ESCommon.Rtf.RtfTableCell class. /// </summary> /// <param name="width">Cell width in centimeters.</param> /// <param name="text">Text displayed in the cell.</param> /// <param name="style">Style applied to the cell.</param> public RtfTableCell(float width, RtfParagraphContentBase text, RtfTableCellStyle style) : base(text, style.DefaultParagraphFormatting) { Initialize(style); _definition.Width = TwipConverter.ToTwip(width, MetricUnit.Centimeter); }
/// <summary> /// Initializes a new instance of ESCommon.Rtf.RtfTableCell class. /// </summary> /// <param name="width">Cell width in centimeters.</param> /// <param name="text">Text displayed in the cell.</param> public RtfTableCell(float width, RtfParagraphContentBase text) : base(text) { Initialize(); _definition.Width = TwipConverter.ToTwip(width, MetricUnit.Centimeter); }
/// <summary> /// Initializes a new instance of ESCommon.Rtf.RtfTableColumn class. /// </summary> /// <param name="width">Width in centimeters.</param> /// <param name="style">Default cell style.</param> public RtfTableColumn(float width, RtfTableCellStyle style) { Width = TwipConverter.ToTwip(width, MetricUnit.Centimeter); DefaultCellStyle = style; }
/// <summary> /// Initializes a new instance of ESCommon.Rtf.RtfTableColumn class. /// </summary> /// <param name="width">Width in centimeters.</param> public RtfTableColumn(float width) { Width = TwipConverter.ToTwip(width, MetricUnit.Centimeter); }
public Report() { rtf = new RtfDocument(); rtf.FontTable.Add(new RtfFont("Calibri")); rtf.FontTable.Add(new RtfFont("Constantia")); rtf.ColorTable.AddRange(new RtfColor[] { new RtfColor(Color.Red), new RtfColor(0, 0, 255) }); RtfParagraphFormatting LeftAligned12 = new RtfParagraphFormatting(12, RtfTextAlign.Left); RtfParagraphFormatting Centered10 = new RtfParagraphFormatting(10, RtfTextAlign.Center); RtfFormattedParagraph header = new RtfFormattedParagraph(new RtfParagraphFormatting(16, RtfTextAlign.Center)); RtfFormattedParagraph p1 = new RtfFormattedParagraph(new RtfParagraphFormatting(12, RtfTextAlign.Left)); RtfTable t = new RtfTable(RtfTableAlign.Center, 2, 3); header.Formatting.SpaceAfter = TwipConverter.ToTwip(12F, MetricUnit.Point); header.AppendText("Calibri "); header.AppendText(new RtfFormattedText("Bold", RtfCharacterFormatting.Bold)); t.Width = TwipConverter.ToTwip(5, MetricUnit.Centimeter); t.Columns[1].Width = TwipConverter.ToTwip(2, MetricUnit.Centimeter); foreach (RtfTableRow row in t.Rows) { row.Height = TwipConverter.ToTwip(2, MetricUnit.Centimeter); } t.MergeCellsVertically(1, 0, 2); t.DefaultCellStyle = new RtfTableCellStyle(RtfBorderSetting.None, Centered10); t[0, 0].Definition.Style = new RtfTableCellStyle(RtfBorderSetting.None, LeftAligned12, RtfTableCellVerticalAlign.Bottom); t[0, 0].AppendText("Bottom"); t[1, 0].Definition.Style = new RtfTableCellStyle(RtfBorderSetting.Left, Centered10, RtfTableCellVerticalAlign.Center, RtfTableCellTextFlow.BottomToTopLeftToRight); t[1, 1].Definition.Style = t[1, 0].Definition.Style; t[1, 0].AppendText("Vertical"); t[0, 1].Formatting = new RtfParagraphFormatting(10, RtfTextAlign.Center); t[0, 1].Formatting.TextColorIndex = 1; t[0, 1].AppendText(new RtfFormattedText("Black ", 0)); t[0, 1].AppendText("Red "); t[0, 1].AppendText(new RtfFormattedText("Blue", 2)); t[0, 2].AppendText("Normal"); t[1, 2].AppendText(new RtfFormattedText("Italic", RtfCharacterFormatting.Caps | RtfCharacterFormatting.Italic)); t[1, 2].AppendParagraph("+"); t[1, 2].AppendParagraph(new RtfFormattedText("Caps", RtfCharacterFormatting.Caps | RtfCharacterFormatting.Italic)); p1.Formatting.FontIndex = 1; p1.Formatting.IndentLeft = TwipConverter.ToTwip(6.05F, MetricUnit.Centimeter); p1.Formatting.SpaceBefore = TwipConverter.ToTwip(6F, MetricUnit.Point); p1.AppendText("Constantia "); p1.AppendText(new RtfFormattedText("Superscript", RtfCharacterFormatting.Superscript)); p1.AppendParagraph(new RtfFormattedText("Inline", -1, 8)); p1.AppendText(new RtfFormattedText(" font size ", -1, 14)); p1.AppendText(new RtfFormattedText("change", -1, 8)); RtfImage picture = new RtfImage(Properties.Resources.lemon, RtfImageFormat.Wmf); picture.ScaleX = 50; picture.ScaleY = 50; p1.AppendParagraph(picture); RtfFormattedText linkText = new RtfFormattedText("View article", RtfCharacterFormatting.Underline, 2); linkText.BackgroundColorIndex = 1; p1.AppendParagraph(new RtfHyperlink("http://www.codeproject.com/KB/cs/RtfConstructor.aspx", linkText)); RtfFormattedParagraph p2 = new RtfFormattedParagraph(); p2.Formatting = new RtfParagraphFormatting(10); p2.Tabs.Add(new RtfTab(TwipConverter.ToTwip(2.5F, MetricUnit.Centimeter), RtfTabKind.Decimal)); p2.Tabs.Add(new RtfTab(TwipConverter.ToTwip(5F, MetricUnit.Centimeter), RtfTabKind.FlushRight, RtfTabLead.Dots)); p2.Tabs.Add(new RtfTab(TwipConverter.ToTwip(7.5F, MetricUnit.Centimeter))); p2.Tabs.Add(new RtfTab(TwipConverter.ToTwip(10F, MetricUnit.Centimeter), RtfTabKind.Centered)); p2.Tabs.Add(new RtfTab(TwipConverter.ToTwip(15F, MetricUnit.Centimeter), RtfTabLead.Hyphens)); p2.Tabs[2].Bar = true; p2.AppendText("One"); p2.AppendText(new RtfTabCharacter()); p2.AppendText("Two"); p2.AppendText(new RtfTabCharacter()); p2.AppendText("Three"); p2.AppendText(new RtfTabCharacter()); p2.AppendText("Five"); p2.AppendText(new RtfTabCharacter()); p2.AppendText("Six"); rtf.Contents.AddRange(new RtfDocumentContentBase[] { header, t, p1, p2, }); }
public void GetPageRtf(int departmentId) { HttpRequest request = _context.Request; Filter filters = new Filter(); filters.Rules = new List <Rule>(); string[] fields = { "CreationDate", "CreationDateStart", "CreationDateEnd", "Number", "ExternalNumber", "DocumentCodeID", "Content", "OrganizationName", "InnerNumber", "Controlled", "EndDateFrom", "EndDateTo", "IsInput", "IsDepartmentOwner", "ControlledInner", "InnerEndDateFrom", "InnerEndDateTo", "LableID", "DocStatusID" }; foreach (var f in fields) { string data = request[f]; if (!String.IsNullOrWhiteSpace(data)) { filters.AddRule(new Rule { Field = f, Data = data, Op = "cn" }); } } PageSettings gridSettings = new PageSettings { IsSearch = bool.Parse(request["_search"] ?? "false"), PageIndex = int.Parse(request["page"] ?? "1"), PageSize = int.Parse(request["rows"] ?? "50"), SortColumn = request["sidx"] ?? "", SortOrder = request["sord"] ?? "asc", Where = filters }; DataTable dtPage = AdminDocumets.GetPage(gridSettings, UserId, departmentId); JqGridResults jqGridResults = AdminDocumets.BuildJqGridResults(dtPage, gridSettings); _context.Response.Clear(); RtfDocument rtf = new RtfDocument(); rtf.FontTable.Add(new RtfFont("Times New Roman")); RtfFormattedParagraph header = new RtfFormattedParagraph(new RtfParagraphFormatting(14, RtfTextAlign.Center)); header.AppendText(""); header.AppendParagraph(); RtfTable tbl = new RtfTable(RtfTableAlign.Center, 8, dtPage.Rows.Count + 1); tbl.Width = TwipConverter.ToTwip(489, MetricUnit.Point); tbl.DefaultCellStyle = new RtfTableCellStyle(RtfBorderSetting.All, new RtfParagraphFormatting(12, RtfTextAlign.Center)); tbl.Columns[0].Width = TwipConverter.ToTwip(14, MetricUnit.Point); tbl.Columns[1].Width = TwipConverter.ToTwip(60, MetricUnit.Point); tbl.Columns[2].Width = TwipConverter.ToTwip(30, MetricUnit.Point); tbl.Columns[3].Width = TwipConverter.ToTwip(30, MetricUnit.Point); tbl.Columns[4].Width = TwipConverter.ToTwip(30, MetricUnit.Point); tbl.Columns[5].Width = TwipConverter.ToTwip(70, MetricUnit.Point); tbl.Columns[5].DefaultCellStyle = new RtfTableCellStyle(RtfBorderSetting.All, new RtfParagraphFormatting(12, RtfTextAlign.Left)); tbl.Columns[6].Width = TwipConverter.ToTwip(85, MetricUnit.Point); tbl.Columns[6].DefaultCellStyle = new RtfTableCellStyle(RtfBorderSetting.All, new RtfParagraphFormatting(12, RtfTextAlign.Left)); tbl.Columns[7].Width = TwipConverter.ToTwip(170, MetricUnit.Point); tbl.Columns[7].DefaultCellStyle = new RtfTableCellStyle(RtfBorderSetting.All, new RtfParagraphFormatting(10, RtfTextAlign.Left)); foreach (RtfTableRow row in tbl.Rows) { row.Height = TwipConverter.ToTwip(20, MetricUnit.Point); } tbl.Rows[0].Height = TwipConverter.ToTwip(30, MetricUnit.Point); //tbl.Rows[0].Cells[5].Formatting = new RtfParagraphFormatting(12, RtfTextAlign.Center); tbl[0, 0].AppendText(""); tbl[1, 0].AppendText("Дата створення"); tbl[2, 0].AppendText("Шифр"); tbl[3, 0].AppendText("№"); tbl[4, 0].AppendText("№ внутрішній"); tbl[5, 0].AppendText("№ в організації"); tbl[6, 0].AppendText("Організація"); tbl[7, 0].AppendText("Зміст"); int numRow = 1; foreach (JqGridRow dr in jqGridResults.rows) { tbl[0, numRow].AppendText(numRow.ToString()); tbl[1, numRow].AppendText(dr.cell[2]); tbl[2, numRow].AppendText(dr.cell[16]); tbl[3, numRow].AppendText(dr.cell[3]); tbl[4, numRow].AppendText(dr.cell[23]); tbl[5, numRow].AppendText(dr.cell[4]); tbl[6, numRow].AppendText(dr.cell[19]); tbl[7, numRow].AppendText(dr.cell[5]); numRow++; } RtfFormattedParagraph footer = new RtfFormattedParagraph(new RtfParagraphFormatting(14, RtfTextAlign.Left)); footer.AppendParagraph(); footer.AppendText(String.Format("Список станом на ")); footer.AppendParagraph(); footer.AppendText(String.Format("Всього документів: {0}", dtPage.Rows.Count)); footer.AppendParagraph(); footer.AppendText("Виконав ______________________"); rtf.Contents.AddRange(new RtfDocumentContentBase[] { header, tbl, footer }); RtfWriter rtfWriter = new RtfWriter(); StringBuilder sb = new StringBuilder(); using (TextWriter writer = new StringWriter(sb)) { rtfWriter.Write(writer, rtf); } string fileName = String.Format("docTempates_({0}).rtf", DateTime.Now.ToString("yyyy.MM.dd")); _context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); _context.Response.ContentType = "application/rtf"; _context.Response.Write(sb.ToString()); }
/// <summary> /// Sets the properties of the current border. /// </summary> /// <param name="width">Width in points.</param> /// <param name="style">Border style.</param> /// <param name="colorIndex">Index of entry in the color table.</param> public void SetProperties(float width, RtfBorderStyle style, int colorIndex) { Width = TwipConverter.ToTwip(width, MetricUnit.Point); Style = style; ColorIndex = colorIndex; }