本文整理汇总了C#中MigraDoc.DocumentObjectModel.Document.AddStyle方法的典型用法代码示例。如果您正苦于以下问题:C# Document.AddStyle方法的具体用法?C# Document.AddStyle怎么用?C# Document.AddStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MigraDoc.DocumentObjectModel.Document
的用法示例。
在下文中一共展示了Document.AddStyle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StyleDoc
private void StyleDoc(Document doc)
{
Color green = new Color(108, 179, 63),
brown = new Color(88, 71, 76),
lightbrown = new Color(150, 132, 126);
var body = doc.Styles["Normal"];
body.Font.Size = Unit.FromInch(0.14);
body.Font.Color = new Color(51, 51, 51);
body.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
body.ParagraphFormat.LineSpacing = 1.25;
body.ParagraphFormat.SpaceAfter = 10;
var footer = doc.Styles["Footer"];
footer.Font.Size = Unit.FromInch(0.125);
footer.Font.Color = green;
var h1 = doc.Styles["Heading1"];
h1.Font.Color = green;
h1.Font.Bold = true;
h1.Font.Size = Unit.FromPoint(15);
var h2 = doc.Styles["Heading2"];
h2.Font.Color = green;
h2.Font.Bold = true;
h2.Font.Size = Unit.FromPoint(13);
var h3 = doc.Styles["Heading3"];
h3.Font.Bold = true;
h3.Font.Color = Colors.Black;
h3.Font.Size = Unit.FromPoint(11);
var links = doc.Styles["Hyperlink"];
links.Font.Color = green;
var unorderedlist = doc.AddStyle("UnorderedList", "Normal");
var listInfo = new ListInfo();
listInfo.ListType = ListType.BulletList1;
unorderedlist.ParagraphFormat.ListInfo = listInfo;
unorderedlist.ParagraphFormat.LeftIndent = "1cm";
unorderedlist.ParagraphFormat.FirstLineIndent = "-0.5cm";
unorderedlist.ParagraphFormat.SpaceAfter = 0;
var orderedlist = doc.AddStyle("OrderedList", "UnorderedList");
orderedlist.ParagraphFormat.ListInfo.ListType = ListType.NumberList1;
// for list spacing (since MigraDoc doesn't provide a list object that we can target)
var listStart = doc.AddStyle("ListStart", "Normal");
listStart.ParagraphFormat.SpaceAfter = 0;
listStart.ParagraphFormat.LineSpacing = 0.5;
var listEnd = doc.AddStyle("ListEnd", "ListStart");
listEnd.ParagraphFormat.LineSpacing = 1;
var hr = doc.AddStyle("HorizontalRule", "Normal");
var hrBorder = new Border();
hrBorder.Width = "1pt";
hrBorder.Color = Colors.DarkGray;
hr.ParagraphFormat.Borders.Bottom = hrBorder;
hr.ParagraphFormat.LineSpacing = 0;
hr.ParagraphFormat.SpaceBefore = 15;
}
示例2: WriteToPDF
private static void WriteToPDF(DataCell[][] dataCells, string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
// Create a new MigraDoc document
var document = new Document();
document.Styles["Normal"].Font.Name = "Arial";
document.DefaultPageSetup.LeftMargin -= Unit.FromCentimeter(1);
var section = document.AddSection();
var rightStyle = document.AddStyle("RightAligned", "Normal");
rightStyle.ParagraphFormat.Alignment = ParagraphAlignment.Right;
var headingStyle = document.AddStyle("Heading", "Normal");
headingStyle.Font.Size = Unit.FromPoint(11);
var headingBigStyle = document.AddStyle("HeadingBig", "Normal");
headingBigStyle.Font.Size = Unit.FromPoint(16);
var table = section.AddTable();
table.Style = "Table";
table.Rows.LeftIndent = 0;
var columnCount = dataCells.Max(x => x.Length);
for (var i = 0; i < columnCount; i++)
{
var column = table.AddColumn((18.0/columnCount) + "cm");
column.Format.Alignment = ParagraphAlignment.Left;
}
foreach (var row in dataCells)
{
var pdfRow = table.AddRow();
int counter = 0;
foreach (var dataCell in row)
{
var pdfCell = pdfRow.Cells[counter];
pdfCell.AddParagraph(dataCell.Content);
if (dataCell.Outline.HasFlag(DataCellOutline.Top))
{
pdfCell.Borders.Top.Visible = true;
pdfCell.Borders.Top.Style = BorderStyle.Single;
pdfCell.Borders.Top.Width = Unit.FromMillimeter(0.5);
pdfCell.Borders.Top.Color = new Color(0, 0, 0);
}
if (dataCell.Outline.HasFlag(DataCellOutline.Bottom))
{
pdfCell.Borders.Bottom.Visible = true;
pdfCell.Borders.Bottom.Style = BorderStyle.Single;
pdfCell.Borders.Bottom.Width = Unit.FromMillimeter(0.5);
pdfCell.Borders.Bottom.Color = new Color(0, 0, 0);
}
if (dataCell.Outline.HasFlag(DataCellOutline.Left))
{
pdfCell.Borders.Left.Visible = true;
pdfCell.Borders.Left.Style = BorderStyle.Single;
pdfCell.Borders.Left.Width = Unit.FromMillimeter(0.5);
pdfCell.Borders.Left.Color = new Color(0, 0, 0);
}
if (dataCell.Outline.HasFlag(DataCellOutline.Right))
{
pdfCell.Borders.Right.Visible = true;
pdfCell.Borders.Right.Style = BorderStyle.Single;
pdfCell.Borders.Right.Width = Unit.FromMillimeter(0.5);
pdfCell.Borders.Right.Color = new Color(0, 0, 0);
}
switch (dataCell.Type)
{
case DataCellType.HeadingBig:
pdfCell.Style = "HeadingBig";
pdfCell.MergeRight = columnCount - 1;
break;
case DataCellType.Heading:
pdfCell.Style = "Heading";
break;
case DataCellType.Number:
pdfCell.Style = "RightAligned";
break;
case DataCellType.ResultGood:
PDFDataSerializer.SetCellResultStyle(pdfCell, new Color(0xBC, 0xED, 0x91));
break;
case DataCellType.ResultNeutral:
PDFDataSerializer.SetCellResultStyle(pdfCell, new Color(0xFF, 0xEC, 0xB3));
break;
case DataCellType.ResultBad:
PDFDataSerializer.SetCellResultStyle(pdfCell, new Color(0xFF, 0x8A, 0x65));
break;
}
//.........这里部分代码省略.........
示例3: Test
// [UnitTestFunction]
public static void Test()
{
Document doc = new Document();
Style styl = doc.AddStyle("TestStyle1", Style.DefaultParagraphFontName);
styl.Font.Bold = true;
Section sec = doc.AddSection();
sec.PageSetup.PageHeight = "30cm";
sec.Headers.FirstPage.Format.Font.Bold = true;
sec.Headers.Primary.AddParagraph("This is the Primary Header.");
sec.Headers.FirstPage.AddParagraph("This is the First Page Header.");
sec.Headers.EvenPage.AddParagraph("This is the Even Page Header.");
Paragraph par = sec.AddParagraph("Paragraph 1");
// par.Style = "TestStyle1";
par.Format.ListInfo.NumberPosition = 2;
par = sec.AddParagraph("Paragraph 2");
par.Format.ListInfo.ListType = ListType.BulletList3;
Image img1 = par.AddImage("logo.gif");
// Image img1 = par.AddImage("tick_green.png");
img1.ScaleHeight = 5;
img1.ScaleWidth = 2;
img1.Height = "0.3cm";
img1.Width = "5cm";
img1.PictureFormat.CropLeft = "-2cm";
img1.FillFormat.Color = Color.PowderBlue;
img1.LineFormat.Width = 2;
par = sec.AddParagraph("Paragraph 3");
par.AddLineBreak();
par.Format.ListInfo.NumberPosition = 2;
TextFrame tf = sec.AddTextFrame();
tf.WrapFormat.Style = WrapStyle.None;
tf.RelativeHorizontal = RelativeHorizontal.Page;
tf.RelativeVertical = RelativeVertical.Page;
tf.Top = Unit.FromCm(2);
tf.Left = ShapePosition.Center;
tf.Height = "20cm";
tf.Width = "10cm";
tf.FillFormat.Color = Color.LemonChiffon;
tf.LineFormat.Color = Color.BlueViolet;
tf.LineFormat.DashStyle = DashStyle.DashDotDot;
tf.LineFormat.Width = 2;
tf.AddParagraph("in a text frame");
tf.MarginTop = "3cm";
tf.Orientation = TextOrientation.Downward;
Image img = sec.AddImage("test1.jpg");
img.ScaleHeight = 500;
img.ScaleWidth = 200;
img.Height = "10cm";
img.Width = "10cm";
img.PictureFormat.CropLeft = "-2cm";
img.FillFormat.Color = Color.LawnGreen;
img.LineFormat.Width = 3;
img.WrapFormat.Style = WrapStyle.None;
sec = doc.AddSection();//.AddParagraph("test");
sec.PageSetup.PageWidth = "30cm";
sec.AddParagraph("Section 2");
DocumentRenderer docRenderer = new DocumentRenderer();
docRenderer.Render(doc, "RtfListInfo.txt", null);
DdlWriter.WriteToFile(doc, "RtfListInfo.mdddl");
System.IO.File.Copy("RtfListInfo.txt", "RtfListInfo.rtf", true);
System.Diagnostics.Process.Start("RtfListInfo.txt");
}
示例4: CreateDocument
/// <summary>
/// Creates a <see cref="Document"/>.
/// </summary>
/// <param name="title">The document title.</param>
/// <returns>A <see cref="Document"/>.</returns>
protected Document CreateDocument(string title = "")
{
Document document = new Document();
document.AddSection();
document.Info.Title = this.Settings.MetaTitle;
document.Info.Author = this.Settings.MetaAuthor;
this.DefaultStyle = document.Styles[StyleNames.Normal];
this.DefaultStyle.Font.Name = this.Settings.FontFace;
this.DefaultStyle.Font.Size = this.Settings.FontSize;
this.DefaultStyle.Font.Color = this.CreateColorFromHex(this.Settings.FontColourHex);
Style hyperlinkStyle = document.Styles[StyleNames.Hyperlink];
hyperlinkStyle.BaseStyle = StyleNames.Normal;
hyperlinkStyle.Font.Underline = Underline.Single;
hyperlinkStyle.Font.Color = Colors.Blue;
Style tableStyle = document.Styles.AddStyle(PdfResources.StyleNameTable, StyleNames.Normal);
tableStyle.ParagraphFormat.LeftIndent = 4;
tableStyle.ParagraphFormat.RightIndent = 4;
Style tableHeaderStyle = document.Styles.AddStyle(PdfResources.StyleNameHeaderRow, PdfResources.StyleNameTable);
tableHeaderStyle.Font.Bold = true;
tableHeaderStyle.Font.Color = this.CreateColorFromHex(this.Settings.HeaderRowFontColourHex);
this.WriteHeader(document, title, this.Settings.HeaderLogoUri);
Color headerRowColour = this.CreateColorFromHex(this.Settings.HeaderRowBackgroundHex);
var headerStyle = document.Styles[StyleNames.Header];
headerStyle.Font.Name = this.Settings.FontFace;
headerStyle.Font.Size = "20pt";
var headingOneStyle = document.Styles[StyleNames.Heading1];
headingOneStyle.Font.Name = this.Settings.FontFace;
headingOneStyle.Font.Size = this.DefaultStyle.Font.Size * 2.0;
var headingTwoStyle = document.Styles[StyleNames.Heading2];
headingTwoStyle.BaseStyle = StyleNames.Heading1;
headingTwoStyle.ParagraphFormat.Font.Color = headerRowColour;
headingTwoStyle.ParagraphFormat.Borders.Top = new Border { Color = headerRowColour, Style = BorderStyle.Single };
headingTwoStyle.ParagraphFormat.SpaceBefore = new Unit(6, UnitType.Millimeter);
headingTwoStyle.ParagraphFormat.SpaceAfter = new Unit(2, UnitType.Millimeter);
headingTwoStyle.Font.Size = this.DefaultStyle.Font.Size * 1.5;
var headingThreeStyle = document.Styles[StyleNames.Heading3];
headingThreeStyle.BaseStyle = StyleNames.Heading2;
headingThreeStyle.ParagraphFormat.Borders.Top = new Border { Style = BorderStyle.None, Visible = false, Width = 0 };
headingThreeStyle.Font.Size = this.DefaultStyle.Font.Size * 1.25;
var controlLabelStyle = document.AddStyle(PdfResources.StyleNameControlLabel, StyleNames.Normal);
controlLabelStyle.ParagraphFormat.SpaceBefore = new Unit(3, UnitType.Millimeter);
controlLabelStyle.ParagraphFormat.SpaceAfter = new Unit(2, UnitType.Millimeter);
var unorderedlist = document.AddStyle(PdfResources.StyleNameUnorderedList, StyleNames.Normal);
var listInfo = new ListInfo
{
ListType = ListType.BulletList1
};
unorderedlist.ParagraphFormat.ListInfo = listInfo;
unorderedlist.ParagraphFormat.LeftIndent = 2;
unorderedlist.ParagraphFormat.FirstLineIndent = -0.5;
unorderedlist.ParagraphFormat.SpaceAfter = 0;
var orderedlist = document.AddStyle(PdfResources.StyleNameOrderedList, PdfResources.StyleNameUnorderedList);
orderedlist.ParagraphFormat.ListInfo.ListType = ListType.NumberList1;
// for list spacing (since MigraDoc doesn't provide a list object that we can target)
var listStart = document.AddStyle(PdfResources.StyleNameListStart, StyleNames.Normal);
listStart.ParagraphFormat.SpaceBefore = 0;
listStart.ParagraphFormat.SpaceAfter = 0;
listStart.ParagraphFormat.LineSpacing = 0.5;
var listEnd = document.AddStyle(PdfResources.StyleNameListEnd, PdfResources.StyleNameListStart);
listEnd.ParagraphFormat.SpaceBefore = 0;
listEnd.ParagraphFormat.SpaceAfter = 0;
listEnd.ParagraphFormat.LineSpacing = 1;
return document;
}