示例#1
0
文件: test-687.cs 项目: nobled/mono
	public static int Main()
	{
		XUnit xunit = new XUnit();
		Unit unit = new Unit();
		Unit uu = unit + xunit;
		unit += xunit;
		return 0;
	}
示例#2
0
 public static void DrawImage(XGraphics gfx, XImage image, XUnit x, XUnit y, XUnit width, XUnit height)
 {
     gfx.DrawImage(image, x, y, width, height);
 }
示例#3
0
 internal FormattedCell(Cell cell, DocumentRenderer documentRenderer, Borders cellBorders, FieldInfos fieldInfos, XUnit xOffset, XUnit yOffset)
 {
     this.cell             = cell;
     this.fieldInfos       = fieldInfos;
     this.yOffset          = yOffset;
     this.xOffset          = xOffset;
     this.bordersRenderer  = new BordersRenderer(cellBorders, null);
     this.documentRenderer = documentRenderer;
 }
示例#4
0
        private void DrawLine(float begxmm, float endxmm, float fromtopmm)
        {
            XPen pen = new XPen(XColors.Black, 1);

            pen.LineCap  = XLineCap.Round;
            pen.LineJoin = XLineJoin.Bevel;
            XPoint[] points =
                new XPoint[] { new XPoint(XUnit.FromMillimeter(begxmm).Point, XUnit.FromMillimeter(fromtopmm).Point), new XPoint(XUnit.FromMillimeter(endxmm).Point, XUnit.FromMillimeter(fromtopmm).Point) };
            gfx.DrawLines(pen, points);
        }
示例#5
0
 internal VerticalLineInfo(XUnit height, XUnit descent, XUnit inherentlineSpace)
 {
     Height            = height;
     Descent           = descent;
     InherentlineSpace = inherentlineSpace;
 }
        /// <summary>
        /// Demonstrates serveral bar code types.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            XRect rc;

            base.RenderPage(gfx);

            Graphics grfx = gfx.Internals.Graphics;

            Code2of5Interleaved bc25 = new Code2of5Interleaved();

            bc25.Text = "123456";
            bc25.Size = new XSize(90, 30);
            //bc25.Direction = BarCodeDirection.RightToLeft;
            bc25.TextLocation = TextLocation.Above;
            gfx.DrawBarCode(bc25, XBrushes.DarkBlue, new XPoint(100, 100));

            CodeDataMatrix dm = new CodeDataMatrix("test", 26);

            dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15));
            gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 100));

            rc = new XRect(30, 200, XUnit.FromCentimeter(9.3) + XUnit.FromMillimeter(0.5), XUnit.FromMillimeter(6));
            gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(128, XColors.LightSeaGreen)), rc);

            CodeOmr omr = new CodeOmr(0xF8F5FF3F.ToString(), rc.Size, CodeDirection.LeftToRight);

            omr.MakerDistance  = XUnit.FromMillimeter(3);
            omr.MakerThickness = XUnit.FromMillimeter(0.5);
            gfx.DrawBarCode(omr, XBrushes.Black, rc.Center);

            omr.Direction = CodeDirection.RightToLeft;
            gfx.DrawBarCode(omr, XBrushes.Black, rc.Center + new XSize(0, 50));

            omr.Direction = CodeDirection.RightToLeft;
            gfx.DrawBarCode(omr, XBrushes.Black, rc.Center + new XSize(0, 50));

            omr.Direction = CodeDirection.TopToBottom;
            gfx.DrawBarCode(omr, XBrushes.Black, rc.Center + new XSize(300, 25));
        }
示例#7
0
        public void GeneratePDF(IItemsSoldReportData sales, string outputPath)
        {
            PdfDocument document  = new PdfDocument();
            var         titleWord = sales.IsDailyReport() ? "Daily" : "Weekly";

            document.Info.Title = titleWord + " Inventory Sold Report -- " + sales.GetDate().ToString("yyyy-MM-dd");

            PdfPage page = document.AddPage();

            page.Size = PdfSharp.PageSize.A4;

            XUnit     margin = XUnit.FromInch(1);
            XGraphics gfx    = XGraphics.FromPdfPage(page);

            AddTitle(sales, margin, page, gfx);
            int pageNumber = 1;

            DrawPageNumber(pageNumber, margin, page, gfx);

            XUnit yCoord = margin + XUnit.FromInch(1.3);

            // draw headers
            DrawHeaders(yCoord, margin, gfx);

            XUnit xCoord              = margin;
            XFont itemFont            = new XFont("Segoe UI", 14, XFontStyle.Regular);
            XFont itemDescriptionFont = new XFont("Segoe UI", 12, XFontStyle.Regular);

            //for (int i = 0; i < 40; i++) // for creating lots of PDF dummy data
            //{
            foreach (ReportItemSold itemSold in sales.GetItemsSold())
            {
                if (yCoord + XUnit.FromInch(0.6) >= page.Height - margin)
                {
                    page      = document.AddPage();
                    page.Size = PdfSharp.PageSize.A4;
                    gfx       = XGraphics.FromPdfPage(page);
                    AddTitle(sales, margin, page, gfx);
                    DrawPageNumber(++pageNumber, margin, page, gfx);
                    yCoord = margin + XUnit.FromInch(1.3);
                    DrawHeaders(yCoord, margin, gfx);
                }
                yCoord += XUnit.FromInch(0.5);
                xCoord  = margin;
                // these could be centered nicely or something, but *shrug*
                if (string.IsNullOrWhiteSpace(itemSold.Description))
                {
                    gfx.DrawString(itemSold.Name, itemFont, XBrushes.Black,
                                   new XRect(xCoord, yCoord, XUnit.FromInch(0), XUnit.FromInch(0.25)), XStringFormats.CenterLeft);
                }
                else
                {
                    gfx.DrawString(itemSold.Name, itemFont, XBrushes.Black, new XPoint(xCoord, yCoord), XStringFormats.CenterLeft);
                    gfx.DrawString(itemSold.Description, itemDescriptionFont, XBrushes.Black,
                                   new XPoint(xCoord, yCoord + XUnit.FromInch(0.25)), XStringFormats.CenterLeft);
                }
                xCoord += XUnit.FromInch(2.5);
                gfx.DrawString(itemSold.QuantityPurchased.ToString(), itemFont, XBrushes.Black,
                               new XRect(xCoord + XUnit.FromInch(0.65), yCoord, XUnit.FromInch(0), XUnit.FromInch(.25)), XStringFormats.CenterRight);
                //new XPoint(xCoord + XUnit.FromInch(0.65), yCoord), XStringFormats.CenterRight);
                xCoord += XUnit.FromInch(1.5);
                gfx.DrawString(itemSold.TotalCostWithCurrency, itemFont, XBrushes.Black,
                               //new XPoint(xCoord + XUnit.FromInch(0.85), yCoord), XStringFormats.CenterRight);
                               new XRect(xCoord + XUnit.FromInch(0.85), yCoord, XUnit.FromInch(0), XUnit.FromInch(.25)), XStringFormats.CenterRight);
                xCoord += XUnit.FromInch(1.5);
                gfx.DrawString(itemSold.TotalProfitWithCurrency, itemFont, XBrushes.Black,
                               //new XPoint(page.Width - margin - XUnit.FromInch(0.05), yCoord), XStringFormats.CenterRight);
                               new XRect(page.Width - margin - XUnit.FromInch(0.05), yCoord, XUnit.FromInch(0), XUnit.FromInch(.25)), XStringFormats.CenterRight);

                XUnit yCoordForLine = XUnit.FromInch(0.38);
                gfx.DrawLine(XPens.Black, margin, yCoord + yCoordForLine, page.Width - margin, yCoord + yCoordForLine);
            }
            //}
            yCoord += XUnit.FromInch(0.15);
            // print category totals
            var itemTypeMoneyInfoList = sales.GetItemTypeMoneyInfo();

            foreach (var moneyInfo in itemTypeMoneyInfoList)
            {
                if (yCoord + XUnit.FromInch(0.5) >= page.Height - margin)
                {
                    // GOTTA AADDDDDD A NEWWWW PAGEEE....
                    page      = document.AddPage();
                    page.Size = PdfSharp.PageSize.A4;
                    gfx       = XGraphics.FromPdfPage(page);
                    AddTitle(sales, margin, page, gfx);
                    DrawPageNumber(++pageNumber, margin, page, gfx);
                    yCoord = margin + XUnit.FromInch(1.3);
                    DrawHeaders(yCoord, margin, gfx);
                }
                yCoord += XUnit.FromInch(0.5);
                XFont totalCategoryFont     = new XFont("Segoe UI", 14, XFontStyle.Bold);
                XFont totalCategoryDataFont = new XFont("Segoe UI", 14, XFontStyle.Bold);
                xCoord = margin;
                gfx.DrawString(moneyInfo.Type.Name + " total", totalCategoryFont, XBrushes.Black, new XPoint(xCoord, yCoord), XStringFormats.CenterLeft);
                xCoord += XUnit.FromInch(2.5);
                gfx.DrawString(moneyInfo.TotalItemsSold.ToString(), totalCategoryDataFont, XBrushes.Black,
                               new XPoint(xCoord + XUnit.FromInch(0.65), yCoord), XStringFormats.CenterRight);
                xCoord += XUnit.FromInch(1.5);
                gfx.DrawString(moneyInfo.TotalIncomeWithCurrency.ToString(), totalCategoryDataFont, XBrushes.Black,
                               new XPoint(xCoord + XUnit.FromInch(0.85), yCoord), XStringFormats.CenterRight);
                xCoord += XUnit.FromInch(1.5);
                gfx.DrawString(moneyInfo.TotalProfitWithCurrency.ToString(), totalCategoryDataFont, XBrushes.Black,
                               new XPoint(page.Width - margin - XUnit.FromInch(0.05), yCoord), XStringFormats.CenterRight);
            }
            // print totals
            if (yCoord + XUnit.FromInch(0.5) >= page.Height - margin)
            {
                // GOTTA AADDDDDD A NEWWWW PAGEEE....
                page      = document.AddPage();
                page.Size = PdfSharp.PageSize.A4;
                gfx       = XGraphics.FromPdfPage(page);
                AddTitle(sales, margin, page, gfx);
                DrawPageNumber(++pageNumber, margin, page, gfx);
                yCoord = margin + XUnit.FromInch(1.3);
                DrawHeaders(yCoord, margin, gfx);
            }
            yCoord += XUnit.FromInch(0.5);
            XFont totalFont     = new XFont("Segoe UI", 16, XFontStyle.Bold);
            XFont totalDataFont = new XFont("Segoe UI", 14, XFontStyle.Bold);

            xCoord = margin;
            gfx.DrawString("TOTAL", totalFont, XBrushes.Black, new XPoint(xCoord, yCoord), XStringFormats.CenterLeft);
            xCoord += XUnit.FromInch(2.5);
            gfx.DrawString(sales.GetTotalItemsSold().ToString(), totalDataFont, XBrushes.Black,
                           new XPoint(xCoord + XUnit.FromInch(0.65), yCoord), XStringFormats.CenterRight);
            xCoord += XUnit.FromInch(1.5);
            gfx.DrawString(sales.GetTotalIncomeWithCurrency(), totalDataFont, XBrushes.Black,
                           new XPoint(xCoord + XUnit.FromInch(0.85), yCoord), XStringFormats.CenterRight);
            xCoord += XUnit.FromInch(1.5);
            gfx.DrawString(sales.GetTotalProfitWithCurrency(), totalDataFont, XBrushes.Black,
                           new XPoint(page.Width - margin - XUnit.FromInch(0.05), yCoord), XStringFormats.CenterRight);


            // save the document and start the process for viewing the pdf
            document.Save(outputPath);
            Process.Start(outputPath);
        }
