static void DemonstrateFormattedText(MigraDocMadeEZR document) { document.AddParagraph("Heading2", "Formatted Text"); var paragraph = document.AddParagraph(); paragraph.AddText("Text can be formatted "); paragraph.AddFormattedText(new MezFormattedText("bold").Bold(true)); paragraph.AddText(", "); paragraph.AddFormattedText(new MezFormattedText("italic").Italic(true)); paragraph.AddText(", or "); paragraph.AddFormattedText(new MezFormattedText("bold & italic").Bold(true).Italic(true)); paragraph.AddText("."); paragraph.AddLineBreak(); paragraph.AddText("You can set the "); paragraph.AddFormattedText(new MezFormattedText("size").Font(15)); paragraph.AddText(", the "); paragraph.AddFormattedText(new MezFormattedText("color").Color(Colors.Firebrick)); paragraph.AddText(", the "); // Times New Roman looks smaller than Segoe UI, so we make it a bit larger. paragraph.AddFormattedText(new MezFormattedText("font").Font("Times New Roman", 12)); paragraph.AddText("."); paragraph.AddLineBreak(); paragraph.AddText("You can set the "); paragraph.AddFormattedText(new MezFormattedText("subscript").Subscript(true)); paragraph.AddText(" or "); paragraph.AddFormattedText(new MezFormattedText("superscript").Superscript(true)); paragraph.AddText("."); }
public static void DemonstrateCellMerge(MigraDocMadeEZR document) { document.Section.AddParagraph("Cell Merge", "Heading2"); var table = document.Section.AddTable(); table.Borders.Visible = true; table.TopPadding = 5; table.BottomPadding = 5; var column = table.AddColumn(); column.Format.Alignment = ParagraphAlignment.Left; column = table.AddColumn(); column.Format.Alignment = ParagraphAlignment.Center; column = table.AddColumn(); column.Format.Alignment = ParagraphAlignment.Right; table.Rows.Height = 35; var row = table.AddRow(); row.Cells[0].AddParagraph("Merge Right"); row.Cells[0].MergeRight = 1; row = table.AddRow(); row.VerticalAlignment = VerticalAlignment.Bottom; row.Cells[0].MergeDown = 1; row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom; row.Cells[0].AddParagraph("Merge Down"); table.AddRow(); }
/// <summary> /// Defines the styles used in the document. /// </summary> public static void DefineStyles(MigraDocMadeEZR document) { // Change the predefined style Normal. // Because all styles are derived from Normal, the next line changes the // font of the whole document. Or, more exactly, it changes the font of // all styles and paragraphs that do not redefine the font. document.Style(StyleNames.Normal).Font("Segoe UI"); // Heading1 to Heading9 are predefined styles with an outline level. An outline level // other than OutlineLevel.BodyText automatically creates the outline (or bookmarks) // in PDF. document.Style(StyleNames.Heading1).Font("Segoe UI Light", 16) .Color(Colors.DarkBlue).SpaceAfter(6).PageBreakBefore(true).KeepWithNext(true); // Set KeepWithNext for all headings to prevent headings from appearing all alone // at the bottom of a page. The other headings inherit this from Heading1. document.Style(StyleNames.Heading2).Font(14).SpaceBefore(6).SpaceAfter(6).PageBreakBefore(false); document.Style(StyleNames.Heading3).Font(12).Italic(true).SpaceBefore(6).SpaceAfter(3); document.Style(StyleNames.Header).SetTabStop("16cm", TabAlignment.Right); document.Style(StyleNames.Footer).SetTabStop("8cm", TabAlignment.Center); // Create a new style called TextBox based on style Normal. document.AddStyle("TextBox", StyleNames.Normal).Alignment(ParagraphAlignment.Justify) .Borders(2.5).BorderDistance("3pt").ShadingColor(Colors.SkyBlue); // Create a new style called TOC based on style Normal. document.AddStyle("TOC", StyleNames.Normal) .SetTabStop("16cm", TabAlignment.Right, TabLeader.Dots).Color(Colors.Blue); }
/// <summary> /// Defines page setup, headers, and footers. /// </summary> static void DefineContentSection(MigraDocMadeEZR document) { var section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; var header = section.Headers.Primary; header.AddParagraph("\tOdd Page Header"); header = section.Headers.EvenPage; header.AddParagraph("Even Page Header"); // Create a paragraph with centered page number. See definition of style "Footer". var paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must // not belong to more than one other object. If you forget cloning an exception is thrown. section.Footers.EvenPage.Add(paragraph.Clone()); }
/// <summary> /// Defines the table of contents. /// </summary> public static void DefineTableOfContents(MigraDocMadeEZR document) { var section = document.Section; section.AddPageBreak(); var paragraph = section.AddParagraph("Table of Contents"); paragraph.Format.Font.Size = 14; paragraph.Format.Font.Bold = true; paragraph.Format.SpaceAfter = 24; paragraph.Format.OutlineLevel = OutlineLevel.Level1; paragraph = section.AddParagraph(); paragraph.Style = "TOC"; var hyperlink = paragraph.AddHyperlink("Paragraphs"); hyperlink.AddText("Paragraphs\t"); hyperlink.AddPageRefField("Paragraphs"); paragraph = section.AddParagraph(); paragraph.Style = "TOC"; hyperlink = paragraph.AddHyperlink("Tables"); hyperlink.AddText("Tables\t"); hyperlink.AddPageRefField("Tables"); paragraph = section.AddParagraph(); paragraph.Style = "TOC"; hyperlink = paragraph.AddHyperlink("Charts"); hyperlink.AddText("Charts\t"); hyperlink.AddPageRefField("Charts"); }
public static void DefineTables(MigraDocMadeEZR document) { var paragraph = document.AddParagraph("Heading1", "Table Overview"); paragraph.AddBookmark("Tables"); DemonstrateSimpleTable(document); DemonstrateAlignment(document); DemonstrateCellMerge(document); }
public static void DefineParagraphs(MigraDocMadeEZR document) { var paragraph = document.AddParagraph("Heading1", "Paragraph Layout Overview"); paragraph.AddBookmark("Paragraphs"); DemonstrateAlignment(document); DemonstrateIndent(document); DemonstrateFormattedText(document); DemonstrateBordersAndShading(document); }
/// <summary> /// Creates the invoice document. /// </summary> public MigraDocMadeEZR CreateDocument() { // Create a new MigraDoc document. _document = new MigraDocMadeEZR(); _document.InfoTitle = "A sample invoice"; _document.InfoSubject = "Demonstrates how to create an invoice."; _document.InfoAuthor = "Stefan Lange"; DefineStyles(); CreatePage(); FillContent(); return(_document); }
static void DemonstrateBordersAndShading(MigraDocMadeEZR document) { document.AddPageBreak(); document.AddParagraph("Heading2", "Borders and Shading"); document.AddParagraph("Heading3", "Border around Paragraph"); document.AddParagraph(FillerText.MediumText).Borders(2.5, Colors.Navy).BorderDistance(3); document.AddParagraph("Heading3", "Shading"); document.AddParagraph(FillerText.Text).ShadingColor(Colors.LightCoral); document.AddParagraph("Heading3", "Borders & Shading"); document.AddParagraph("TextBox", FillerText.MediumText); }
static void Main(string[] args) { // Instantiate MigraDocMadeEZR. var mez = new MigraDocMadeEZR(); // Create a MigraDoc document. CreateDocument(mez); #if DEBUG //MigraDoc.DocumentObjectModel.IO.DdlWriter dw = new MigraDoc.DocumentObjectModel.IO.DdlWriter("HelloWorld.mdddl"); //dw.WriteDocument(mez.Document); //dw.Close(); mez.SaveMDDDL("HelloWorld.mdddl"); #endif // Save the document and start a viewer. const string filename = "HelloWorld.pdf"; mez.MakePdf(filename, true, false); }
public static void DemonstrateAlignment(MigraDocMadeEZR document) { document.Section.AddParagraph("Cell Alignment", "Heading2"); var table = document.Section.AddTable(); table.Borders.Visible = true; table.Format.Shading.Color = Colors.LavenderBlush; table.Shading.Color = Colors.Salmon; table.TopPadding = 5; table.BottomPadding = 5; var column = table.AddColumn(); column.Format.Alignment = ParagraphAlignment.Left; column = table.AddColumn(); column.Format.Alignment = ParagraphAlignment.Center; column = table.AddColumn(); column.Format.Alignment = ParagraphAlignment.Right; table.Rows.Height = 35; var row = table.AddRow(); row.VerticalAlignment = VerticalAlignment.Top; row.Cells[0].AddParagraph("Text"); row.Cells[1].AddParagraph("Text"); row.Cells[2].AddParagraph("Text"); row = table.AddRow(); row.VerticalAlignment = VerticalAlignment.Center; row.Cells[0].AddParagraph("Text"); row.Cells[1].AddParagraph("Text"); row.Cells[2].AddParagraph("Text"); row = table.AddRow(); row.VerticalAlignment = VerticalAlignment.Bottom; row.Cells[0].AddParagraph("Text"); row.Cells[1].AddParagraph("Text"); row.Cells[2].AddParagraph("Text"); }
static void DemonstrateIndent(MigraDocMadeEZR document) { document.AddParagraph("Heading2", "Indent"); document.AddParagraph("Heading3", "Left Indent"); document.AddParagraph(FillerText.Text).LeftIndent("2cm"); document.AddParagraph("Heading3", "Right Indent"); document.AddParagraph(FillerText.Text).RightIndent("1in"); document.AddParagraph("Heading3", "First Line Indent"); document.AddParagraph(FillerText.Text).FirstLineIndent("12mm"); document.AddParagraph("Heading3", "First Line Negative Indent"); document.AddParagraph(FillerText.Text).LeftIndent("1.5cm").FirstLineIndent("-1.5cm"); }
static void DemonstrateAlignment(MigraDocMadeEZR document) { document.AddParagraph("Heading2", "Alignment"); document.AddParagraph("Heading3", "Left Aligned"); document.AddParagraph(FillerText.Text).Alignment(ParagraphAlignment.Left); document.AddParagraph("Heading3", "Right Aligned"); document.AddParagraph(FillerText.Text).Alignment(ParagraphAlignment.Right); document.AddParagraph("Heading3", "Centered"); document.AddParagraph(FillerText.Text).Alignment(ParagraphAlignment.Center); document.AddParagraph("Heading3", "Justified"); document.AddParagraph(FillerText.MediumText).Alignment(ParagraphAlignment.Justify); }
/// <summary> /// Defines the cover page. /// </summary> public static void DefineCover(MigraDocMadeEZR document) { var section = document.Section; var paragraph = section.AddParagraph(); paragraph.Format.SpaceAfter = "3cm"; var image = section.AddImage("../../../../assets/images/Logo landscape.png"); image.Width = "10cm"; paragraph = section.AddParagraph("A sample document that demonstrates the\ncapabilities of MigraDoc"); paragraph.Format.Font.Size = 16; paragraph.Format.Font.Color = Colors.DarkRed; paragraph.Format.SpaceBefore = "8cm"; paragraph.Format.SpaceAfter = "3cm"; paragraph = section.AddParagraph("Rendering date: "); paragraph.AddDateField(); }
public static MigraDocMadeEZR CreateDocument() { // Create a new MigraDoc document. var document = new MigraDocMadeEZR(); document.InfoTitle = "Hello, MigraDoc"; document.InfoSubject = "Demonstrates an excerpt of the capabilities of MigraDoc."; document.InfoAuthor = "Stefan Lange (modifications by Thomas Hövel)"; Styles.DefineStyles(document); Cover.DefineCover(document); TableOfContents.DefineTableOfContents(document); DefineContentSection(document); Paragraphs.DefineParagraphs(document); Tables.DefineTables(document); Charts.DefineCharts(document); return(document); }
/// <summary> /// Defines the charts page. /// </summary> public static void DefineCharts(MigraDocMadeEZR document) { var paragraph = document.AddParagraph("Heading1", "Chart Overview"); paragraph.AddBookmark("Charts"); document.AddParagraph("Heading2", "Sample Chart"); var chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(16); chart.Height = Unit.FromCentimeter(12); var series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Column2D; series.Add(1, 17, 45, 5, 3, 20, 11, 23, 8, 19); series.HasDataLabel = true; series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.Add(41, 7, 5, 45, 13, 10, 21, 13, 18, 9); var xseries = chart.XValues.AddXSeries(); xseries.Add("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N"); chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = "X-Axis"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; document.Section.Add(chart); }
public static void DemonstrateSimpleTable(MigraDocMadeEZR document) { document.Section.AddParagraph("Simple Tables", "Heading2"); var table = new Table(); table.Borders.Width = 0.75; var column = table.AddColumn(Unit.FromCentimeter(2)); column.Format.Alignment = ParagraphAlignment.Center; table.AddColumn(Unit.FromCentimeter(5)); var row = table.AddRow(); row.Shading.Color = Colors.PaleGoldenrod; var cell = row.Cells[0]; cell.AddParagraph("Itemus"); cell = row.Cells[1]; cell.AddParagraph("Descriptum"); row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph("1"); cell = row.Cells[1]; cell.AddParagraph(FillerText.ShortText); row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph("2"); cell = row.Cells[1]; cell.AddParagraph(FillerText.Text); table.SetEdge(0, 0, 2, 3, Edge.Box, BorderStyle.Single, 1.5, Colors.Black); document.Section.Add(table); }
/// <summary> /// Creates an absolutely minimalistic document. /// </summary> static void CreateDocument(MigraDocMadeEZR mez) { // Add a paragraph to the section. var mezParagraph = mez.AddParagraph(); // Set font color. mezParagraph.Color(Colors.DarkBlue); // Add some text to the paragraph. mezParagraph.AddFormattedText(new MezFormattedText("Hello, World!").Bold(true)); // Create the primary footer. var footer = mez.Section.Footers.Primary; // _THHO TODO Add support for Headers and Footers to MEZ? // Add content to footer. var paragraph = footer.AddParagraph(); paragraph.Add(new DateField() { Format = "yyyy/MM/dd HH:mm:ss" }); paragraph.Format.Alignment = ParagraphAlignment.Center; }