protected override HtmlItem renderingHtmltr(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent) { Htmltr tr = it as Htmltr; MigraDoc.DocumentObjectModel.Tables.Row rw = null; if (tr != null) { HtmlTable tb = parent as HtmlTable; if (tb != null) { MigraDoc.DocumentObjectModel.Tables.Table tt = renderparent as MigraDoc.DocumentObjectModel.Tables.Table; if (tt != null) { if (tt.Columns.Count > 0) rw = tt.AddRow(); tr.SetTableParent(tb); } } foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); RenderStyle.CreateRenderStyle(it, ref ff).Render(); HtmlItem itemrendered = renderingit(t, ref par, it, rw); } } return tr; }
protected override HtmlItem renderingHtmlLi(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlLi l = it as HtmlLi; if (l != null) { foreach (HtmlItem i in it.ListItem) { FormattedText ff = new FormattedText(); HtmlItem itemrendered = renderingit(i, ref par, l, null); HtmlText textitem = itemrendered as HtmlText; //RenderStyle.CreateRenderStyle(it, ref ff).Render(); if (textitem != null) { ff.Add(new Text(textitem.Text)); par.Add(ff); it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size); if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size); } } } return l; }
protected override HtmlItem renderingHtmlDiv(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlDiv div = it as HtmlDiv; if (div != null) { foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); RenderStyle.CreateRenderStyle(it, ref ff).Render(); //Render styles element HtmlItem itemrendered = renderingit(t, ref par, it, null); HtmlText textitem = itemrendered as HtmlText; if (textitem != null) { ff.Add(new Text(textitem.Text)); it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size); if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size); } par.Add(ff); } par.AddLineBreak(); } return div; }
private void addServiceToWaterMark(Paragraph lineOne, string serviceText, Boolean includeSeparator) { MigraDoc.DocumentObjectModel.FormattedText serviceFormatted = lineOne.AddFormattedText(serviceText); serviceFormatted.Font.Size = 11; serviceFormatted.Font.Name = "Impact"; serviceFormatted.Font.Bold = true; serviceFormatted.Color = mttPurple; if (includeSeparator) { MigraDoc.DocumentObjectModel.FormattedText lineSeparator = lineOne.AddFormattedText(" | "); lineSeparator.Font.Size = 10; lineSeparator.Color = separatorGrey; } }
internal override void VisitFormattedText(FormattedText formattedText) { Document document = formattedText.Document; ParagraphFormat format = null; Style style = document.styles[formattedText.style.Value]; if (style != null) format = style.paragraphFormat; else if (formattedText.style.Value != "") format = document.styles["InvalidStyleName"].paragraphFormat; if (format != null) { if (formattedText.font == null) formattedText.Font = format.font.Clone(); else if (format.font != null) FlattenFont(formattedText.font, format.font); } }
/// <summary> /// Renders <paramref name="control"/> to the <paramref name="document"/>. /// </summary> /// <param name="document">The PDF document.</param> /// <param name="control">The control to be rendered.</param> /// <param name="level">The depth down the control tree being rendered (affects indenting).</param> /// <param name="controlList">The complete control list.</param> protected override void DoRender(Document document, Control control, int level, ControlList controlList) { IControlWithOptions controlWithOptions = control as IControlWithOptions; string suffix = string.Format(" {0}", controlWithOptions.AllowMultipleSelect ? PdfResources.SelectAll : PdfResources.SelectOne); FormattedText formattedSuffix = new FormattedText { Style = StyleNames.Normal, Italic = true }; formattedSuffix.AddText(suffix); this.Label.Add(formattedSuffix); foreach (var option in controlWithOptions.OptionValues ?? new ControlValueOptionList()) { Paragraph paragraph = document.LastSection.AddParagraph(); FormattedText checkboxText = this.CreateEmptyCheckbox(document.Styles[StyleNames.Normal]); paragraph.Format.LeftIndent = new Unit(PdfConstants.IndentMultiplier * level, UnitType.Millimeter); paragraph.Add(checkboxText); paragraph.AddText(option.Description); } }
/// <summary> /// Renders <paramref name="control"/> to the <paramref name="document"/>. /// </summary> /// <param name="document">The PDF document.</param> /// <param name="control">The control to be rendered.</param> /// <param name="level">The depth down the control tree being rendered (affects indenting).</param> /// <param name="controlList">The complete control list.</param> protected override void DoRender(Document document, Control control, int level, ControlList controlList) { IControlWithOptions controlWithOptions = control as IControlWithOptions; string suffix = string.Format(" {0}", controlWithOptions.AllowMultipleSelect ? PdfResources.IndicateAll : PdfResources.IndicateOne); FormattedText formattedSuffix = new FormattedText { Style = StyleNames.Normal, Italic = true }; formattedSuffix.AddText(suffix); this.Label.Add(formattedSuffix); RepeaterOptionSource optionSource = controlWithOptions.OptionSource as RepeaterOptionSource; RepeaterControl repeater = controlList.FindRecursive<RepeaterControl>(optionSource.RepeaterName); ControlList valueList = new ControlList(); valueList.AddRange(optionSource.ValueFields.Select(valueField => repeater.Controls.FindRecursive<Control>(valueField))); for (int i = 1; i <= (repeater.MaximumCount ?? PdfConstants.DefaultRepeaterLength); i++) { this.ListRenderer.Render(valueList, this.Factory, level, controlList); } }
protected override HtmlItem renderingHtmlContent(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlContent content = it as HtmlContent; if (content != null) { if (parent is HtmlContent) par.AddLineBreak(); foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); if (content.Bold.hasValue()) ff.Bold = content.Bold.Value; if (content.Size.hasValue()) ff.Size = content.Size.Value; RenderStyle.CreateRenderStyle(it, ref ff).Render(); HtmlItem itemrendered = renderingit(t, ref par, it, null); HtmlText textitem = itemrendered as HtmlText; if (textitem != null) { ff.Add(new Text(textitem.Text)); par.Add(ff); it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size); //ff.Section.PageSetup.PageWidth=59 =>>210 mm A4 if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size); } } par.AddLineBreak(); } return content; }
protected override HtmlItem renderingHtmlSpan(HtmlItem it, ref Paragraph par, HtmlItem parent) { HtmlSpan span = it as HtmlSpan; if (span != null) { foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); if (span.Size.hasValue()) ff.Size = span.Size.Value; if (span.Bold.hasValue()) ff.Bold = span.Bold.Value; if (span.Sub.hasValue()) ff.Subscript = span.Sub.Value; if (span.Super.hasValue()) ff.Superscript = span.Super.Value; RenderStyle.CreateRenderStyle(it, ref ff).Render(); // render styles element HtmlItem itemrendered = renderingit(t, ref par, it, null); HtmlText textitem = itemrendered as HtmlText; if (textitem != null) { ff.Add(new Text(textitem.Text)); it.SizeRenderItem.Width = calculateWithText(textitem.Text.Length, ff.Size); if (it.SizeRenderItem.Width > 210) it.SizeRenderItem.Width = 210; it.SizeRenderItem.Height = calculateHeightText(textitem.Text.Length, ff.Size); } par.Add(ff); } } return span; }
/// <summary> /// Adds a new FormattedText with the given Font. /// </summary> public FormattedText AddFormattedText(Font font) { FormattedText formattedText = new FormattedText(); formattedText.Font.ApplyFont(font); this.Add(formattedText); return formattedText; }
/// <summary> /// Adds a new FormattedText. /// </summary> public FormattedText AddFormattedText() { FormattedText formattedText = new FormattedText(); this.Add(formattedText); return formattedText; }
/// <summary> /// Adds a new FormattedText /// </summary> public void Add(FormattedText formattedText) { Elements.Add(formattedText); }
protected override HtmlItem renderingHtmlTable(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent) { HtmlTable tbl = it as HtmlTable; MigraDoc.DocumentObjectModel.Shapes.TextFrame tf = null; Paragraph partf = null; if (tbl != null) { MigraDoc.DocumentObjectModel.Tables.Table tt = null; MigraDoc.DocumentObjectModel.Tables.Cell cellparent = renderparent as MigraDoc.DocumentObjectModel.Tables.Cell; if (cellparent != null) { tf = cellparent.AddTextFrame(); tt = tf.AddTable(); partf = tf.AddParagraph(); } else tt = par.Section.AddTable(); tbl.SizeRenderItem.Width = 0; for (int i = 0; i < tbl.Cells; i++) { MigraDoc.DocumentObjectModel.Tables.Column cc = tt.AddColumn(); } foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); RenderStyle.CreateRenderStyle(it, ref ff).Render(); if (partf != null) renderingit(t, ref partf, it, tt); else renderingit(t, ref par, it, tt); } RenderStyle.CreateRenderStyle(it, ref tt).Render(); } return tbl; }
public static RenderStyle CreateRenderStyle(HtmlItem it, ref FormattedText frmt) { return new RenderStyleFormattedText(it, ref frmt); }
protected RenderStyle(HtmlItem it, ref FormattedText frmt) { }
/// <summary> /// Adds a new FormattedText /// </summary> public void Add(FormattedText formattedText) { this.Elements.Add(formattedText); }
public void VisitRun(Run element) { var runText = element.InnerText; _pdfText = _pdfParagraph.AddFormattedText(GetTextFragment(runText)); }
/// <summary> /// Adds a new FormattedText with the given text. /// </summary> public FormattedText AddFormattedText(string text) { FormattedText formattedText = new FormattedText(); formattedText.AddText(text); this.Add(formattedText); return formattedText; }
internal FormattedTextRenderer(DocumentObject domObj, RtfDocumentRenderer docRenderer) : base(domObj, docRenderer) { this.formattedText = domObj as FormattedText; }
protected override HtmlItem renderingHtmltd(HtmlItem it, ref Paragraph par, HtmlItem parent, DocumentObject renderparent) { MigraDoc.DocumentObjectModel.Tables.Row rw = renderparent as MigraDoc.DocumentObjectModel.Tables.Row; Htmltd tb = it as Htmltd; if (tb != null) { if (rw != null) { Htmltr tr = parent as Htmltr; if (tr != null)// properties of tr { tb.SetTrParent(tr); HtmlTable tbl = tr.GetTableParent(); if (tbl != null)// properties of table { tr.SetTableParent(tbl); } } //add paragraph to the cell Paragraph paragrcell = rw[tb.IndexCell].AddParagraph(); //render style cell content // RenderStyle.CreateRenderStyle(it, ref paragrcell).Render(); MigraDoc.DocumentObjectModel.Tables.Cell cc = rw[tb.IndexCell]; RenderStyle.CreateRenderStyle(it, ref cc).Render(); //reder elements in cell decimal minWidthCell = 0; decimal minWidthCellpar = 0; decimal minHeightCell = 0; decimal minHeightCellpar = 0; foreach (HtmlItem t in it.ListItem) { FormattedText ff = new FormattedText(); RenderStyle.CreateRenderStyle(it, ref ff).Render(); if (rw.Table.Columns.Count > tb.IndexCell) { renderingit(t, ref paragrcell, null, rw[tb.IndexCell]); Iheight hh = t as Iheight; if (hh != null) { if (minWidthCell < minWidthCellpar) minWidthCell = minWidthCellpar; if (minHeightCell < minHeightCellpar) minHeightCell = minHeightCellpar; minWidthCellpar = 0; } if (t.StyleItem != null)// width of style if (t.StyleItem.Width != null) if (t.StyleItem.Width.Measure.HasValue) if (t.StyleItem.Width.Measure.Value > t.SizeRenderItem.Width) t.SizeRenderItem.Width = t.StyleItem.Width.Measure.Value; minWidthCellpar += t.SizeRenderItem.Width; if (t.StyleItem != null)// height of style if (t.StyleItem.Width != null) if (t.StyleItem.High.Measure.HasValue) if (t.StyleItem.High.Measure.Value > t.SizeRenderItem.Height) t.SizeRenderItem.Height = t.StyleItem.High.Measure.Value; minHeightCellpar += t.SizeRenderItem.Height; if (t is HtmlTable) //Always insert a margin Migradoc when table is in a cell minHeightCellpar += 25; } } if (minWidthCellpar > minWidthCell) minWidthCell = minWidthCellpar; if (minHeightCellpar > minHeightCell) minHeightCell = minHeightCellpar; if (rw[tb.IndexCell].Column.Width < (Unit)minWidthCell) { rw[tb.IndexCell].Column.Width = (Unit)minWidthCell; tb.SetWidth(minWidthCell); } if (rw[tb.IndexCell].Row.Height < (Unit)minHeightCell) { rw[tb.IndexCell].Row.Height = (Unit)minHeightCell; tb.SetHeight(minHeightCell); } } } return tb; }
void FillContent(DataTable dt) { // Fill the address in the address text frame. var paragraph = addressFrame.AddParagraph(); paragraph.AddText("Region Skåne Koncern"); paragraph.AddLineBreak(); paragraph.AddText("Malmö..."); paragraph.AddLineBreak(); paragraph.AddText("23651 Sverige"); if (dt != null) { foreach (DataRow row in dt.Rows) { // Each item fills two rows. var row1 = this.table.AddRow(); var row2 = this.table.AddRow(); row1.TopPadding = 1.5; row1.Cells[0].Shading.Color = TableGray; row1.Cells[0].VerticalAlignment = VerticalAlignment.Center; row1.Cells[0].MergeDown = 1; row1.Cells[1].Format.Alignment = ParagraphAlignment.Left; row1.Cells[1].MergeRight = 3; row1.Cells[5].Shading.Color = TableGray; row1.Cells[5].MergeDown = 1; string apa = row["06Benämning 1"].ToString(); Console.WriteLine(apa + row[1].ToString()); row1.Cells[0].AddParagraph(); paragraph = row1.Cells[1].AddParagraph(apa); var formattedText = new FormattedText() { Style = "Title" }; formattedText.AddText(row[1].ToString()); paragraph.Add(formattedText); paragraph.AddFormattedText(" by ", TextFormat.Italic); paragraph.AddText(row[2].ToString()); row2.Cells[1].AddParagraph(apa); row2.Cells[2].AddParagraph(apa + " €"); row2.Cells[4].AddParagraph(); row2.Cells[5].AddParagraph(apa); row1.Cells[5].AddParagraph(row["06Benämning 1"].ToString() + " €"); row1.Cells[5].VerticalAlignment = VerticalAlignment.Bottom; table.SetEdge(0, table.Rows.Count - 2, 6, 2, Edge.Box, BorderStyle.Single, 0.75); // Add an invisible row as a space line to the table. var rows = table.AddRow(); rows.Borders.Visible = false; rows = table.AddRow(); rows.Cells[0].Borders.Visible = false; rows.Cells[0].AddParagraph(row["06Benämning 1"].ToString()); rows.Cells[5].AddParagraph(0.ToString("0.00") + " €"); rows.Cells[0].Format.Font.Bold = true; rows.Cells[0].Format.Alignment = ParagraphAlignment.Right; rows.Cells[0].MergeRight = 4; } } /* // Iterate the invoice items. double totalExtendedPrice = 0; var iter = _navigator.Select("/invoice/items/*"); while (iter.MoveNext()) { item = iter.Current; var quantity = GetValueAsDouble(item, "quantity"); var price = GetValueAsDouble(item, "price"); var discount = GetValueAsDouble(item, "discount"); // Each item fills two rows. var row1 = this.table.AddRow(); var row2 = this.table.AddRow(); row1.TopPadding = 1.5; row1.Cells[0].Shading.Color = TableGray; row1.Cells[0].VerticalAlignment = VerticalAlignment.Center; row1.Cells[0].MergeDown = 1; row1.Cells[1].Format.Alignment = ParagraphAlignment.Left; row1.Cells[1].MergeRight = 3; row1.Cells[5].Shading.Color = TableGray; row1.Cells[5].MergeDown = 1; row1.Cells[0].AddParagraph(GetValue(item, "itemNumber")); paragraph = row1.Cells[1].AddParagraph(); var formattedText = new FormattedText() { Style = "Title" }; formattedText.AddText(GetValue(item, "title")); paragraph.Add(formattedText); paragraph.AddFormattedText(" by ", TextFormat.Italic); paragraph.AddText(GetValue(item, "author")); row2.Cells[1].AddParagraph(GetValue(item, "quantity")); row2.Cells[2].AddParagraph(price.ToString("0.00") + " €"); if (discount > 0) row2.Cells[3].AddParagraph(discount.ToString("0") + '%'); row2.Cells[4].AddParagraph(); row2.Cells[5].AddParagraph(price.ToString("0.00")); var extendedPrice = quantity * price; extendedPrice = extendedPrice * (100 - discount) / 100; row1.Cells[5].AddParagraph(extendedPrice.ToString("0.00") + " €"); row1.Cells[5].VerticalAlignment = VerticalAlignment.Bottom; totalExtendedPrice += extendedPrice; _table.SetEdge(0, _table.Rows.Count - 2, 6, 2, Edge.Box, BorderStyle.Single, 0.75); } // Add an invisible row as a space line to the table. var row = _table.AddRow(); row.Borders.Visible = false; // Add the total price row. row = _table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Total Price"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = 4; row.Cells[5].AddParagraph(totalExtendedPrice.ToString("0.00") + " €"); row.Cells[5].Format.Font.Name = "Segoe UI"; // Add the VAT row. row = _table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("VAT (7%)"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = 4; row.Cells[5].AddParagraph((0.07 * totalExtendedPrice).ToString("0.00") + " €"); // Add the additional fee row. row = _table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Shipping and Handling"); row.Cells[5].AddParagraph(0.ToString("0.00") + " €"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = 4; // Add the total due row. row = _table.AddRow(); row.Cells[0].AddParagraph("Total Due"); row.Cells[0].Borders.Visible = false; row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = 4; totalExtendedPrice += 0.19 * totalExtendedPrice; row.Cells[5].AddParagraph(totalExtendedPrice.ToString("0.00") + " €"); row.Cells[5].Format.Font.Name = "Segoe UI"; row.Cells[5].Format.Font.Bold = true; // Set the borders of the specified cell range. _table.SetEdge(5, _table.Rows.Count - 4, 1, 4, Edge.Box, BorderStyle.Single, 0.75); // Add the notes paragraph. paragraph = _document.LastSection.AddParagraph(); paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Format.SpaceBefore = "1cm"; paragraph.Format.Borders.Width = 0.75; paragraph.Format.Borders.Distance = 3; paragraph.Format.Borders.Color = TableBorder; paragraph.Format.Shading.Color = TableGray; item = SelectItem("/invoice"); paragraph.AddText(GetValue(item, "notes")); } * */ }
public RenderStyleFormattedText(HtmlItem it, ref FormattedText frmt) { Frmt = frmt; It = it; }