示例#8
0
 /// <summary>
 /// Initializes a new instance of the Font class with the specified name and size.
 /// </summary>
 public Font(string name, XUnit size)
     : this()
 {
     _name = name;
     _size = size;
 }
示例#9
0
        /// <summary>
        ///   Formats (measures) the table.
        /// </summary>
        /// <param name="area"> The area on which to fit the table. </param>
        /// <param name="previousFormatInfo"> </param>
        internal override void Format(Area area, FormatInfo previousFormatInfo)
        {
            DocumentElements elements = DocumentRelations.GetParent(_table) as DocumentElements;

            if (elements != null)
            {
                Section section = DocumentRelations.GetParent(elements) as Section;
                if (section != null)
                {
                    _doHorizontalBreak = section.PageSetup.HorizontalPageBreak;
                }
            }

            _renderInfo = new TableRenderInfo();
            InitFormat(area, previousFormatInfo);

            // Don't take any Rows higher then MaxElementHeight
            XUnit topHeight   = CalcStartingHeight();
            XUnit probeHeight = topHeight;
            XUnit offset;

            if (_startRow > _lastHeaderRow + 1 &&
                _startRow < _table.Rows.Count)
            {
                offset = _bottomBorderMap[_startRow] - topHeight;
            }
            else
            {
                offset = -CalcMaxTopBorderWidth(0);
            }

            int   probeRow       = _startRow;
            XUnit currentHeight  = 0;
            XUnit startingHeight = 0;
            bool  isEmpty        = false;

            while (probeRow < _table.Rows.Count)
            {
                bool firstProbe = probeRow == _startRow;
                probeRow = _connectedRowsMap[probeRow];
                // Don't take any Rows higher then MaxElementHeight
                probeHeight = _bottomBorderMap[probeRow + 1] - offset;
                // First test whether MaxElementHeight has been set.
                if (MaxElementHeight > 0 && firstProbe && probeHeight > MaxElementHeight - Tolerance)
                {
                    probeHeight = MaxElementHeight - Tolerance;
                }
                //if (firstProbe && probeHeight > MaxElementHeight - Tolerance)
                //    probeHeight = MaxElementHeight - Tolerance;

                //The height for the first new row(s) + headerrows:
                if (startingHeight == 0)
                {
                    if (probeHeight > area.Height)
                    {
                        isEmpty = true;
                        break;
                    }
                    startingHeight = probeHeight;
                }

                if (probeHeight > area.Height)
                {
                    break;
                }

                else
                {
                    _currRow      = probeRow;
                    currentHeight = probeHeight;
                    ++probeRow;
                }
            }
            if (!isEmpty)
            {
                TableFormatInfo formatInfo = (TableFormatInfo)_renderInfo.FormatInfo;
                formatInfo.StartRow  = _startRow;
                formatInfo._isEnding = _currRow >= _table.Rows.Count - 1;
                formatInfo.EndRow    = _currRow;
            }
            FinishLayoutInfo(area, currentHeight, startingHeight);
        }
示例#10
0
        public override void StrokePath(double strokeWidth, int color)
        {
            var pen = new XPen(XColor.FromArgb(color), XUnit.FromPoint(strokeWidth).Millimeter);

            XGraphics.DrawPath(pen, CurrentPath);
        }
