///<summary></summary> public static void DrawString(TextFrame frameContainer,string text,MigraDoc.DocumentObjectModel.Font font,RectangleF rectF, ParagraphAlignment alignment) { TextFrame frame=new TextFrame(); Paragraph par=frame.AddParagraph(); par.Format.Font=font.Clone(); par.Format.Alignment=alignment; par.AddText(text); frame.RelativeVertical=RelativeVertical.Page; frame.RelativeHorizontal=RelativeHorizontal.Page; frame.MarginLeft=Unit.FromInch(rectF.Left/100); frame.MarginTop=Unit.FromInch(rectF.Top/100); frame.Top=TopPosition.Parse("0 in"); frame.Left=LeftPosition.Parse("0 in"); frame.Width=Unit.FromInch(rectF.Right/100f);// frameContainer.Width; Unit bottom=Unit.FromInch(rectF.Bottom/100f); if(frameContainer.Height<bottom) { frameContainer.Height=bottom; } frame.Height=frameContainer.Height; //LineFormat lineformat=new LineFormat(); //lineformat.Width=1; //frame.LineFormat=lineformat; frameContainer.Elements.Add(frame); }
public static Column AddColumn(this Table table, ParagraphAlignment align, Unit unit = new Unit()) { Column column = table.AddColumn(); column.Width = unit; column.Format.Alignment = align; return column; }
public static ST_Jc ValueOf(ParagraphAlignment val) { switch (val) { case ParagraphAlignment.BOTH: return(ST_Jc.both); case ParagraphAlignment.CENTER: return(ST_Jc.center); case ParagraphAlignment.DISTRIBUTE: return(ST_Jc.distribute); case ParagraphAlignment.HIGH_KASHIDA: return(ST_Jc.highKashida); case ParagraphAlignment.LOW_KASHIDA: return(ST_Jc.lowKashida); case ParagraphAlignment.MEDIUM_KASHIDA: return(ST_Jc.mediumKashida); case ParagraphAlignment.NUM_TAB: return(ST_Jc.numTab); case ParagraphAlignment.RIGHT: return(ST_Jc.right); case ParagraphAlignment.THAI_DISTRIBUTE: return(ST_Jc.thaiDistribute); default: return(ST_Jc.left); } }
///<summary></summary> public static void DrawString(TextFrame frameContainer, string text, MigraDoc.DocumentObjectModel.Font font, RectangleF rectF, ParagraphAlignment alignment) { TextFrame frame = new TextFrame(); Paragraph par = frame.AddParagraph(); par.Format.Font = font.Clone(); par.Format.Alignment = alignment; par.AddText(text); frame.RelativeVertical = RelativeVertical.Page; frame.RelativeHorizontal = RelativeHorizontal.Page; frame.MarginLeft = Unit.FromInch(rectF.Left / 100); frame.MarginTop = Unit.FromInch(rectF.Top / 100); frame.Top = TopPosition.Parse("0 in"); frame.Left = LeftPosition.Parse("0 in"); frame.Width = Unit.FromInch(rectF.Right / 100f); // frameContainer.Width; Unit bottom = Unit.FromInch(rectF.Bottom / 100f); if (frameContainer.Height < bottom) { frameContainer.Height = bottom; } frame.Height = frameContainer.Height; //LineFormat lineformat=new LineFormat(); //lineformat.Width=1; //frame.LineFormat=lineformat; frameContainer.Elements.Add(frame); }
static void FillRow(Row row, ParagraphAlignment rowParAligment, bool rowBold, Color rowBackgroundColor, int cellIndex, string colText, bool colBold, ParagraphAlignment colParAligment, VerticalAlignment colVerAlignment, bool rowHeadingFormat = false, Color?fontColor = null, Unit?rowHeight = null, int?fontSize = null) { row.HeadingFormat = rowHeadingFormat; row.Format.Alignment = rowParAligment; row.Format.Font.Bold = rowBold; if (rowHeight != null) { row.Height = (float)rowHeight; } // if (fontColor != null) row.Format.Font.Color = (Color)fontColor; row.Shading.Color = rowBackgroundColor; row.Cells[cellIndex].AddParagraph(colText); row.Cells[cellIndex].Format.Font.Bold = colBold; if (fontSize != null) { row.Cells[cellIndex].Format.Font.Size = (int)fontSize; } row.Cells[cellIndex].Format.Alignment = colParAligment; row.Cells[cellIndex].VerticalAlignment = colVerAlignment; if (fontColor != null) { row.Cells[cellIndex].Format.Font.Color = (Color)fontColor; } }
public void AddTableRowCell(Row row, int index, ParagraphAlignment alignment, string text, bool bold = false) { row.Cells[index].AddParagraph(text); row.Cells[index].Format.Font.Bold = bold; row.Cells[index].Format.Alignment = alignment; row.Cells[index].VerticalAlignment = VerticalAlignment.Center; }
private static void InsertCell( DocumentBuilder builder, string cellContext, CellMerge horizontalMerge = CellMerge.None, CellMerge verticalMerge = CellMerge.None, LineStyle lineStyle = LineStyle.Single, CellVerticalAlignment cellVerticalAlignment = CellVerticalAlignment.Center, ParagraphAlignment alignment = ParagraphAlignment.Center ) { builder.InsertCell(); builder.CellFormat.Borders.LineStyle = lineStyle; builder.CellFormat.Borders.Color = Color.Black; //单元格垂直对齐方向 builder.CellFormat.VerticalAlignment = cellVerticalAlignment; //单元格水平对齐方向 builder.ParagraphFormat.Alignment = alignment; builder.CellFormat.HorizontalMerge = horizontalMerge; builder.CellFormat.VerticalMerge = verticalMerge; builder.Write(cellContext); }
public bool WriteWordTable(DataTable dt, bool haveBorder) { Aspose.Words.Tables.Table table = docBuilder.StartTable();//开始画Table ParagraphAlignment paragraphAlignmentValue = docBuilder.ParagraphFormat.Alignment; docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //添加Word表格 for (int row = 0; row < dt.Rows.Count; row++) { docBuilder.RowFormat.Height = 25; for (int col = 0; col < dt.Columns.Count; col++) { docBuilder.InsertCell(); docBuilder.Font.Size = 10.5; docBuilder.Font.Name = "宋体"; docBuilder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; //垂直居中对齐 docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //水平居中对齐 docBuilder.CellFormat.Width = 50.0; docBuilder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPoints(50); if (haveBorder == true) { //设置外框样式 docBuilder.CellFormat.Borders.LineStyle = LineStyle.Single; //样式设置结束 } docBuilder.Write(dt.Rows[row][col].ToString()); } docBuilder.EndRow(); } docBuilder.EndTable(); docBuilder.ParagraphFormat.Alignment = paragraphAlignmentValue; table.Alignment = Aspose.Words.Tables.TableAlignment.Center; table.PreferredWidth = Aspose.Words.Tables.PreferredWidth.Auto; return(true); }
// ExStart:ImportTableFromDataTable /// <summary> /// Imports the content from the specified DataTable into a new Aspose.Words Table object. /// The table is inserted at the current position of the document builder and using the current builder's formatting if any is defined. /// </summary> public static Table ImportTableFromDataTable(DocumentBuilder builder, DataTable dataTable, bool importColumnHeadings) { Table table = builder.StartTable(); // Check if the names of the columns from the data source are to be included in a header row. if (importColumnHeadings) { // Store the original values of these properties before changing them. bool boldValue = builder.Font.Bold; ParagraphAlignment paragraphAlignmentValue = builder.ParagraphFormat.Alignment; // Format the heading row with the appropriate properties. builder.Font.Bold = true; builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; // Create a new row and insert the name of each column into the first row of the table. foreach (DataColumn column in dataTable.Columns) { builder.InsertCell(); builder.Writeln(column.ColumnName); } builder.EndRow(); // Restore the original formatting. builder.Font.Bold = boldValue; builder.ParagraphFormat.Alignment = paragraphAlignmentValue; } foreach (DataRow dataRow in dataTable.Rows) { foreach (object item in dataRow.ItemArray) { // Insert a new cell for each object. builder.InsertCell(); switch (item.GetType().Name) { case "DateTime": // Define a custom format for dates and times. DateTime dateTime = (DateTime)item; builder.Write(dateTime.ToString("MMMM d, yyyy")); break; default: // By default any other item will be inserted as text. builder.Write(item.ToString()); break; } } // After we insert all the data from the current record we can end the table row. builder.EndRow(); } // We have finished inserting all the data from the DataTable, we can end the table. builder.EndTable(); return(table); }
/// <summary> /// 设置段落格式 /// </summary> /// <param name="builder"></param> /// <param name="alignment">段落对齐方式</param> /// <param name="lineSpacing">行距</param> public static void SetParagraph(DocumentBuilder builder, ParagraphAlignment alignment, int lineSpacing) { var ph = builder.ParagraphFormat; ph.Alignment = alignment; // One line equals 12 points. so 1.5 lines = 18 points ph.LineSpacing = lineSpacing; }
public static Column AddColumn(this Table table, ParagraphAlignment align, Unit unit = new Unit()) { Column column = table.AddColumn(); column.Width = unit; column.Format.Alignment = align; return(column); }
public void Write(string strText, double conSize = 12, bool nBold = false, ParagraphAlignment pa = ParagraphAlignment.Left, bool underline = false) { oWordApplic.Bold = nBold; oWordApplic.Font.Size = conSize; oWordApplic.ParagraphFormat.Alignment = pa; oWordApplic.Underline = underline ? Underline.Single : Underline.None; oWordApplic.Write(strText); }
private static Paragraph AddText(this Paragraph paragraph, string text, ParagraphAlignment align, string style = null) { paragraph.Format.Alignment = align; if (style == null) paragraph.AddText(text); else paragraph.AddFormattedText(text, style); return paragraph; }
public void AddParagraph(string text, ParagraphAlignment alignment = ParagraphAlignment.Left, int fontsize = 12) { Paragraph paragraph = new Paragraph(); paragraph.Format.Alignment = alignment; paragraph.Format.Font.Size = fontsize; paragraph.AddText(text); _document.LastSection.Add(paragraph); }
static void DrawFormattedValue(Document doc, MigraDoc.Rendering.DocumentRenderer docRenderer, XGraphics gfx, Color color, String fontName, Unit fontSize, ParagraphAlignment alignment, float value, double x, double y, double width = 5) { DrawFormatted(doc, docRenderer, gfx, color, fontName, fontSize, alignment, value.ToString("F2"), x, y, width); }
public DocxConfig() { textAlign = ParagraphAlignment.LEFT; rightToLeft = false; marginLeft = 0; marginRight = 0; columnCount = 1; lineSpacing = 1; showPageNumbers = true; fontSize = 12; renderTableOfContents = false; }
/// <summary> /// 插入表格 /// </summary> /// <param name="dt"></param> /// <param name="oWordApplic"></param> /// <param name="haveBorder"></param> public static void InsertTable(DataTable dt, DocumentBuilder oWordApplic, bool haveBorder) { Aspose.Words.Tables.Table table = oWordApplic.StartTable();//开始画Table ParagraphAlignment paragraphAlignmentValue = oWordApplic.ParagraphFormat.Alignment; oWordApplic.ParagraphFormat.Alignment = ParagraphAlignment.Center; //列头 foreach (DataColumn col in dt.Columns) { oWordApplic.InsertCell(); oWordApplic.Font.Size = 8; oWordApplic.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐 if (haveBorder == true) { //设置外框样式 oWordApplic.CellFormat.Borders.LineStyle = LineStyle.Single; //样式设置结束 } oWordApplic.Write(col.ColumnName); } oWordApplic.EndRow(); //添加Word表格 for (int row = 0; row < dt.Rows.Count; row++) { //oWordApplic.RowFormat.Height = 25; for (int col = 0; col < dt.Columns.Count; col++) { oWordApplic.InsertCell(); oWordApplic.Font.Size = 8; //oWordApplic.Font.Name = "宋体"; //oWordApplic.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐 oWordApplic.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐 //oWordApplic.CellFormat.Width = 50.0; //oWordApplic.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPoints(50); if (haveBorder == true) { //设置外框样式 oWordApplic.CellFormat.Borders.LineStyle = LineStyle.Single; //样式设置结束 } oWordApplic.Write(dt.Rows[row][col].ToString()); } oWordApplic.EndRow(); } oWordApplic.EndTable(); oWordApplic.ParagraphFormat.Alignment = paragraphAlignmentValue; //table.Alignment = Aspose.Words.Tables.TableAlignment.Center; //table.PreferredWidth = Aspose.Words.Tables.PreferredWidth.Auto; }
/// <summary> /// 插入文字函数 /// </summary> /// <param name="m_Docx"></param> /// <param name="Font"></param> /// <param name="size"></param> /// <param name="text"></param> /// <param name="position"></param> private static void word_insert_text(XWPFDocument m_Docx, string Font, int size, string text, ParagraphAlignment position = ParagraphAlignment.CENTER) { XWPFParagraph gp = m_Docx.CreateParagraph(); //创建XWPFParagraph gp.SetAlignment(position); XWPFRun gr = gp.CreateRun(); gr.SetFontFamily(Font); gr.SetFontSize(size); gr.SetText(text); }
public ExportToWordService WriteLine(string text, int fontSize, ParagraphAlignment alignment) { var par = doc.CreateParagraph(); par.Alignment = alignment; XWPFRun run = par.CreateRun(); run.FontFamily = "Calibri"; run.FontSize = fontSize; run.SetText(text); return(this); }
private XWPFTableCell _createTableCell(XWPFTableCell cell, string text, ParagraphAlignment alignment, bool isBold) { var paragraph = cell.Paragraphs[0]; paragraph.Alignment = alignment; paragraph.SpacingAfterLines = 0; var run = paragraph.CreateRun(); run.SetText(text); run.IsBold = isBold; return(cell); }
//private void SetText(XWPFTable tb, int row, int column, string text, ParagraphAlignment paragraphAlignment = ParagraphAlignment.LEFT) //{ // tb.GetRow(row).GetCell(column).SetText(text); //} private void SetText(XWPFTable tb, int row, int column, String cellText, ParagraphAlignment paragraphAlignment = ParagraphAlignment.LEFT) { var cell = tb.GetRow(row).GetCell(column); XWPFParagraph p0 = new XWPFParagraph(new CT_P(), cell); p0.Alignment = paragraphAlignment; XWPFRun r0 = p0.CreateRun(); r0.FontFamily = "宋体"; r0.FontSize = 11; r0.SetText(cellText); cell.SetParagraph(p0); }
private static Paragraph AddText(this Paragraph paragraph, string text, ParagraphAlignment align, string style = null) { paragraph.Format.Alignment = align; if (style == null) { paragraph.AddText(text); } else { paragraph.AddFormattedText(text, style); } return(paragraph); }
public static DW.ParagraphAlignment import(this ParagraphAlignment alignment) { switch (alignment) { case ParagraphAlignment.Near: return(DW.ParagraphAlignment.Near); case ParagraphAlignment.Far: return(DW.ParagraphAlignment.Far); case ParagraphAlignment.Center: return(DW.ParagraphAlignment.Center); } return(default(DW.ParagraphAlignment)); }
void DrawText(SharpDX.Direct2D1.DeviceContext context, RectangleF rect, string text, string font, int size, TextAlignment alignment, ParagraphAlignment pAlignment) { if (_format == null) { using (var factory = new Factory()) { _format = new TextFormat(factory, font, size); _format.TextAlignment = alignment; _format.ParagraphAlignment = pAlignment; } } context.DrawText(text, _format, rect, _brush); }
/// <summary> /// Mostly use for main rows /// </summary> /// <param name="row"></param> /// <param name="rowParAligment"></param> /// <param name="rowBold"></param> /// <param name="rowBackgroundColor"></param> /// <param name="cellIndex"></param> /// <param name="colText"></param> /// <param name="colBold"></param> /// <param name="colParAligment"></param> /// <param name="colVerAlignment"></param> /// <param name="rowHeadingFormat"></param> /// <param name="fontColor"></param> /// <param name="rowHeight"></param> /// <param name="fontSize"></param> /// <param name="borders"></param> protected void FillRow(Row row, ParagraphAlignment rowParAligment, bool rowBold, Color rowBackgroundColor, int cellIndex, string colText, bool colBold, ParagraphAlignment colParAligment, VerticalAlignment colVerAlignment, bool rowHeadingFormat = false, Color?fontColor = null, Unit?rowHeight = null, int?fontSize = null, Borders borders = null) { row.HeadingFormat = rowHeadingFormat; row.Format.Alignment = rowParAligment; row.Format.Font.Bold = rowBold; if (rowHeight != null) { row.Height = (float)rowHeight; } // if (fontColor != null) row.Format.Font.Color = (Color)fontColor; row.Shading.Color = rowBackgroundColor; row.Cells[cellIndex].AddParagraph(colText); row.Cells[cellIndex].Format.Font.Bold = colBold; if (fontSize != null) { row.Cells[cellIndex].Format.Font.Size = (int)fontSize; } row.Cells[cellIndex].Format.Alignment = colParAligment; row.Cells[cellIndex].VerticalAlignment = colVerAlignment; if (fontColor != null) { row.Cells[cellIndex].Format.Font.Color = (Color)fontColor; } else { row.Cells[cellIndex].Format.Font.Color = _blackColor; } if (borders != null) { row.Borders.Visible = borders.Visible; row.Borders.Color = borders.Color; if (borders.Left != null) { row.Borders.Left.Color = borders.Left.Color; row.Borders.Left.Visible = borders.Left.Visible; } if (borders.Bottom != null) { row.Borders.Bottom.Color = borders.Bottom.Color; row.Borders.Bottom.Visible = borders.Bottom.Visible; } else { row.Borders.Visible = false; } } }
/// <summary> /// 可设置文字在单元格内是否水平居中 /// </summary> /// <param name="builder"></param> /// <param name="cellWidth"></param> /// <param name="cellAlign">文字水平对齐方向</param> /// <param name="cellText"></param> public static void SetValueCellText(DocumentBuilder builder, int cellWidth, ParagraphAlignment cellAlign, string cellText = "") { builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None; builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.Width = cellWidth; builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //单元格水平对齐方向 builder.ParagraphFormat.Alignment = cellAlign; builder.CellFormat.FitText = true;//单元格内文字为多行(默认为单行,会影响单元格宽) if (!string.IsNullOrEmpty(cellText)) { builder.Write(cellText); } }
/// <summary> /// Initializes a new instance of the <see cref="PdfStyling"/> class. /// </summary> /// <param name="fontName">Name of the font.</param> /// <param name="fontSize">Size of the font.</param> /// <param name="fontColor">Color of the font.</param> /// <param name="headerTitleFontSize">Size of the header title font.</param> /// <param name="headerTitleColor">Color of the header title.</param> /// <param name="paragraphSmallFontSize">Size of the paragraph small font.</param> /// <param name="paragraphSmallColor">Color of the paragraph small.</param> /// <param name="horizontalRuleColor">Color of the horizontal rule.</param> /// <param name="pageFormat">The page format.</param> /// <param name="orientation">The orientation.</param> /// <param name="margin">The margin.</param> /// <param name="showPageNumber">if set to <c>true</c> [show page number].</param> /// <param name="pageNumberAlignment">The page number alignment.</param> /// <param name="pageNumberMarginTop">The page number margin top.</param> /// <param name="tableStyling">The PDF table styling.</param> /// <exception cref="System.IndexOutOfRangeException">You have to define all 4 sites [top, right, bottom, left]</exception> public PdfStyling( string fontName = "Trebuchet MS", int fontSize = 10, Color?fontColor = null, int headerTitleFontSize = 18, Color?headerTitleColor = null, int paragraphSmallFontSize = 8, Color?paragraphSmallColor = null, Color?horizontalRuleColor = null, PageFormat pageFormat = PageFormat.A4, Orientation orientation = Orientation.Portrait, Unit[] margin = null, bool showPageNumber = true, ParagraphAlignment pageNumberAlignment = ParagraphAlignment.Right, int pageNumberMarginTop = 8, IPdfTableStyling tableStyling = null) { if (margin != null && margin.Length < 4) { throw new IndexOutOfRangeException("You have to define all 4 sites [top, right, bottom, left]"); } this.FontName = fontName; this.FontSize = fontSize; this.FontColor = fontColor.HasValue ? fontColor.Value : Colors.Black; this.HeaderTitleFontSize = headerTitleFontSize; this.HeaderTitleColor = headerTitleColor.HasValue ? headerTitleColor.Value : new Color((byte)255, (byte)96, (byte)96, (byte)96); this.ParagraphSmallFontSize = paragraphSmallFontSize; this.ParagraphSmallColor = paragraphSmallColor.HasValue ? paragraphSmallColor.Value : new Color((byte)255, (byte)166, (byte)166, (byte)166); this.HorizontalRuleColor = horizontalRuleColor.HasValue ? horizontalRuleColor.Value : Colors.Black; this.PageFormat = pageFormat; this.Orientation = orientation; this.Margin = margin == null ? new Unit[4] { Unit.FromCentimeter(2.5), Unit.FromCentimeter(2.5), Unit.FromCentimeter(2), Unit.FromCentimeter(2.5) } : margin; this.ShowPageNumber = showPageNumber; this.PageNumberAlignment = pageNumberAlignment; this.PageNumberMarginTop = pageNumberMarginTop; this.TableStyling = tableStyling == null ? new PdfTableStyling() : tableStyling; }
private static Paragraph SetParagraph(Section section, string paragraphText, Font paragraphFont, string spaceBefore = "", string spaceAfter = "", string leftIndent = "", string rightIndent = "", ParagraphAlignment paragraphAlignment = ParagraphAlignment.Left) { var paragraph = section.AddParagraph(paragraphText); paragraph.Format = new ParagraphFormat { Font = paragraphFont, Alignment = paragraphAlignment, LeftIndent = leftIndent, RightIndent = rightIndent, SpaceBefore = spaceBefore, SpaceAfter = spaceAfter }; return(paragraph); }
/// <summary> /// Used for generals rows /// </summary> /// <param name="row"></param> /// <param name="cellIndex"></param> /// <param name="colText"></param> /// <param name="colBold"></param> /// <param name="colParAligment"></param> /// <param name="colVerAlignment"></param> /// <param name="fontColor"></param> /// <param name="marginLeft"></param> /// <param name="fontSize"></param> /// <param name="borders"></param> protected void FillRow(Row row, int cellIndex, string colText, bool colBold, ParagraphAlignment colParAligment, VerticalAlignment colVerAlignment, Color?fontColor = null, float?marginLeft = null, int?fontSize = null, Borders borders = null) { if (fontSize != null) { row.Cells[cellIndex].Format.Font.Size = (int)fontSize; } if (fontColor != null) { row.Cells[cellIndex].Format.Font.Color = (Color)fontColor; } else { row.Cells[cellIndex].Format.Font.Color = _blackColor; } if (marginLeft != null) { row.Cells[cellIndex].Format.LeftIndent = (float)marginLeft; } row.Cells[cellIndex].AddParagraph(string.IsNullOrEmpty(colText) ? "" : colText); row.Cells[cellIndex].Format.Font.Bold = colBold; row.Cells[cellIndex].Format.Alignment = colParAligment; row.Cells[cellIndex].VerticalAlignment = colVerAlignment; if (borders != null) { row.Borders.Visible = borders.Visible; row.Borders.Color = borders.Color; if (borders.Left != null) { row.Borders.Left.Color = borders.Left.Color; row.Borders.Left.Visible = borders.Left.Visible; } if (borders.Bottom != null) { row.Borders.Bottom.Color = borders.Bottom.Color; row.Borders.Bottom.Visible = borders.Bottom.Visible; } } else { row.Borders.Visible = false; } }
static void DrawFormatted(Document doc, MigraDoc.Rendering.DocumentRenderer docRenderer, XGraphics gfx, Color color, String fontName, Unit fontSize, ParagraphAlignment alignment, String text, double x, double y, double width = 5) { Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); para.Format.Alignment = alignment; para.Format.Font.Name = fontName; para.Format.Font.Size = fontSize; para.Format.Font.Bold = true; para.Format.Font.Color = color; //para.Format.Borders.Color = color; //para.Format.LineSpacing = 10; //para.Format.LineSpacingRule = LineSpacingRule.Exactly; para.AddText(text); docRenderer.RenderObject(gfx, XUnit.FromCentimeter(x), XUnit.FromCentimeter(y), XUnit.FromCentimeter(width), para); }
/// <summary> /// 填写单元格文字(日期格式) /// </summary> /// <param name="builder"></param> /// <param name="cellWidth"></param> /// <param name="cellAlign">文字水平对齐方向</param> /// <param name="cellText"></param> public static void SetDateCellText(DocumentBuilder builder, int cellWidth, ParagraphAlignment cellAlign, DateTime dt) { builder.InsertCell(); builder.CellFormat.HorizontalMerge = CellMerge.None; builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.Width = cellWidth; builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //单元格水平对齐方向 builder.ParagraphFormat.Alignment = cellAlign; builder.CellFormat.FitText = true;//单元格内文字为多行(默认为单行,会影响单元格宽) builder.Write(dt.Year.ToString()); builder.Write("年"); builder.Write(dt.Month.ToString()); builder.Write("月"); builder.Write(dt.Day.ToString()); builder.Write("日"); }
public void NewTextFormat(string formatName, string fontFamilyName = DEFAULT_FONT_STYLE, FontWeight fontWeight = FontWeight.Normal, FontStyle fontStyle = FontStyle.Normal, FontStretch fontStretch = FontStretch.Normal, float fontSize = DEFAULT_FONT_SIZE, TextAlignment textAlignment = TextAlignment.Leading, ParagraphAlignment paragraphAlignment = ParagraphAlignment.Near) { if (_textFormats.ContainsKey(formatName)) { return; } TextFormat textFormat = new TextFormat(_writeFactory, fontFamilyName, fontWeight, fontStyle, fontStretch, fontSize); textFormat.TextAlignment = textAlignment; textFormat.ParagraphAlignment = paragraphAlignment; _textFormats.Add(formatName, textFormat); }
/// <summary> /// Used for generals rows /// </summary> /// <param name="row"></param> /// <param name="cellIndex"></param> /// <param name="colText"></param> /// <param name="colBold"></param> /// <param name="colParAligment"></param> /// <param name="colVerAlignment"></param> /// <param name="fontColor"></param> /// <param name="marginLeft"></param> /// <param name="fontSize"></param> static void FillRow(Row row, int cellIndex, string colText, bool colBold, ParagraphAlignment colParAligment, VerticalAlignment colVerAlignment, Color?fontColor = null, float?marginLeft = null, int?fontSize = null) { if (fontSize != null) { row.Cells[cellIndex].Format.Font.Size = (int)fontSize; } if (fontColor != null) { row.Cells[cellIndex].Format.Font.Color = (Color)fontColor; } if (marginLeft != null) { row.Cells[cellIndex].Format.LeftIndent = (float)marginLeft; } row.Cells[cellIndex].AddParagraph(colText); row.Cells[cellIndex].Format.Font.Bold = colBold; row.Cells[cellIndex].Format.Alignment = colParAligment; row.Cells[cellIndex].VerticalAlignment = colVerAlignment; }
public static Table CreateSimpleTableWithoutHeader(string[] strArrayColumnSize, string[][] strMatrixContent, string fontName, Color fontColor, Unit fontSize, double borderSize, double edgeSize, ParagraphAlignment alignment) { Table table = new Table(); table.Borders.Width = borderSize; for (int i = 0; i < strArrayColumnSize.GetLength(0); i++) { table.AddColumn(strArrayColumnSize[i]); } Row row; Cell cell; for (int i = 0; i < strMatrixContent.GetLength(0); i++) { row = table.AddRow(); row.Format.Alignment = alignment; row.Format.Font.Bold = false; row.Format.Font.Name = fontName; row.Format.Font.Color = fontColor; row.Format.Font.Size = fontSize; string[] strArrayContent = strMatrixContent[i]; for (int j = 0; j < strArrayContent.GetLength(0); j++) { cell = row.Cells[j]; if (strArrayContent[j].Contains(".jpg") || strArrayContent[j].Contains(".png")) { Image image = new Image(strArrayContent[j]); image.Width = strArrayColumnSize[j]; cell.Add(image); } else { cell.AddParagraph(strArrayContent[j]); } } } table.SetEdge(0, 0, strArrayColumnSize.GetLength(0), strMatrixContent.GetLength(0), Edge.Box, BorderStyle.Single, edgeSize, Colors.Black); return table; }
/// <summary> /// Creates <see cref="ParagraphFormat"/> object. /// </summary> public ParagraphFormat(ParagraphAlignment pa, ParagraphVerticalAlignment pva, bool ml, bool sil, StringTrimming tr, Brush bg) { Alignment = pa; VerticalAlignment = pva; MultiLine = ml; ShowIncompleteLines = sil; Trimming = tr; BackgroundBrush = bg; }
public void Text( double? size, Color? color, TextAlignment? alignment, ParagraphAlignment? paragraphAlignment, WordWrapping? wordWrapping) { if (size != null) TextSize = size.Value; if (color != null) TextColor = color.Value; if (alignment != null) TextAlignment = alignment.Value; if (paragraphAlignment != null) ParagraphAlignment = paragraphAlignment.Value; if (wordWrapping != null) WordWrapping = wordWrapping.Value; }
private void AppendLine(string text, RichEditControl richEditControl, Font font, Color color, ParagraphAlignment aligment) { DocumentRange range = richEditControl.Document.AppendText(text + '\n'); CharacterProperties cp = richEditControl.Document.BeginUpdateCharacters(range); cp.FontName = font.Name; cp.FontSize = font.Size; cp.ForeColor = color; richEditControl.Document.EndUpdateCharacters(cp); ParagraphProperties pp = richEditControl.Document.BeginUpdateParagraphs(range); pp.Alignment = aligment; richEditControl.Document.EndUpdateParagraphs(pp); }
public static Table CreateSimpleRow(string[] strArrayRow, string[] strArrayRowSize, string fontName, Color fontColor, Color shadeColor, Unit fontSize, ParagraphAlignment alignment, double borderSize, double edgeSize, bool isBold) { Table table = new Table(); table.Borders.Width = borderSize; for (int i = 0; i < strArrayRow.GetLength(0); i++) { table.AddColumn(strArrayRowSize[i]); } Row row = table.AddRow(); row.Format.Alignment = alignment; row.Format.Font.Bold = isBold; row.Format.Font.Name = fontName; row.Format.Font.Color = fontColor; row.Format.Font.Size = fontSize; row.Shading.Color = shadeColor; row.VerticalAlignment = VerticalAlignment.Center; Cell cell; for (int i = 0; i < strArrayRow.GetLength(0); i++) { cell = row.Cells[i]; cell.AddParagraph(strArrayRow[i]); } table.SetEdge(0, 0, strArrayRow.GetLength(0), 1, Edge.Box, BorderStyle.Single, edgeSize, Colors.Black); return table; }
/// <summary> /// Draws string with given character format and alignment at given <see cref="Point"/>. /// </summary> /// <param name="img"><see cref="Image"/> object to draw into.</param> /// <param name="str"><see cref="string"/> to be drawn.</param> /// <param name="pnt"><see cref="Point"/> where the string will be drawn.</param> /// <param name="fmt"><see cref="CharacterFormat"/> used to draw the <see cref="string"/>. </param> /// <param name="align">Specifies whether the <paramref name="pnt"/> is at left, right /// or in the center of the string. (<see cref="ParagraphAlignment.Full"/> means the same /// as <see cref="ParagraphAlignment.Left"/>.)</param> /// <remarks>There's a problem while drawing strings using ClearType on transparent /// background. Resulting text is going to look thick and jagged. If this applies to you, use /// rather Image DrawString(string, CharacterFormat) or /// Image DrawStringInRectangle(string, SizeF, CharacterFormat, ParagraphFormat) where the /// problem is corrected (at cost of a slight performance loss).</remarks> public void DrawString(Image img, string str, PointF pnt, CharacterFormat fmt, ParagraphAlignment align) { Graphics gr = Graphics.FromImage(img); DrawString(gr, str, pnt, fmt, align); gr.Dispose(); }
/// <summary> /// Draws string with given character format and alignment at given <see cref="Point"/>. /// </summary> /// <param name="gr"><see cref="Graphics"/> object to draw into.</param> /// <param name="str"><see cref="string"/> to be drawn.</param> /// <param name="pnt"><see cref="Point"/> where the string will be drawn.</param> /// <param name="fmt"><see cref="CharacterFormat"/> used to draw the <see cref="string"/>. </param> /// <param name="align">Specifies whether the <paramref name="pnt"/> is at left, right /// or in the center of the string. (<see cref="ParagraphAlignment.Full"/> means the same /// as <see cref="ParagraphAlignment.Left"/>.)</param> public void DrawString(Graphics gr, string str, PointF pnt, CharacterFormat fmt, ParagraphAlignment align) { StringFormat sf = (StringFormat) StringFormat.GenericDefault.Clone(); sf.Alignment = ParAl2StrAl(align); sf.HotkeyPrefix = fmt.HotkeyPrefix; Matrix trOld = null; if (fmt.Angle != 0) { trOld = gr.Transform.Clone(); gr.TranslateTransform(pnt.X, pnt.Y); gr.RotateTransform(fmt.Angle); gr.TranslateTransform(-pnt.X, -pnt.Y); } if (fmt.Formatted) { CharacterFormat cf = fmt.ShallowCopy(); cf.Angle = 0; SDUFormattedString fs = new SDUFormattedString(str, cf); SizeF sz = fs.Measure(gr, true); sz.Height += GetMeasureStringVerticalGap(gr, cf.Font); PointF ofs = pnt; switch (align) { case ParagraphAlignment.Right: ofs.X -= sz.Width; break; case ParagraphAlignment.Center: ofs.X -= sz.Width/2; break; } ParagraphFormat pf = new ParagraphFormat(); pf.MultiLine = false; pf.Alignment = align; fs.DrawStringInRectangle(gr, new RectangleF(ofs, sz), pf); } else if (fmt.FilledBounds) { ParagraphFormat pf = new ParagraphFormat(); //pf.Alignment=align; SizeF sz = MeasureStringExactly(gr, str, fmt, pf, false); sz.Width += GetMeasureStringHorizontalGap(gr, fmt.Font); pnt.X += GetMeasureStringHorizontalGap(gr, fmt.Font)/2; pnt.Y += GetMeasureStringVerticalGap(gr, fmt.Font); gr.FillRectangle(fmt.Brush, new RectangleF(pnt, sz)); } else gr.DrawString(str, fmt.Font, fmt.Brush, pnt, sf); if (trOld != null) gr.Transform = trOld; }
/// <summary> /// Creates <see cref="ParagraphFormat"/> object with implicit formatting. /// </summary> public ParagraphFormat() { Alignment = ParagraphAlignment.Left; VerticalAlignment = ParagraphVerticalAlignment.Top; MultiLine = true; ShowIncompleteLines = true; Trimming = StringTrimming.EllipsisCharacter; BackgroundBrush = null; }
public void Text(double? size = null, Color? color = null, TextAlignment? alignment = null, ParagraphAlignment? paragraphAlignment = null, WordWrapping? wordWrapping = null) { _state.Text(size, color, alignment, paragraphAlignment, wordWrapping); }
public static void DefineParagraph(Document document, string strText, ParagraphAlignment alignment, Unit fontSize) { Paragraph paragraph = document.LastSection.AddParagraph(); paragraph.Format.Alignment = alignment; paragraph.Format.Font.Size = fontSize; paragraph.AddText(strText); }
public static Paragraph AddParagraph(this TextFrame frame, string text, ParagraphAlignment align, string style = null) { return frame.AddParagraph().AddText(text, align, style); }
public static Paragraph AddParagraph(this Cell cell, string text, ParagraphAlignment align, string style = null) { return cell.AddParagraph().AddText(text, align, style); }
/// <summary> /// Converts <see cref="ParagraphAlignment"/> value into <see cref="StringAlignment"/>. /// </summary> /// <param name="par"><see cref="ParagraphAlignment"/> value to be converted.</param> /// <returns>Resulting <see cref="StringAlignment"/> value.</returns> private StringAlignment ParAl2StrAl(ParagraphAlignment par) { //As profiller showed this point to be a bottleneck, we have performed some optimalizations... return (StringAlignment) ((int) par%3); //Original unoptimized code /* switch(par) { case ParagraphAlignment.Left: return StringAlignment.Near; case ParagraphAlignment.Full: return StringAlignment.Near; case ParagraphAlignment.Right: return StringAlignment.Far; case ParagraphAlignment.Center: return StringAlignment.Center; } System.Diagnostics.Debug.Assert(false); return StringAlignment.Near; */ }
/** * Specifies the paragraph alignment which shall be applied to text in this * paragraph. * <p> * <p> * If this element is not Set on a given paragraph, its value is determined * by the Setting previously Set at any level of the style hierarchy (i.e. * that previous Setting remains unChanged). If this Setting is never * specified in the style hierarchy, then no alignment is applied to the * paragraph. * </p> * * @param align the paragraph alignment to apply to this paragraph. */ public void SetAlignment(ParagraphAlignment align) { CT_PPr pr = GetCTPPr(); CT_Jc jc = pr.IsSetJc() ? pr.jc : pr.AddNewJc(); jc.val = EnumConverter.ValueOf<ST_Jc, ParagraphAlignment>(align); }
public void Text( double? size, Color? color, TextAlignment? alignment, ParagraphAlignment? paragraphAlignment, WordWrapping? wordWrapping) { record(t => t.Text(size, color, alignment, paragraphAlignment, wordWrapping)); }