Beispiel #1
0
        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 DefineTables(MigraDocMadeEZR document)
        {
            var paragraph = document.AddParagraph("Heading1", "Table Overview");

            paragraph.AddBookmark("Tables");

            DemonstrateSimpleTable(document);
            DemonstrateAlignment(document);
            DemonstrateCellMerge(document);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        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");
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        /// <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;
        }
        /// <summary>
        /// Creates the static parts of the invoice.
        /// </summary>
        void CreatePage()
        {
            var section = _document.Section;

            // Define the page setup. We use an image in the header, therefore the
            // default top margin is too small for our invoice.
            // We increase the TopMargin to prevent the document body from overlapping the page header.
            // We have an image of 3.5 cm height in the header.
            // The default position for the header is 1.25 cm.
            // We add 0.5 cm spacing between header image and body and get 5.25 cm.
            // Default value is 2.5 cm.
            section.PageSetup.TopMargin = "5.25cm";

            // Put the logo in the header.
#if true
            var image = new MezImage("../../../../assets/images/MigraDoc.png")
                        .Height("3.5cm")
                        .LockAspectRatio(true)
                        .RelativeVertical(RelativeVertical.Line)
                        .RelativeHorizontal(RelativeHorizontal.Margin)
                        .Top(ShapePosition.Top)
                        .Left(ShapePosition.Right)
                        .WrapFormatStyle(WrapStyle.Through);
            section.Headers.Primary.Add(image);
#else
            var image = section.Headers.Primary.AddImage("../../../../assets/images/MigraDoc.png");
            image.Height             = "3.5cm";
            image.LockAspectRatio    = true;
            image.RelativeVertical   = RelativeVertical.Line;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top              = ShapePosition.Top;
            image.Left             = ShapePosition.Right;
            image.WrapFormat.Style = WrapStyle.Through;
#endif

            // Create the footer.
            var paragraph2 = new MezParagraph("PowerBooks Inc ● Sample Street 42 ● 56789 Cologne ● Germany")
                             .Alignment(ParagraphAlignment.Center).Font(9);
            section.Footers.Primary.Add(paragraph2);

            // Create the text frame for the address.
            _addressFrame                    = section.AddTextFrame();
            _addressFrame.Height             = "3.0cm";
            _addressFrame.Width              = "7.0cm";
            _addressFrame.Left               = ShapePosition.Left;
            _addressFrame.RelativeHorizontal = RelativeHorizontal.Margin;
            _addressFrame.Top                = "5.0cm";
            _addressFrame.RelativeVertical   = RelativeVertical.Page;

            // Show the sender in the address frame.
            new MezParagraph(_addressFrame.AddParagraph("PowerBooks Inc · Sample Street 42 · 56789 Cologne"))
            .Font(7).Bold(true).SpaceAfter(3);

            _document.AddParagraph().LineSpacingRule(LineSpacingRule.Exactly).LineSpacing("5.25cm");

            // Add the print date field.
            _document.AddParagraph()
            // We use SpaceBefore to move the first text line below the address field.
            .SpaceBefore(0)
            .Style("Reference")
            .AddFormattedText(new MezFormattedText("INVOICE").Bold(true))
            .AddTab()
            .AddText("Cologne, ")
            .AddDateField("dd.MM.yyyy");

            // Create the item table.
            _table = _document.AddTable("1cm;C|2.5cm;R|3cm;R|3.5cm;R|2cm;C|4cm;R")
                     .Style("Table")
                     .BorderColor(TableBorder)
                     .BorderWidth(0.25)
                     .BorderLeft(0.5)
                     .BorderRight(0.5)
                     .LeftIndent(0);

            //// Before you can add a row, you must define the columns.
            //var column = _table.AddColumn("1cm");
            //column.Format.Alignment = ParagraphAlignment.Center;

            //column = _table.AddColumn("2.5cm");
            //column.Format.Alignment = ParagraphAlignment.Right;

            //column = _table.AddColumn("3cm");
            //column.Format.Alignment = ParagraphAlignment.Right;

            //column = _table.AddColumn("3.5cm");
            //column.Format.Alignment = ParagraphAlignment.Right;

            //column = _table.AddColumn("2cm");
            //column.Format.Alignment = ParagraphAlignment.Center;

            //column = _table.AddColumn("4cm");
            //column.Format.Alignment = ParagraphAlignment.Right;

            // Create the header of the table.
            var row = _document.AddRow(new MezParagraph("Item") /*.Bold(true).Alignment(ParagraphAlignment.Left)*/,
                                       new MezParagraph("Title and Author") /*.Alignment(ParagraphAlignment.Left)*/,
                                       null, null, null,
                                       new MezParagraph("Extended Price") /*.Alignment(ParagraphAlignment.Left)*/)
                      .Heading(true)
                      .Alignment(ParagraphAlignment.Center)
                      .Bold(true)
                      .ShadingColor(TableBlue);

            // Special settings not yet covered by MEZ.
            row.Row.Cells[0].Format.Font.Bold  = false;
            row.Row.Cells[0].Format.Alignment  = ParagraphAlignment.Left;
            row.Row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom;
            row.Row.Cells[0].MergeDown         = 1;
            row.Row.Cells[1].Format.Alignment  = ParagraphAlignment.Left;
            row.Row.Cells[1].MergeRight        = 3;
            row.Row.Cells[5].Format.Alignment  = ParagraphAlignment.Left;
            row.Row.Cells[5].VerticalAlignment = VerticalAlignment.Bottom;
            row.Row.Cells[5].MergeDown         = 1;

            row = _document.AddRow(null,
                                   new MezParagraph("Quantity") /*.Alignment(ParagraphAlignment.Left)*/,
                                   new MezParagraph("Unit Price") /*.Alignment(ParagraphAlignment.Left)*/,
                                   new MezParagraph("Discount (%)") /*.Alignment(ParagraphAlignment.Left)*/,
                                   new MezParagraph("Taxable") /*.Alignment(ParagraphAlignment.Left)*/,
                                   null)
                  .Heading(true)
                  .Alignment(ParagraphAlignment.Center)
                  .Bold(true)
                  .ShadingColor(TableBlue);
            row.Row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row.Row.Cells[2].Format.Alignment = ParagraphAlignment.Left;
            row.Row.Cells[3].Format.Alignment = ParagraphAlignment.Left;
            row.Row.Cells[4].Format.Alignment = ParagraphAlignment.Left;

            _table.Table.SetEdge(0, 0, 6, 2, Edge.Box, BorderStyle.Single, 0.75, Color.Empty);
        }