示例#11
0
            protected void ProduceResponse(HttpContext context, ITypeAccepter accepter, string title, RenderContext ctx, Size tileSize,
                                           AbstractMatrix transform,
                                           bool transparent = false, IDictionary <string, object> queryDefaults = null)
            {
                // New-style Options

                #region URL Parameters
                // TODO: move to ParseOptions (maybe - requires options to be parsed after stylesheet creation?)
                if (GetBoolOption("sscoords", queryDefaults: queryDefaults, defaultValue: false))
                {
                    ctx.Styles.hexCoordinateStyle = HexCoordinateStyle.Subsector;
                }

                if (GetBoolOption("allhexes", queryDefaults: queryDefaults, defaultValue: false))
                {
                    ctx.Styles.numberAllHexes = true;
                }

                if (GetBoolOption("nogrid", queryDefaults: queryDefaults, defaultValue: false))
                {
                    ctx.Styles.parsecGrid.visible = false;
                }

                if (!GetBoolOption("routes", queryDefaults: queryDefaults, defaultValue: true))
                {
                    ctx.Styles.macroRoutes.visible = false;
                    ctx.Styles.microRoutes.visible = false;
                }

                if (!GetBoolOption("rifts", queryDefaults: queryDefaults, defaultValue: true))
                {
                    ctx.Styles.showRiftOverlay = false;
                }

                if (GetBoolOption("po", queryDefaults: queryDefaults, defaultValue: false))
                {
                    ctx.Styles.populationOverlay.visible = true;
                }

                if (GetBoolOption("im", queryDefaults: queryDefaults, defaultValue: false))
                {
                    ctx.Styles.importanceOverlay.visible = true;
                }

                if (GetBoolOption("cp", queryDefaults: queryDefaults, defaultValue: false))
                {
                    ctx.Styles.capitalOverlay.visible = true;
                }

                if (GetBoolOption("stellar", queryDefaults: queryDefaults, defaultValue: false))
                {
                    ctx.Styles.showStellarOverlay = true;
                }

                ctx.Styles.dimUnofficialSectors    = GetBoolOption("dimunofficial", queryDefaults: queryDefaults, defaultValue: false);
                ctx.Styles.colorCodeSectorStatus   = GetBoolOption("review", queryDefaults: queryDefaults, defaultValue: false);
                ctx.Styles.droyneWorlds.visible    = GetBoolOption("dw", queryDefaults: queryDefaults, defaultValue: false);
                ctx.Styles.minorHomeWorlds.visible = GetBoolOption("mh", queryDefaults: queryDefaults, defaultValue: false);
                ctx.Styles.ancientsWorlds.visible  = GetBoolOption("an", queryDefaults: queryDefaults, defaultValue: false);

                // TODO: Return an error if pattern is invalid?
                ctx.Styles.highlightWorldsPattern = HighlightWorldPattern.Parse(
                    GetStringOption("hw", queryDefaults: queryDefaults, defaultValue: String.Empty).Replace(' ', '+'));
                ctx.Styles.highlightWorlds.visible = ctx.Styles.highlightWorldsPattern != null;

                double devicePixelRatio = GetDoubleOption("dpr", defaultValue: 1, queryDefaults: queryDefaults);
                if (devicePixelRatio <= 0)
                {
                    devicePixelRatio = 1;
                }

                bool dataURI = GetBoolOption("datauri", queryDefaults: queryDefaults, defaultValue: false);

                if (GetStringOption("milieu", SectorMap.DEFAULT_MILIEU) != SectorMap.DEFAULT_MILIEU)
                {
                    // TODO: Make this declarative in resource files.
                    if (ctx.Styles.macroBorders.visible)
                    {
                        ctx.Styles.macroBorders.visible = false;
                        ctx.Styles.microBorders.visible = true;
                    }
                    ctx.Styles.macroNames.visible  = false;
                    ctx.Styles.macroRoutes.visible = false;
                }
                #endregion

                MemoryStream ms = null;
                if (dataURI)
                {
                    ms = new MemoryStream();
                }
                Stream outputStream = ms ?? Context.Response.OutputStream;

                if (accepter.Accepts(context, ContentTypes.Image.Svg, ignoreHeaderFallbacks: true))
                {
                    #region SVG Generation
                    using (var svg = new SVGGraphics(tileSize.Width, tileSize.Height))
                    {
                        RenderToGraphics(ctx, transform, svg);

                        using (var stream = new MemoryStream())
                        {
                            svg.Serialize(new StreamWriter(stream));
                            context.Response.ContentType = ContentTypes.Image.Svg;
                            if (!dataURI)
                            {
                                context.Response.AddHeader("content-length", stream.Length.ToString());
                                context.Response.AddHeader("content-disposition", "inline;filename=\"map.svg\"");
                            }
                            stream.WriteTo(outputStream);
                        }
                    }
                    #endregion
                }

                else if (accepter.Accepts(context, ContentTypes.Application.Pdf, ignoreHeaderFallbacks: true))
                {
                    #region PDF Generation
                    using (var document = new PdfDocument())
                    {
                        document.Version       = 14; // 1.4 for opacity
                        document.Info.Title    = title;
                        document.Info.Author   = "Joshua Bell";
                        document.Info.Creator  = "TravellerMap.com";
                        document.Info.Subject  = DateTime.Now.ToString("F", CultureInfo.InvariantCulture);
                        document.Info.Keywords = "The Traveller game in all forms is owned by Far Future Enterprises. Copyright (C) 1977 - 2017 Far Future Enterprises. Traveller is a registered trademark of Far Future Enterprises.";

                        // TODO: Credits/Copyright
                        // This is close, but doesn't define the namespace correctly:
                        // document.Info.Elements.Add( new KeyValuePair<string, PdfItem>( "/photoshop/Copyright", new PdfString( "HelloWorld" ) ) );

                        PdfPage page = document.AddPage();

                        // NOTE: only PageUnit currently supported in MGraphics is Points
                        page.Width  = XUnit.FromPoint(tileSize.Width);
                        page.Height = XUnit.FromPoint(tileSize.Height);

                        using (var gfx = new PdfSharpGraphics(XGraphics.FromPdfPage(page)))
                        {
                            RenderToGraphics(ctx, transform, gfx);

                            using (var stream = new MemoryStream())
                            {
                                document.Save(stream, closeStream: false);
                                context.Response.ContentType = ContentTypes.Application.Pdf;
                                if (!dataURI)
                                {
                                    context.Response.AddHeader("content-length", stream.Length.ToString());
                                    context.Response.AddHeader("content-disposition", "inline;filename=\"map.pdf\"");
                                }
                                stream.WriteTo(outputStream);
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region Bitmap Generation
                    int width  = (int)Math.Floor(tileSize.Width * devicePixelRatio);
                    int height = (int)Math.Floor(tileSize.Height * devicePixelRatio);
                    using (var bitmap = TryConstructBitmap(width, height, PixelFormat.Format32bppArgb))
                    {
                        if (bitmap == null)
                        {
                            throw new HttpError(500, "Internal Server Error",
                                                $"Failed to allocate bitmap ({width}x{height}). Insufficient memory?");
                        }

                        if (transparent)
                        {
                            bitmap.MakeTransparent();
                        }

                        using (var g = System.Drawing.Graphics.FromImage(bitmap))
                        {
                            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

                            using (var graphics = new BitmapGraphics(g))
                            {
                                graphics.ScaleTransform((float)devicePixelRatio);
                                RenderToGraphics(ctx, transform, graphics);
                            }
                        }

                        BitmapResponse(context.Response, outputStream, ctx.Styles, bitmap, transparent ? ContentTypes.Image.Png : null);
                    }
                    #endregion
                }

                if (dataURI)
                {
                    string contentType = context.Response.ContentType;
                    context.Response.ContentType = ContentTypes.Text.Plain;
                    ms.Seek(0, SeekOrigin.Begin);

                    context.Response.Output.Write("data:");
                    context.Response.Output.Write(contentType);
                    context.Response.Output.Write(";base64,");
                    context.Response.Output.Flush();

                    System.Security.Cryptography.ICryptoTransform encoder = new System.Security.Cryptography.ToBase64Transform();
                    using (System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(context.Response.OutputStream, encoder, System.Security.Cryptography.CryptoStreamMode.Write))
                    {
                        ms.WriteTo(cs);
                        cs.FlushFinalBlock();
                    }
                }

                context.Response.Flush();
                context.Response.Close();
                return;
            }
示例#12
0
        private void Page1(PdfDocument document, int pageNum)
        {
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            // Unicode hack
            gfx.MUH = PdfFontEncoding.Unicode;

            // Get the A4 page size
            Unit width, height;

            PageSetup.GetPageSize(PageFormat.A4, out width, out height);

            XFont font = new XFont("Verdana", 13, XFontStyle.Bold);

            // You always need a MigraDoc document for rendering.
            Document doc = new Document();

            // Add a section to the document and configure it such
            // that it will be in the center of the page
            Section section = doc.AddSection();

            section.PageSetup.PageHeight  = height;
            section.PageSetup.PageWidth   = width;
            section.PageSetup.LeftMargin  = 0;
            section.PageSetup.RightMargin = 0;
            section.PageSetup.TopMargin   = 20;

            // Add a top paragraph with date
            Paragraph para = section.AddParagraph();

            para.Format.Alignment  = ParagraphAlignment.Right;
            para.Format.Font.Name  = "Times New Roman";
            para.Format.Font.Size  = 12;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            para.AddFormattedText(dateTimePicker1.Value.Date.ToString("dddd, d MMMM yyyy"), TextFormat.Bold);

            // Add a bottom paragraph with page number
            Paragraph pg = section.AddParagraph();

            pg.Format.Alignment  = ParagraphAlignment.Right;
            pg.Format.Font.Name  = "Times New Roman";
            pg.Format.Font.Size  = 12;
            pg.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            pg.AddFormattedText("Page " + pageNum, TextFormat.Bold);

            // Create a table
            Table table = new Table();

            table.Borders.Visible = true;
            table.Borders.Width   = 1; // Default to show borders 1 pixel wide Column
            table.TopPadding      = 5;
            table.BottomPadding   = 5;

            Column column = table.AddColumn(40);

            column.Format.Alignment = ParagraphAlignment.Left;

            column = table.AddColumn(150);
            column.Format.Alignment = ParagraphAlignment.Left;

            column = table.AddColumn(120);
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(120);
            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(80);
            column.Format.Alignment = ParagraphAlignment.Center;

            table.Rows.Height = 20;

            Row row = table.AddRow();

            row.Shading.Color     = Colors.PaleGoldenrod;
            row.VerticalAlignment = VerticalAlignment.Top;

            // Table header
            row.Cells[0].AddParagraph("#");
            row.Cells[1].AddParagraph("Name");
            row.Cells[2].AddParagraph("Start");
            row.Cells[3].AddParagraph("End");
            row.Cells[4].AddParagraph("Duration");

            // Define the last row number on the current page
            int lastNum;

            if (rowNum >= pageNum * rowsPerPage)
            {
                lastNum = pageNum * rowsPerPage;
            }
            else
            {
                lastNum = rowNum;
            }

            // Put the rows into the table
            for (int i = 1 + (pageNum - 1) * rowsPerPage; i <= lastNum; i++)
            {
                DataRow dr = dt.Rows[i - 1];
                row = table.AddRow();
                row.Cells[0].AddParagraph(i.ToString());
                row.Cells[1].AddParagraph(dr["name"].ToString());
                row.Cells[2].AddParagraph(dr["start"].ToString());
                row.Cells[3].AddParagraph(dr["end"].ToString());
                row.Cells[4].AddParagraph(dr["duration"].ToString());
            }

            table.SetEdge(0, 0, 5, 1, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.Black);

            doc.LastSection.Add(table);

            // Create a renderer and prepare (=layout) the document
            MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(10), XUnit.FromCentimeter(1), "10cm", para);
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(2), XUnit.FromCentimeter(2), "12cm", table);
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(10), XUnit.FromCentimeter(28), "10cm", pg);
        }
示例#13
0
        /// <summary>
        /// Formats the elements on the areas provided by the area provider.
        /// </summary>
        /// <param name="gfx">The graphics object to render on.</param>
        /// <param name="topLevel">if set to <c>true</c> formats the object is on top level.</param>
        public void FormatOnAreas(XGraphics gfx, bool topLevel)
        {
            this.gfx = gfx;
            XUnit      prevBottomMargin = 0;
            XUnit      yPos             = prevBottomMargin;
            RenderInfo prevRenderInfo   = null;
            FormatInfo prevFormatInfo   = null;
            ArrayList  renderInfos      = new ArrayList();
            bool       ready            = this.elements.Count == 0;
            bool       isFirstOnPage    = true;
            Area       area             = this.areaProvider.GetNextArea();
            XUnit      maxHeight        = area.Height;

            if (ready)
            {
                this.areaProvider.StoreRenderInfos(renderInfos);
                return;
            }
            int idx = 0;

            while (!ready && area != null)
            {
                DocumentObject docObj   = this.elements[idx];
                Renderer       renderer = Renderer.Create(gfx, this.documentRenderer, docObj, this.areaProvider.AreaFieldInfos);
                if (renderer != null) // "Slightly hacked" for legends: see below
                {
                    renderer.MaxElementHeight = maxHeight;
                }

                if (topLevel && this.documentRenderer.HasPrepareDocumentProgress)
                {
                    this.documentRenderer.OnPrepareDocumentProgress(this.documentRenderer.ProgressCompleted + idx + 1,
                                                                    this.documentRenderer.ProgressMaximum);
                }

                // "Slightly hacked" for legends: they are rendered as part of the chart.
                // So they are skipped here.
                if (renderer == null)
                {
                    ready = idx == this.elements.Count - 1;
                    if (ready)
                    {
                        this.areaProvider.StoreRenderInfos(renderInfos);
                    }
                    ++idx;
                    continue;
                }
                ///////////////////////////////////////////
                if (prevFormatInfo == null)
                {
                    LayoutInfo initialLayoutInfo = renderer.InitialLayoutInfo;
                    XUnit      distance          = prevBottomMargin;
                    if (initialLayoutInfo.VerticalReference == VerticalReference.PreviousElement &&
                        initialLayoutInfo.Floating != Floating.None) //Added KlPo 12.07.07
                    {
                        distance = MarginMax(initialLayoutInfo.MarginTop, distance);
                    }

                    area = area.Lower(distance);
                }
                renderer.Format(area, prevFormatInfo);
                this.areaProvider.PositionHorizontally(renderer.RenderInfo.LayoutInfo);
                bool pagebreakBefore = this.areaProvider.IsAreaBreakBefore(renderer.RenderInfo.LayoutInfo) && !isFirstOnPage;
                pagebreakBefore = pagebreakBefore || !isFirstOnPage && IsForcedAreaBreak(idx, renderer, area);

                if (!pagebreakBefore && renderer.RenderInfo.FormatInfo.IsEnding)
                {
                    if (PreviousRendererNeedsRemoveEnding(prevRenderInfo, renderer.RenderInfo, area))
                    {
                        prevRenderInfo.RemoveEnding();
                        renderer = Renderer.Create(gfx, this.documentRenderer, docObj, this.areaProvider.AreaFieldInfos);
                        renderer.MaxElementHeight = maxHeight;
                        renderer.Format(area, prevRenderInfo.FormatInfo);
                    }
                    else if (NeedsEndingOnNextArea(idx, renderer, area, isFirstOnPage))
                    {
                        renderer.RenderInfo.RemoveEnding();
                        prevRenderInfo = FinishPage(renderer.RenderInfo, pagebreakBefore, ref renderInfos);
                        if (prevRenderInfo != null)
                        {
                            prevFormatInfo = prevRenderInfo.FormatInfo;
                        }
                        else
                        {
                            prevFormatInfo = null;
                            isFirstOnPage  = true;
                        }
                        prevBottomMargin = 0;
                        area             = this.areaProvider.GetNextArea();
                        maxHeight        = area.Height;
                    }
                    else
                    {
                        renderInfos.Add(renderer.RenderInfo);
                        isFirstOnPage = false;
                        areaProvider.PositionVertically(renderer.RenderInfo.LayoutInfo);
                        if (renderer.RenderInfo.LayoutInfo.VerticalReference == VerticalReference.PreviousElement &&
                            renderer.RenderInfo.LayoutInfo.Floating != Floating.None)//Added KlPo 12.07.07
                        {
                            prevBottomMargin = renderer.RenderInfo.LayoutInfo.MarginBottom;
                            if (renderer.RenderInfo.LayoutInfo.Floating != Floating.None)
                            {
                                area = area.Lower(renderer.RenderInfo.LayoutInfo.ContentArea.Height);
                            }
                        }
                        else
                        {
                            prevBottomMargin = 0;
                        }

                        prevFormatInfo = null;
                        prevRenderInfo = null;

                        ++idx;
                    }
                }
                else
                {
                    if (renderer.RenderInfo.FormatInfo.IsEmpty && isFirstOnPage)
                    {
                        area = area.Unite(new Rectangle(area.X, area.Y, area.Width, double.MaxValue));

                        renderer = Renderer.Create(gfx, this.documentRenderer, docObj, this.areaProvider.AreaFieldInfos);
                        renderer.MaxElementHeight = maxHeight;
                        renderer.Format(area, prevFormatInfo);
                        prevFormatInfo = null;

                        //Added KlPo 12.07.07
                        this.areaProvider.PositionHorizontally(renderer.RenderInfo.LayoutInfo);
                        this.areaProvider.PositionVertically(renderer.RenderInfo.LayoutInfo);
                        //Added End
                        ready = idx == this.elements.Count - 1;

                        ++idx;
                    }
                    prevRenderInfo = FinishPage(renderer.RenderInfo, pagebreakBefore, ref renderInfos);
                    if (prevRenderInfo != null)
                    {
                        prevFormatInfo = prevRenderInfo.FormatInfo;
                    }
                    else
                    {
                        prevFormatInfo = null;
                    }
                    isFirstOnPage    = true;
                    prevBottomMargin = 0;
#if false
                    area = this.areaProvider.GetNextArea();
#else
                    if (!ready) //!!!newTHHO 19.01.2007: korrekt? oder GetNextArea immer ausführen???
                    {
                        area      = this.areaProvider.GetNextArea();
                        maxHeight = area.Height;
                    }
#endif
                }
                if (idx == this.elements.Count && !ready)
                {
                    this.areaProvider.StoreRenderInfos(renderInfos);
                    ready = true;
                }
            }
        }
示例#14
0
 static double S(double centimeters)
 {
     return(XUnit.FromCentimeter(centimeters).Point);
 }
示例#15
0
        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);
        }
        public static DocumentBuilder AddAfterschoolAgreement(this DocumentBuilder builder)
        {
            var            imageDir    = Path.Combine(Directory.GetCurrentDirectory(), "Content", "Images", "AfterschoolAgreement");
            var            checkboxUrl = Path.Combine(imageDir, "Checkbox.png");
            var            logoUrl     = Path.Combine(imageDir, "SchoolLogo.jpg");
            SectionBuilder section     = builder.AddSection()
                                         .SetSize(PaperSize.Letter)
                                         .SetOrientation(PageOrientation.Portrait);

            // HEADER BLOCK
            section.AddTable()
            .SetContentRowStyleBorder(borderBuilder => borderBuilder.SetStroke(Stroke.None))
            .AddColumnToTable("", 52)
            .AddColumnToTable("", XUnit.FromPercent(40))
            .AddColumnToTable("", XUnit.FromPercent(60))
            .AddRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Left)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddImageToCell(logoUrl, 65, 45, ScalingMode.UserDefined)
            .ToRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Center)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .SetFontSize(12)
            .AddParagraph("AFTERSCHOOL")
            .SetBold()
            .ToCell()
            .AddParagraphToCell("BANK DRAFT FORM")
            .ToRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Center)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddParagraphToCell("REGISTRATION PACKET  PG. 4 of 4")
            .SetBackColor(Color.Black)
            .SetFont(Fonts.Courier(12).SetColor(Color.White).SetBold())
            .ToTable();

            // TITLE BLOCK
            section.AddParagraph("BEST SCHOOL of Twin Peaks ")
            .SetMarginTop(5)
            .SetBold()
            .SetFontColor(Color.Gray)
            .SetFontSize(12)
            .AddText("Afterschool ")
            .SetFontColor(Color.Black)
            .ToParagraph()
            .AddTextToParagraph("Agreement ACH/CC Automatic Payment Option");

            // STEP 1 BLOCK
            section.AddParagraph("STEP #1")
            .SetBackColor(Color.FromRgba(0.3f, 0.3f, 0.3f))
            .SetFont(Fonts.Courier(16).SetColor(Color.White).SetBold());
            section.AddParagraph()
            .SetMarginLeft(0)
            .SetBorderWidth(0)
            .SetFontSize(4)
            .AddTabSymbol()
            .AddTabulationInPercent(100, TabulationType.Right, TabulationLeading.BottomLine);
            section.AddParagraph()
            .SetFontSize(6)
            .AddTextToParagraph("CHILD'S FIRST NAME")
            .AddTabSymbol()
            .AddTextToParagraph("MIDDLE INITIAL")
            .AddTabSymbol()
            .AddTextToParagraph("LAST NAME")
            .AddTabulationInPercent(35, TabulationType.Left)
            .AddTabulationInPercent(65, TabulationType.Left);
            section.AddParagraph()
            .SetMarginLeft(0)
            .SetMarginTop(15)
            .SetBorderWidth(0)
            .SetFontSize(6)
            .AddTabSymbol()
            .AddTabulationInPercent(100, TabulationType.Right, TabulationLeading.BottomLine);
            section.AddParagraph()
            .SetFontSize(6)
            .AddTextToParagraph("PHONE NUMBER (DAY)")
            .AddTabSymbol()
            .AddTextToParagraph("PHONE NUMBER (EVENING)")
            .AddTabulationInPercent(65, TabulationType.Left);
            section.AddParagraph()
            .SetMarginLeft(0)
            .SetMarginTop(15)
            .SetBorderWidth(0)
            .SetFontSize(6)
            .AddTabSymbol()
            .AddTabulationInPercent(100, TabulationType.Right, TabulationLeading.BottomLine);
            section.AddParagraph()
            .SetFontSize(6)
            .AddTextToParagraph("CHILD'S SCHOOL")
            .AddTabSymbol()
            .AddTextToParagraph("CHILD'S ADDRESS")
            .AddTabSymbol()
            .AddTextToParagraph("CITY")
            .AddTabSymbol()
            .AddTextToParagraph("STATE")
            .AddTabSymbol()
            .AddTextToParagraph("ZIP")
            .AddTabulationInPercent(35, TabulationType.Left)
            .AddTabulationInPercent(65, TabulationType.Left)
            .AddTabulationInPercent(77, TabulationType.Left)
            .AddTabulationInPercent(90, TabulationType.Left);
            section.AddParagraph()
            .SetFontSize(6)
            .SetMarginLeft(0)
            .SetMarginTop(15)
            .SetMarginBottom(3)
            .SetBorderWidth(0)
            .AddTabSymbol()
            .AddTabulationInPercent(100, TabulationType.Right, TabulationLeading.BottomLine);

            // STEP 2 AND 3 BLOCKS
            TableBuilder step2And3Table = section.AddTable()
                                          .SetContentRowStyleBorder(borderBuilder => borderBuilder.SetStroke(Stroke.None))
                                          .AddColumnToTable("", XUnit.FromPercent(49))
                                          .AddColumnToTable("", XUnit.FromPercent(2))
                                          .AddColumnToTable("", XUnit.FromPercent(49));

            step2And3Table
            .AddRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Left)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddParagraphToCell("STEP #2")
            .SetPadding(2, 0, 0, 0)
            .SetBackColor(Color.FromRgba(0.3f, 0.3f, 0.3f))
            .SetFont(Fonts.Courier(16).SetColor(Color.White).SetBold())
            .ToRow()
            .AddCellToRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Left)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddParagraphToCell("STEP #3")
            .SetPadding(2, 0, 0, 0)
            .SetBackColor(Color.FromRgba(0.3f, 0.3f, 0.3f))
            .SetFont(Fonts.Courier(16).SetColor(Color.White).SetBold());
            step2And3Table
            .AddRow()
            .AddCell()
            .SetBorder(Stroke.Solid, Color.Black, StyleSheet.DefaultBorderWidth)
            .SetHorizontalAlignment(HorizontalAlignment.Center)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddParagraphToCell("Begin Draft Date:")
            .AddParagraphToCell("_______ / _______ / _______")
            .ToRow()
            .AddCellToRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Center)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddTable()
            .SetHeaderRowStyleBackColor(Color.Gray)
            .AddColumnToTable("", XUnit.FromPercent(70))
            .AddColumnToTable("", XUnit.FromPercent(30))
            .AddRow()
            .AddCell("DRAFT DATES")
            .SetBackColor(Color.Gray)
            .SetFontColor(Color.White)
            .ToRow()
            .AddCell("AMOUNT")
            .SetBackColor(Color.Gray)
            .SetFontColor(Color.White)
            .ToTable()
            .AddRow()
            .SetVerticalAlignment(VerticalAlignment.Bottom)
            .AddCell("Monthly on the 1st")
            .SetFontSize(10)
            .ToRow()
            .AddCell("$")
            .SetBold()
            .ToTable()
            .AddRow()
            .SetVerticalAlignment(VerticalAlignment.Bottom)
            .AddCell("Semi-Monthly on the 1st & 15th")
            .SetFontSize(10)
            .ToRow()
            .AddCell("$")
            .SetBold()
            .ToTable()
            .SetMarginBottom(5);

            // STEP 4 BLOCK
            section.AddParagraph("STEP #4")
            .SetBackColor(Color.FromRgba(0.3f, 0.3f, 0.3f))
            .SetFont(Fonts.Courier(16).SetColor(Color.White).SetBold());
            section.AddTable()
            .SetMarginTop(2)
            .SetContentRowStyleBorder(borderBuilder => borderBuilder.SetStroke(Stroke.None))
            .AddColumnToTable("", XUnit.FromPercent(49))
            .AddColumnToTable("", XUnit.FromPercent(2))
            .AddColumnToTable("", XUnit.FromPercent(49))
            .AddRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Left)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .SetPadding(2, 0, 0, 0)
            .AddParagraph("")
            .AddInlineImageToParagraph(checkboxUrl, 11, 11, ScalingMode.UserDefined)
            .AddTextToParagraph(" OPTION 1: CREDIT/DEBIT CARD")
            .ToCell()
            .SetBackColor(Color.Gray)
            .SetFont(Fonts.Courier(14).SetColor(Color.White).SetBold())
            .ToRow()
            .AddCellToRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Left)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .SetPadding(2, 0, 0, 0)
            .AddParagraph("")
            .AddInlineImageToParagraph(checkboxUrl, 11, 11, ScalingMode.UserDefined)
            .AddTextToParagraph(" OPTION 2: BANK DRAFT")
            .ToCell()
            .SetBackColor(Color.Gray)
            .SetFont(Fonts.Courier(14).SetColor(Color.White).SetBold())
            .ToTable()
            .AddRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Center)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .SetFont(Fonts.Courier(6))
            .AddTable()
            .SetContentRowStyleFont(Fonts.Courier(6))
            .SetDefaultAltRowStyle()
            .AddColumnToTable("", XUnit.FromPercent(65))
            .AddColumnToTable("", XUnit.FromPercent(35))
            .AddRow()
            .AddCell()
            .SetColSpan(2)
            .SetFontSize(8)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddParagraph("Check one:  ")
            .AddInlineImageToParagraph(checkboxUrl, 8, 8, ScalingMode.UserDefined)
            .AddTextToParagraph(" Visa  ")
            .AddInlineImageToParagraph(checkboxUrl, 8, 8, ScalingMode.UserDefined)
            .AddTextToParagraph(" Mastercard  ")
            .AddInlineImageToParagraph(checkboxUrl, 8, 8, ScalingMode.UserDefined)
            .AddTextToParagraph(" Discover  ")
            .AddInlineImageToParagraph(checkboxUrl, 8, 8, ScalingMode.UserDefined)
            .AddTextToParagraph(" AmEx")
            .ToTable()
            .AddRow()
            .AddCell("CREDIT/DEBIT CARD #")
            .AddParagraph("FILL HERE")
            .SetFontColor(Color.White)
            .SetFontSize(16)
            .ToRow()
            .AddCell("EXP. DATE")
            .AddParagraph("FILL HERE")
            .SetFontColor(Color.White)
            .SetFontSize(16)
            .ToTable()
            .AddRow()
            .AddCell("CARDHOLDER NAME")
            .AddParagraph("FILL HERE")
            .SetFontColor(Color.White)
            .SetFontSize(16)
            .ToRow()
            .AddCell("CVV")
            .AddParagraph("FILL HERE")
            .SetFontColor(Color.White)
            .SetFontSize(16)
            .ToTable()
            .ToCell()
            .ToRow()
            .AddCellToRow()
            .AddCell()
            .SetHorizontalAlignment(HorizontalAlignment.Center)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .SetFontSize(6)
            .AddTable()
            .SetContentRowStyleFont(Fonts.Courier(6))
            .SetDefaultAltRowStyle()
            .AddColumnToTable("", XUnit.FromPercent(60))
            .AddColumnToTable("", XUnit.FromPercent(40))
            .AddRow()
            .AddCell("ACCOUNT HOLDER NAME")
            .AddParagraph("FILL HERE")
            .SetFontColor(Color.White)
            .SetFontSize(16)
            .ToRow()
            .AddCell("BANK NAME")
            .AddParagraph("FILL HERE")
            .SetFontColor(Color.White)
            .SetFontSize(16)
            .ToTable()
            .AddRow()
            .AddCell("ROUTING/TRANSIT #")
            .AddParagraph("FILL HERE")
            .SetFontColor(Color.White)
            .SetFontSize(16)
            .ToRow()
            .AddCell("BANK ACCOUNT #")
            .AddParagraph("FILL HERE")
            .SetFontColor(Color.White)
            .SetFontSize(16)
            .ToTable();

            // INFORMATION BLOCK
            section.AddParagraph("AUTOMATED CLEARINGHOUSE(ACH) DRAFTS ARE REQUIRED TO HAVE A VOIDED CHECK. DEBIT CARDS ARE NOT ACCEPTED. MUST BE ACH OR CREDIT CARDS ONLY.")
            .SetMarginTop(10)
            .SetBold()
            .SetFontSize(8);
            section.AddParagraph("Only 1 Form of Draft Payment can be entered per person.")
            .SetListBulleted()
            .SetFontSize(8);
            section.AddParagraph("Children enrolled in Summer Camp may have a larger draft amount on May 15 & Aug 1.")
            .SetListBulleted()
            .SetFontSize(8);
            section.AddParagraphToSection()
            .AddParagraph("I understand that this transfer will occur monthly on the 1st. First draft begins Aug. 1.")
            .SetListNumbered(NumerationStyle.Arabic, 0, 0)
            .SetFontSize(8);
            section.AddParagraph("I understand that should I choose to change a Bank Account I must provide a school with at least a 2 week notice.")
            .SetListNumbered(NumerationStyle.Arabic, 0, 0)
            .SetFontSize(8);
            section.AddParagraph("I understand that the information above will be used to transfer payment from my account.")
            .SetListNumbered(NumerationStyle.Arabic, 0, 0)
            .SetFontSize(8);
            section.AddParagraph("I understand that if my payment is returned for non-sufficient funds I will be charged a $30 fee.")
            .SetListNumbered(NumerationStyle.Arabic, 0, 0)
            .SetFontSize(8);
            section.AddParagraph("BEST SCHOOL only accepts Visa, MasterCard, Discover, and American Express.")
            .SetListNumbered(NumerationStyle.Arabic, 0, 0)
            .SetFontSize(8);
            section.AddParagraph("I understand that after three returned items, I will be ineligible to use the automatic payment option.")
            .SetListNumbered(NumerationStyle.Arabic, 0, 0)
            .SetFontSize(8);
            section.AddParagraph("ACCOUNT HOLDER ACKNOWLEDGMENT")
            .SetMarginTop(5)
            .SetBold();
            section.AddParagraph()
            .SetMarginTop(8)
            .SetMarginLeft(0)
            .SetBorderWidth(0)
            .AddTabSymbol().AddTabulationInPercent(50, TabulationType.Right, TabulationLeading.BottomLine)
            .AddTabSymbol().AddTabSymbol()
            .AddTabulationInPercent(70, TabulationType.Left)
            .AddTabulationInPercent(100, TabulationType.Right, TabulationLeading.BottomLine);
            section.AddParagraph()
            .SetMarginTop(0)
            .SetFontSize(10)
            .AddTabSymbol().AddTextToParagraph("Account Holder Signature")
            .AddTabulationInPercent(25, TabulationType.Center)
            .AddTabSymbol()
            .AddTextToParagraph("Date")
            .AddTabulationInPercent(85, TabulationType.Center);

            // STAPLE BLOCK
            TableBuilder pleaseStapleHereTable = section.AddTable()
                                                 .SetAlignment(HorizontalAlignment.Center)
                                                 .SetWidth(XUnit.FromPercent(80))
                                                 .SetMarginTop(5)
                                                 .SetBorderStroke(Stroke.Dotted)
                                                 .AddColumnToTable("", XUnit.FromPercent(10))
                                                 .AddColumnToTable("", XUnit.FromPercent(80))
                                                 .AddColumnToTable("", XUnit.FromPercent(10));

            pleaseStapleHereTable.AddRow()
            .SetHorizontalAlignment(HorizontalAlignment.Center)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddCell()
            .SetBorderStroke(Stroke.Dotted, Stroke.Dotted, Stroke.None, Stroke.Dotted)
            .SetFontSize(6)
            .AddParagraphToCell("Please").AddParagraphToCell("Staple").AddParagraphToCell("Here")
            .ToRow()
            .AddCell()
            .SetBorderStroke(Stroke.None, Stroke.Dotted, Stroke.None, Stroke.Dotted)
            .SetPadding(0, 68, 0, 64)
            .SetVerticalAlignment(VerticalAlignment.Center)
            .AddParagraph("STAPLE VOIDED CHECK HERE").SetBold().SetFontSize(24)
            .ToRow()
            .AddCell()
            .SetBorderStroke(Stroke.None, Stroke.Dotted, Stroke.Dotted, Stroke.Dotted)
            .SetFontSize(6).AddParagraphToCell("Please").AddParagraphToCell("Staple").AddParagraphToCell("Here")
            .ToSection()
            .SetMargins(20, 20, 20, 0);
            return(builder);
        }
 internal PageInfo(XUnit width, XUnit height, PageOrientation orientation)
 {
     _width       = width;
     _height      = height;
     _orientation = orientation;
 }
示例#18
0
        private void DrawPageNumber(int number, XUnit margin, PdfPage page, XGraphics gfx)
        {
            XFont headerFont = new XFont("Verdana", 10, XFontStyle.Regular);

            gfx.DrawString("-" + number.ToString() + "-", headerFont, XBrushes.Black, new XRect(0, page.Height - margin, page.Width, margin), XStringFormats.Center);
        }
示例#19
0
 public XUnit GetLinePosition(XUnit requestedHeight)
 {
     return GetLinePosition(requestedHeight, -1f);
 }
示例#20
0
        public PdfDocument CreateFirstPage(Candidate model, PdfDocument pdfDocument)
        {
            PdfPage pdfPage = new PdfPage();
            XSize   size    = PageSizeConverter.ToSize(PageSize.A4);

            pdfPage.Orientation = PageOrientation.Portrait;

            pdfPage.Width              = size.Width;
            pdfPage.Height             = size.Height;
            pdfPage.TrimMargins.Top    = 10;
            pdfPage.TrimMargins.Right  = 10;
            pdfPage.TrimMargins.Bottom = 10;
            pdfPage.TrimMargins.Left   = 10;

            pdfDocument.Pages.Add(pdfPage);


            XGraphics gfx = XGraphics.FromPdfPage(pdfPage);

            gfx.MUH  = PdfFontEncoding.Unicode;
            gfx.MFEH = PdfFontEmbedding.Default;


            var document = new Document();
            var section  = document.AddSection();

            section.PageSetup.PageFormat   = PageFormat.A4;
            section.PageSetup.TopMargin    = "5cm";
            section.PageSetup.BottomMargin = "5cm";
            section.PageSetup.RightMargin  = "5cm";
            section.PageSetup.LeftMargin   = "5cm";

            var paragraph = section.AddParagraph();

            paragraph.Format.Alignment    = ParagraphAlignment.Left;
            paragraph.Format.KeepTogether = true;
            paragraph.AddText(model.CandidateProfile.Profile);


            Image image = section.AddImage(@"D:\source\play\pdfgen\pdfgen\portrait-profile-007.jpg");

            image.Height             = "1.5cm";
            image.Width              = "4cm";
            image.LockAspectRatio    = true;
            image.RelativeVertical   = RelativeVertical.Line;
            image.RelativeHorizontal = RelativeHorizontal.Margin;
            image.Top              = ShapePosition.Top;
            image.Left             = ShapePosition.Right;
            image.WrapFormat.Style = WrapStyle.Through;



            PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);

            pdfRenderer.Document = document;
            pdfRenderer.RenderDocument();


            MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(document);
            docRenderer.PrepareDocument();
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(0), XUnit.FromCentimeter(0), "18cm", paragraph);

            return(pdfDocument);
        }
示例#21
0
        private void RenderLabel(XGraphics gfx)
        {
            XSize  lSize = new XSize(XUnit.FromMillimeter(pageSettings.LabelSize.Width), XUnit.FromMillimeter(pageSettings.LabelSize.Height));
            XPoint lPt   = new XPoint(0, 0);
            //Just draw each side for all labels, dont care if they overlap...
            XRect rect = new XRect(lPt, lSize);

            gfx.DrawRoundedRectangle(XPens.Black, rect, new XSize(XUnit.FromMillimeter(pageSettings.Corner.Width), XUnit.FromMillimeter(pageSettings.Corner.Height)));

            foreach (LabelItem item in labelItems)
            {
                item.Render(gfx, lPt);
            }
        }
示例#22
0
        private void RenderDebug(PrintableElement element, PdfPage page)
        {
            using (var gfx = XGraphics.FromPdfPage(page))
            {
                var rect = element.AsXRect();

                gfx.DrawRectangle(XPens.Silver, rect);

                var font = new XFont("Arial Narrow", 4, XFontStyle.Regular);
                var tf   = new XTextFormatter(gfx)
                {
                    Alignment = XParagraphAlignment.Right
                };
                var width  = rect.Width > 18 ?   18: 9;
                var height = rect.Width > 18 ? 5 : 10;
                var dbgStr = $"{element.ElementType} ({XUnit.FromPoint(rect.X).Millimeter:F0},{XUnit.FromPoint(rect.Y).Millimeter:F0})";

                gfx.DrawRectangle(new XSolidBrush(XColor.FromArgb(128 + 64, 240, 240, 240)), rect.TopRight.X - width, rect.Y, width, height);
                tf.DrawString(dbgStr, font, XBrushes.Navy, element.AsXRect());
            }
        }
示例#23
0
        private void RenderGrid(XGraphics gfx)
        {
            int x, y;

            //Create the grid
            for (x = 0; x < pageSettings.LabelsX; x++)
            {
                for (y = 0; y < pageSettings.LabelsY; y++)
                {
                    XSize  sSize = new XSize(XUnit.FromMillimeter(pageSettings.Spacing.Width), XUnit.FromMillimeter(pageSettings.Spacing.Height));
                    XSize  lSize = new XSize(XUnit.FromMillimeter(pageSettings.LabelSize.Width), XUnit.FromMillimeter(pageSettings.LabelSize.Height));
                    XPoint lPt   = new XPoint(XUnit.FromMillimeter(pageSettings.FirstLabel.X), XUnit.FromMillimeter(pageSettings.FirstLabel.Y));
                    XPoint pt    = new XPoint(x * (lSize.Width + sSize.Width) + lPt.X, y * (lSize.Height + sSize.Height) + lPt.Y);

                    //Just draw each side for all labels, dont care if they overlap...
                    XRect rect = new XRect(pt, lSize);
                    gfx.DrawRoundedRectangle(XPens.Black, rect, new XSize(XUnit.FromMillimeter(pageSettings.Corner.Width), XUnit.FromMillimeter(pageSettings.Corner.Height)));

                    //foreach (LabelItem item in labelItems)
                    //    item.Render(gfx, pt);
                }
            }
        }
        public static void GenerateIdentityCard(IdentityDocumentModel vm)
        {
            if (vm.MRZ.Length != 3)
            {
                throw new ArgumentException("MRZ should have 3 rows for indentity cards, not : " + vm.MRZ.Length);
            }

            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            document.Info.Title = "Created with PDFsharp";

            // Create an empty page
            PdfPage page = document.AddPage();

            // Get an XGraphics object for drawing
            XGraphics gfx = XGraphics.FromPdfPage(page);



            // Create a font
            XFont font         = new XFont("OCR-B 10 BT", 12, XFontStyle.Regular);
            var   width        = XUnit.FromMillimeter(85.68);
            var   height       = XUnit.FromMillimeter(54.02);
            var   heightMargin = XUnit.FromInch(.25);
            var   widthMargin  = XUnit.FromInch(.25);

            gfx.DrawRectangle(XBrushes.Beige, new XRect(widthMargin, heightMargin, width, height));
            XImage image = XImage.FromFile(@"Templates\IndentityCard_bg.jpg");

            gfx.DrawImage(image, widthMargin, heightMargin, width, height);

            // Draw the text
            gfx.DrawString(vm.MRZ[0], font, XBrushes.Black,
                           new XRect(XUnit.FromMillimeter(4) + widthMargin, XUnit.FromMillimeter(36.4) + heightMargin, XUnit.FromMillimeter(80), 0),
                           XStringFormats.Default);

            gfx.DrawString(vm.MRZ[1], font, XBrushes.Black,
                           new XRect(XUnit.FromMillimeter(4) + widthMargin, XUnit.FromMillimeter(41) + heightMargin, XUnit.FromMillimeter(80), 0),
                           XStringFormats.Default);

            gfx.DrawString(vm.MRZ[2], font, XBrushes.Black,
                           new XRect(XUnit.FromMillimeter(4) + widthMargin, XUnit.FromMillimeter(44.5) + heightMargin, XUnit.FromMillimeter(80), 0),
                           XStringFormats.Default);

            gfx.DrawLine(XPens.Black, 0, XUnit.FromMillimeter(60) + heightMargin, XUnit.FromInch(8.5), XUnit.FromMillimeter(60) + heightMargin);


            StringBuilder tmpText = new StringBuilder();

            tmpText.AppendLine("DocType : " + vm.DocType);
            tmpText.AppendLine("CountryOfIssue : " + vm.CountryOfIssue);
            tmpText.AppendLine("SurName : " + vm.SurName);
            tmpText.AppendLine("GivenNames : " + vm.GivenNames);
            tmpText.AppendLine("DocumentNum : " + vm.DocumentNum);
            tmpText.AppendLine("Dob : " + vm.Dob);
            tmpText.AppendLine("ExpDate : " + vm.ExpDate);
            tmpText.AppendLine("OptionalOne : " + vm.OptionalOne);
            tmpText.AppendLine("OptionalTwo : " + vm.OptionalTwo);
            tmpText.AppendLine("Nationality : " + vm.Nationality);
            tmpText.AppendLine("Sex : " + vm.Sex);
            tmpText = tmpText.Replace('<', ' ');
            tmpText.AppendLine("MRZ : ");
            tmpText.AppendLine(string.Join("\n", vm.MRZ));
            string text = tmpText.ToString();

            XFont          font2 = new XFont("Times New Roman", 10, XFontStyle.Bold);
            XTextFormatter tf    = new XTextFormatter(gfx);

            XRect rect = new XRect(widthMargin, XUnit.FromMillimeter(62) + heightMargin, 250, XUnit.FromMillimeter(62) + heightMargin + 220);

            gfx.DrawRectangle(XBrushes.LightGray, rect);
            //tf.Alignment = ParagraphAlignment.Left;
            tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);

            // Save the document...
            //string filename = "IndentityCard_"+DateTime.Now.ToOADate().ToString()+".pdf";
            string filename = "IdentityCard.pdf";

            document.Save(filename);
            System.Diagnostics.Process.Start(filename);
        }
示例#25
0
        private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (tabControl1.SelectedIndex)
            {
            case 0:
                pagePreview1.PageSize        = PageSizeConverter.ToSize(pageSettings.PageSize);
                propertyGrid1.SelectedObject = null;
                RefreshTable();
                break;

            case 1:
                pagePreview1.PageSize = new XSize(XUnit.FromMillimeter(pageSettings.LabelSize.Width), XUnit.FromMillimeter(pageSettings.LabelSize.Height));
                break;

            case 2:
                pagePreview1.PageSize = PageSizeConverter.ToSize(pageSettings.PageSize);
                break;
            }
            pagePreview1.Refresh();
        }
示例#26
0
        private void DrawLeftString(string text, float fromleftmm, float fromtopmm, float widthmm, float fontsize)
        {
            XPdfFontOptions o     = new XPdfFontOptions(PdfFontEncoding.Unicode);
            XFont           font1 = new XFont("Times New Roman", fontsize, XFontStyle.Regular, o);

            gfx.DrawString(text, font1, XBrushes.Black,
                           new XRect(XUnit.FromMillimeter(fromleftmm).Point, XUnit.FromMillimeter(fromtopmm).Point, XUnit.FromMillimeter(widthmm).Point, 5),
                           XStringFormats.TopLeft);
        }
示例#27
0
        internal void OnRender()
        {
            if (RenderEvent != null)
            {
                //IDocumentPaginatorSource source = this.documentViewer.Document;

                DrawingVisual  dv = new DrawingVisual();
                DrawingContext dc = dv.RenderOpen();

                XGraphics gfx = XGraphics.FromDrawingContext(dc,
                                                             new XSize(XUnit.FromMillimeter(210).Point, XUnit.FromMillimeter(297).Point), XGraphicsUnit.Point);
                try
                {
                    RenderEvent(gfx);
                }
                catch { }
                dc.Close();
                //DrawingGroup dg = dv.Drawing;

                // Create page content
                PageContent pageContent = new PageContent();
                FixedPage   fixedPage   = new FixedPage();
                fixedPage.Background = Brushes.GhostWhite;
                //UIElement visual = dv; // CreateSecondVisual(false);

                UIElement visual = new DrawingVisualPresenter(dv);
                FixedPage.SetLeft(visual, 0);
                FixedPage.SetTop(visual, 0);

                double pageWidth  = XUnit.FromMillimeter(210).Presentation;
                double pageHeight = XUnit.FromMillimeter(297).Presentation;

                fixedPage.Width  = pageWidth;
                fixedPage.Height = pageHeight;

                fixedPage.Children.Add((UIElement)visual);

                Size size = new Size(pageWidth, pageHeight);
                fixedPage.Measure(size);
                fixedPage.Arrange(new Rect(new Point(), size));
                fixedPage.UpdateLayout();

                ((IAddChild)pageContent).AddChild(fixedPage);

                FixedDocument fixedDocument = new FixedDocument();
                fixedDocument.DocumentPaginator.PageSize = size;

                fixedDocument.Pages.Add(pageContent);

                this.documentViewer.Document = fixedDocument;

                string savedButton = System.Windows.Markup.XamlWriter.Save(fixedDocument);
            }
            else
            {
                this.documentViewer.Document = null;
            }



            //base.OnRender(drawingContext);
            ////drawingContext.DrawLine(new Pen(Brushes.Green, 10), new Point(10, 10), new Point(100, 150));

            //drawingContext.PushTransform(new ScaleTransform(0.75, 0.75));
            //XGraphics gfx = XGraphics.FromDrawingContext(drawingContext, new XSize(100, 100), XGraphicsUnit.Millimeter);
            //if (RenderEvent != null)
            //{
            //  try
            //  {
            //    RenderEvent(gfx);
            //  }
            //  catch
            //  {
            //    RenderEvent = null;
            //  }
            //}
            //else
            //  Draw(gfx);
        }
示例#28
0
        public static void DrawImageFromFile(XGraphics gfx, string jpegSamplePath, XUnit x, XUnit y, XUnit width, XUnit height)
        {
            XImage image = XImage.FromFile(jpegSamplePath);

            gfx.DrawImage(image, x, y, width, height);
        }
示例#29
0
            page.Height = new XUnit()
            {
                Centimeter = 21.75
            };
            page.Width = new XUnit()
            {
                Centimeter = 13.9
            };
            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.DrawImage(XImage.FromStream(imageStream), new XPoint(XUnit.FromInch(point.Item1), XUnit.FromInch(point.Item2)));
            const string filename = "PageSizes_tempfile.pdf";

            document.Save(filename);
        }
示例#30
0
        /// <summary>
        /// Renders a single object to the specified graphics object at the given point.
        /// </summary>
        /// <param name="graphics">The graphics object to render on.</param>
        /// <param name="xPosition">The left position of the rendered object.</param>
        /// <param name="yPosition">The top position of the rendered object.</param>
        /// <param name="width">The width.</param>
        /// <param name="documentObject">The document object to render. Can be paragraph, table, or shape.</param>
        /// <remarks>This function is still in an experimental state.</remarks>
        public void RenderObject(XGraphics graphics, XUnit xPosition, XUnit yPosition, XUnit width, DocumentObject documentObject, CancellationToken ct)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }

            if (documentObject == null)
            {
                throw new ArgumentNullException("documentObject");
            }

            if (!(documentObject is Shape) && !(documentObject is Table) &&
                !(documentObject is Paragraph))
            {
                throw new ArgumentException(AppResources.ObjectNotRenderable, "documentObject");
            }

            Renderer renderer = Renderer.Create(graphics, this, documentObject, null);

            renderer.Format(new Rectangle(xPosition, yPosition, width, double.MaxValue), null);

            RenderInfo renderInfo = renderer.RenderInfo;

            renderInfo.LayoutInfo.ContentArea.X = xPosition;
            renderInfo.LayoutInfo.ContentArea.Y = yPosition;

            renderer = Renderer.Create(graphics, this, renderer.RenderInfo, null);
            renderer.Render(ct);
        }
示例#31
0
        /// <summary>
        /// Renders a single paragraph.
        /// </summary>
        static void SamplePage1(PdfDocument document)
        {
            var page = document.AddPage();
            var gfx  = XGraphics.FromPdfPage(page);

            // HACK²
            gfx.MUH = PdfFontEncoding.Unicode;

            var font = new XFont("Segoe UI", 13, XFontStyle.Bold);

            gfx.DrawString("The following paragraph was rendered using MigraDoc:", font, XBrushes.Black,
                           new XRect(100, 100, page.Width - 200, 300), XStringFormats.Center);

            // You always need a MigraDoc document for rendering.
            var doc = new Document();
            var sec = doc.AddSection();
            // Add a single paragraph with some text and format information.
            var para = sec.AddParagraph();

            para.Format.Alignment  = ParagraphAlignment.Justify;
            para.Format.Font.Name  = "Times New Roman";
            para.Format.Font.Size  = 12;
            para.Format.Font.Color = Colors.DarkGray;
            para.Format.Font.Color = Colors.DarkGray;
            para.AddText("Duisism odigna acipsum delesenisl ");
            para.AddFormattedText("ullum in velenit", TextFormat.Bold);
            para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna " +
                         "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel " +
                         "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis " +
                         "niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex " +
                         "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠");
            para.Format.Borders.Distance = "5pt";
            para.Format.Borders.Color    = Colors.Gold;

#if DEBUG
            MigraDoc.DocumentObjectModel.IO.Xml.DdlWriter.WriteToFile(doc, "MigraDoc.xml");

            Document doc3 = null;
            using (StreamReader sr = File.OpenText("MigraDoc.xml"))
            {
                var errors = new MigraDoc.DocumentObjectModel.IO.DdlReaderErrors();
                var reader = new MigraDoc.DocumentObjectModel.IO.Xml.DdlReader(sr, errors);

                doc3 = reader.ReadDocument();

                using (StreamWriter sw = new StreamWriter("MigraDoc.xml.errors"))
                {
                    foreach (MigraDoc.DocumentObjectModel.IO.DdlReaderError error in errors)
                    {
                        sw.WriteLine("{0}:{1} {2} {3}", error.SourceLine, error.SourceColumn, error.ErrorLevel, error.ErrorMessage);
                    }
                }
            }
#endif

            // Create a renderer and prepare (=layout) the document.
            var docRenderer = new DocumentRenderer(doc3);
            docRenderer.PrepareDocument();

            // Render the paragraph. You can render tables or shapes the same way.
            docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", doc3.Sections[0].LastParagraph /*para*/);
        }