Exemplo n.º 1
0
        public Table(XPoint position, XUnit width)
        {
            this.position = position;
            this.width    = width;

            margin = XUnit.FromPoint(3);
            pen    = new XPen(XColors.Black, XUnit.FromPoint(0.5));
            rows   = new List <Row>();
        }
Exemplo n.º 2
0
 private void CreateBottomBorderMap()
 {
     _bottomBorderMap = new Dictionary <int, XUnit>(); //new SortedList();
     _bottomBorderMap.Add(0, XUnit.FromPoint(0));
     while (!_bottomBorderMap.ContainsKey(_table.Rows.Count))
     {
         CreateNextBottomBorderPosition();
     }
 }
 void CreateBottomBorderMap()
 {
     this.bottomBorderMap = new SortedList <int, XUnit>();
     this.bottomBorderMap.Add(0, XUnit.FromPoint(0));
     while (!this.bottomBorderMap.ContainsKey(this.table.Rows.Count))
     {
         CreateNextBottomBorderPosition();
     }
 }
Exemplo n.º 4
0
        private void AddQuestions(int qcount, int cellsinq, List <string> cellslabels, int rowscnt, PdfRectangle rect)
        {
            int rowhight  = 7;
            int rowscount = rowscnt;//Convert.ToInt32((_page.Height.Millimeter - 80d) / 7d);
            int colscount = qcount / rowscount;

            int mincolwidth = cellsinq * (4 + 3);

            // int colsinterval = Convert.ToInt32(((_page.Width.Millimeter - 40d) - (mincolwidth * colscount)) / colscount);

            int colsinterval = Convert.ToInt32(((XUnit.FromPoint(rect.X2 - rect.X1).Millimeter - 40d) - (mincolwidth * colscount)) / colscount);

            colsinterval = colsinterval < 8 ? 8 : colsinterval;
            int colwidgth = cellsinq * (4 + 3) + colsinterval;

            int maxy  = 0;
            int initx = 15 + (int)XUnit.FromPoint(rect.X1).Millimeter;
            int inity = 55;

            int x = initx;

            int number = 1;

            int rr = 0;
            int y  = inity;

            for (int question = 0; question < qcount; question++)
            {
                if (rr != 0)
                {
                    DrawQuestion(number, cellsinq, x, y);
                }
                else
                {
                    DrawQuestion(number, cellsinq, x, y, cellslabels);
                }
                number++;
                rr++;
                y = y + rowhight;
                if (y > maxy)
                {
                    maxy = y;
                }
                if (rr == rowscount)
                {
                    rr = 0;
                    x += colwidgth;
                    y  = inity;
                }
            }

            this.DrawLine(0, (float)_page.Width.Millimeter, maxy);
            this.DrawLeftString("Добровольность тестирования и достоверность результатов подтверждаю:_______________", initx - 10, maxy + 1, 60, 10);
        }
Exemplo n.º 5
0
        private void DrawCenterMarker(int size, float center)
        {
            XUnit _size = XUnit.FromMillimeter(size);
            XPen  pen   = new XPen(XColors.Black, 2);
            XUnit _x    = XUnit.FromPoint(center);
            XUnit _y    = XUnit.FromMillimeter(10);

            _x.Point = _x.Point - (_size.Point / 2d);
            _y.Point = _y.Point - (_size.Point / 2d);

            gfx.DrawRectangle(pen, XBrushes.Black, _x.Point, _y.Point, _size.Point, _size.Point);
        }
Exemplo n.º 6
0
        public override void PutText(string text, double x, double y, int fontSize, bool isBold)
        {
            var font = new XFont(FontFamily, XUnit.FromPoint(fontSize).Millimeter, isBold ? XFontStyle.Bold : XFontStyle.Regular);

            // With our transformation to mirror the y axis, text printed using DrawString also gets mirrored.
            // As a workaround we move our current transformation to the x/y position and then mirror the y axis again, and then restore the previous transformation.
            XGraphics.Save();
            XGraphics.TranslateTransform(x, y);
            XGraphics.MultiplyTransform(new XMatrix(1.0, 0.0, 0.0, -1.0, 0.0, 0.0));
            XGraphics.DrawString(text, font, XBrushes.Black, 0.0, 0.0);
            XGraphics.Restore();
        }
Exemplo n.º 7
0
        private void DrawCenterMarker(int size)
        {
            XUnit _size = XUnit.FromMillimeter(size);
            //  XGraphics gfx = XGraphics.FromPdfPage(_page);
            XPen  pen = new XPen(XColors.Black, 2);
            XUnit _x  = XUnit.FromPoint(_page.Width.Point / 2d);
            XUnit _y  = XUnit.FromMillimeter(10);

            _x.Point = _x.Point - (_size.Point / 2d);
            _y.Point = _y.Point - (_size.Point / 2d);

            gfx.DrawRectangle(pen, XBrushes.Black, _x.Point, _y.Point, _size.Point, _size.Point);
        }
Exemplo n.º 8
0
        private static void AddTemplateBox(TemplatePage page, PdfPage pdfPage, PdfArray rect, string name)
        {
            var a = rect.Elements[0] as PdfReal;
            var b = rect.Elements[1] as PdfReal;
            var c = rect.Elements[2] as PdfReal;
            var d = rect.Elements[3] as PdfReal;

            if (a is null || b is null || c is null || d is null)
            {
                return;
            }

            // Convert rect to millimeters,
            // and flip vertically (PDF 0,0 is bottom-left; XGraphics, images, and template 0,0 is top-left)
            var x1 = XUnit.FromPoint(a.Value).Millimeter;
            var x2 = XUnit.FromPoint(c.Value).Millimeter;
            var y1 = pdfPage.Height.Millimeter - XUnit.FromPoint(b.Value).Millimeter;
            var y2 = pdfPage.Height.Millimeter - XUnit.FromPoint(d.Value).Millimeter;

            // normalise rectangle (PDF allows for any opposite corners)
            var left   = Math.Min(x1, x2);
            var right  = Math.Max(x1, x2);
            var top    = Math.Min(y1, y2);
            var bottom = Math.Max(y1, y2);

            var boxName = name;

            for (var i = 0; i < 100; i++)
            {
                if (!page.Boxes.ContainsKey(boxName))
                {
                    break;
                }
                boxName = name + "_" + i;
            }

            page.Boxes.Add(boxName, new TemplateBox
            {
                Alignment = TextAlignment.BottomLeft,

                Left   = left, Top = top,
                Width  = right - left,
                Height = bottom - top,

                BoxOrder      = null, DependsOn = null,
                DisplayFormat = null,
                MappingPath   = Array.Empty <string>(),
                WrapText      = false, ShrinkToFit = true,
                BoxFontSize   = null
            });
        }
Exemplo n.º 9
0
 /// <summary>
 /// Gets page size in mm or inch.
 /// </summary>
 public static string PageSize(PdfPage page, bool metric)
 {
     if (metric)
     {
         return(String.Format("{0:0.#} x {1:0.#} mm",
                              XUnit.FromPoint(page.Width).Millimeter,
                              XUnit.FromPoint(page.Height).Millimeter));
     }
     else
     {
         return(String.Format("{0:0.#} x {1:0.#} inch",
                              XUnit.FromPoint(page.Width).Inch,
                              XUnit.FromPoint(page.Height).Inch));
     }
 }
Exemplo n.º 10
0
        public void Create(string filename, int qcount, int cellsinq, List <string> cellslabels, int rowscount)
        {
            s_document        = new PdfDocument();
            _page             = new PdfPage();
            _page.Orientation = PageOrientation.Landscape;
            _page.Size        = PageSize.A4;
            s_document.Pages.Add(_page);
            gfx = XGraphics.FromPdfPage(_page);

            DrawCutLine();


            PdfRectangle leftpage  = new PdfRectangle(new XPoint(0, 0), new XPoint(_page.Width / 2, _page.Height));
            PdfRectangle rightpage = new PdfRectangle(new XPoint(_page.Width / 2, 0), new XPoint(_page.Width, _page.Height));

            //left part
            float leftcenter = (float)(_page.Width / 4) * 1f;

            DrawCenterMarker(7, leftcenter);
            DrawSideMarker(7, 10, 10);
            DrawSideMarker(7, XUnit.FromPoint(leftpage.Width).Millimeter - 10, 10);
            DrawSideMarker(7, 10, XUnit.FromPoint(leftpage.Height).Millimeter - 10);
            DrawSideMarker(7, XUnit.FromPoint(leftpage.Width).Millimeter - 10, XUnit.FromPoint(leftpage.Height).Millimeter - 10);

            AddFields(leftpage);

            AddQuestions(qcount, cellsinq, cellslabels, rowscount, leftpage);

            //right part
            float rigthcenter = (float)(_page.Width / 4) * 3f;

            DrawCenterMarker(7, rigthcenter);
            DrawSideMarker(7, XUnit.FromPoint(rightpage.X1).Millimeter + 10, XUnit.FromPoint(rightpage.Y1).Millimeter + 10);
            DrawSideMarker(7, XUnit.FromPoint(rightpage.X2).Millimeter - 10, XUnit.FromPoint(rightpage.Y1).Millimeter + 10);
            DrawSideMarker(7, XUnit.FromPoint(rightpage.X1).Millimeter + 10, XUnit.FromPoint(rightpage.Y2).Millimeter - 10);
            DrawSideMarker(7, XUnit.FromPoint(rightpage.X2).Millimeter - 10, XUnit.FromPoint(rightpage.Y2).Millimeter - 10);

            AddFields(rightpage);
            AddQuestions(qcount, cellsinq, cellslabels, rowscount, rightpage);



            // Save the s_document...
            s_document.Save(filename);
            // ...and start a viewer
            Process.Start(filename);
        }
Exemplo n.º 11
0
        private void RenderXps(FixedPage xImage, XRect destRect, XRect srcRect, XGraphicsUnit point)
        {
            var page    = _gfx.PdfPage;
            var context = new DocumentRenderingContext(page.Owner);

            using (XForm form = new XForm(page.Owner, XUnit.FromPoint(xImage.PointWidth), XUnit.FromPoint(xImage.PointHeight)))
            {
                var writer = new PdfContentWriter(context, form, RenderMode.Default);


                writer.BeginContent(false);
                writer.WriteElements(xImage.Content);
                writer.EndContent();

                _gfx.DrawImage(form, destRect, srcRect, point);
            }
        }
Exemplo n.º 12
0
        private void AddFields(PdfRectangle rect)
        {
            float           offset = (float)XUnit.FromPoint(rect.X1).Millimeter;
            XPdfFontOptions o      = new XPdfFontOptions(PdfFontEncoding.Unicode);
            XFont           font   = new XFont("Times New Roman", 14, XFontStyle.Regular, o);

            gfx.DrawString("Бланк фиксации результатов теста", font, XBrushes.Black,
                           new XRect(rect.X1, rect.Y1 + XUnit.FromMillimeter(17).Point, rect.X2 - rect.X1, 5),
                           XStringFormats.Center);


            this.DrawLeftString("Подразделение_______________", 10 + offset, 25, 60, 10); this.DrawLeftString("Ф.И.О._____________________________________", 70 + offset, 25, 90, 10);
            this.DrawLeftString("Дата рождения_______________", 10 + offset, 30, 60, 10);
            this.DrawLeftString("Образование_________________", 10 + offset, 35, 30, 10); this.DrawLeftString("Дата тестирования__________________________", 70 + offset, 35, 30, 10);

            this.DrawLeftString("M", 10 + offset, 40, 5, 14); this.DrawRectangle(4, 17 + offset, 42); this.DrawLeftString("Ж", 20 + offset, 40, 5, 14); this.DrawRectangle(4, 27 + offset, 42); this.DrawLeftString("Пример заполнения бланка", 40 + offset, 40, 50, 10); this.DrawRectangle(4, 85 + offset, 42); this.DrawLeftString("Х", 83 + offset, 40, 5, 14);

            this.DrawLine(0, (int)_page.Width.Millimeter, 45);
        }
Exemplo n.º 13
0
        public void SavePDFFile(Image sourceImage, string targetPDFFilePath)

        {
            PdfDocument pdfDocument = null;

            try
            {
                pdfDocument = new PdfDocument();
                double sourceImageWidth  = (sourceImage.Width / 96d) * 72d;
                double sourceImageHeight = (sourceImage.Height / 96d) * 72d;
                int    pageHeight        = (int)((842d / 72d) * 96d);
                int    pageCount         = (int)Math.Ceiling(sourceImageHeight / 842d);

                for (int i = 0; i < pageCount; i++)
                {
                    Bitmap   pageBitmap   = new Bitmap(sourceImage.Width, pageHeight);
                    Graphics pageGraphics = Graphics.FromImage(pageBitmap);

                    pageGraphics.DrawImage
                    (
                        sourceImage,
                        new Rectangle(0, 0, sourceImage.Width, pageHeight),
                        new Rectangle(0, i * pageHeight, sourceImage.Width, pageHeight),
                        GraphicsUnit.Pixel
                    );

                    PdfPage pdfPage = new PdfPage();
                    pdfPage.Width = XUnit.FromPoint(sourceImageWidth);
                    pdfDocument.AddPage(pdfPage);
                    XImage    xImage    = XImage.FromGdiPlusImage(pageBitmap);
                    XGraphics xGraphics = XGraphics.FromPdfPage(pdfPage);
                    xGraphics.DrawImage(xImage, 0, 0);
                }
                pdfDocument.Save(targetPDFFilePath);
            }
            finally
            {
                if (pdfDocument != null)
                {
                    pdfDocument.Clone();
                }
            }
        }
Exemplo n.º 14
0
        private void AddPage(string str)
        {
            _Page = _Doc.AddPage();

            _Page.Size = PdfSharp.PageSize.A4;

            if (Page_Height <= 0 || Page_Width <= 0)
            {
                _Page.Size        = PdfSharp.PageSize.A4;
                _Page.Orientation = PdfSharp.PageOrientation.Landscape;
            }
            else
            {
                _Page.Width  = XUnit.FromPoint(Page_Width);
                _Page.Height = XUnit.FromPoint(Page_Height);
            }


            gfx = XGraphics.FromPdfPage(_Page);
        }
Exemplo n.º 15
0
        static PdfPage AddSinglePageReal(PdfDocument doc, Image image)
        {
            // in case of diff x/y resolutions
            var widthPt  = XUnit.FromPoint(72 * (image.Width / image.HorizontalResolution));
            var heightPt = XUnit.FromPoint(72 * (image.Height / image.VerticalResolution));

            var newPage = doc.Pages.Add(new PdfPage
            {
                Width  = widthPt,
                Height = heightPt
            });

            using (var xgr = XGraphics.FromPdfPage(newPage))
            {
                // cannot dispose pdfImg in loop or it will dispose real image as well
                var pdfImg = XImage.FromGdiPlusImage(image);
                xgr.DrawImage(pdfImg, 0, 0, newPage.Width, newPage.Height);
            }
            return(newPage);
        }
Exemplo n.º 16
0
        public override void StrokePath(double strokeWidth, int color, LineStyle lineStyle)
        {
            var pen = new XPen(XColor.FromArgb(color), XUnit.FromPoint(strokeWidth).Millimeter);

            switch (lineStyle)
            {
            case LineStyle.Dashed:
                pen.DashPattern = new double[] { 4, 4 };
                break;

            case LineStyle.Dotted:
                pen.LineCap     = XLineCap.Round;
                pen.DashPattern = new double[] { 0.01, 3 };
                break;

            default:
                break;
            }
            CurrentPath.Stroke(XGraphics, pen);
        }
Exemplo n.º 17
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());
            }
        }
Exemplo n.º 18
0
        private void button6_Click(object sender, EventArgs e)
        {
            //SetColorTextBg(Color.FromArgb(255, 255, 255));
            //CaptureScreen();
            //printDoc.DefaultPageSettings.PrinterSettings.PrinterName = "Microsoft Print to PDF";
            //printDoc.DefaultPageSettings.PrinterSettings.PrintToFile = true;
            //printDoc.DefaultPageSettings.PrinterSettings.PrintFileName = lblFolderPath.Text;
            //printDoc.Print();

            SetColorTextBg(Color.FromArgb(255, 255, 255));
            CaptureScreen();
            try
            {
                PdfDocument pdfDocument = null;
                pdfDocument = new PdfDocument();

                Bitmap   pageBitmap   = new Bitmap(827, 1259);
                Graphics pageGraphics = Graphics.FromImage(pageBitmap);

                pageGraphics.DrawImage(memoryImage1, 70, 110);
                pageGraphics.DrawImage(memoryImage2, 70, 888);

                PdfPage pdfPage = new PdfPage();

                pdfPage.Width  = XUnit.FromPoint(595.27184);
                pdfPage.Height = XUnit.FromPoint(931.88446);

                pdfDocument.AddPage(pdfPage);
                XImage    xImage    = XImage.FromGdiPlusImage(pageBitmap);
                XGraphics xGraphics = XGraphics.FromPdfPage(pdfPage);
                xGraphics.DrawImage(xImage, 0, 0);
                pdfDocument.Save(lblFolderPath.Text);

                MessageBox.Show("The file '" + docName + ".pdf" + "' has been made.", "Note");
            }
            catch
            {
                MessageBox.Show("The file '" + docName + ".pdf" + "' can not be overwritten because it is open.Please close the file and try again.", "Note");
            }
        }
Exemplo n.º 19
0
        public static void verticalBarCode2()
        {
            using (PdfDocument document = new PdfDocument())
            {
                //create pdf header
                document.Info.Title        = "My barcode";
                document.Info.Author       = "Me";
                document.Info.Subject      = "Barcode";
                document.Info.Keywords     = "Barcode, Ean13";
                document.Info.CreationDate = DateTime.Now;

                //create new pdf page
                PdfPage page = document.AddPage();
                page.Width  = XUnit.FromPoint(672);
                page.Height = XUnit.FromPoint(890);

                using (XGraphics gfx = XGraphics.FromPdfPage(page))
                {
                    //make sure the font is embedded
                    var options = new XPdfFontOptions(PdfFontEncoding.Unicode);

                    //declare a font for drawing in the PDF
                    XFont          fontEan      = new XFont("mrvcode39s", 20, XFontStyle.Regular, options);
                    XTextFormatter tf           = new XTextFormatter(gfx);
                    var            stringFormat = new XStringFormat();
                    stringFormat.Alignment = XStringAlignment.Center;

                    gfx.RotateTransform(-90.0);
                    //create the barcode from string
                    var point1 = new XPoint(-20, -20);
                    var point2 = new XPoint(20, 20);
                    gfx.DrawString("*12234*", fontEan, XBrushes.Black, new XRect(point1, point2), stringFormat);
                }


                document.Save("VerticalBarCodeNew.pdf");
            }
        }
Exemplo n.º 20
0
        public void GenerateReceipt(string filepath)
        {
            var document = new PdfDocument();

            PdfPage        page = document.AddPage();
            XGraphics      gfx  = XGraphics.FromPdfPage(page);
            XTextFormatter tf   = new XTextFormatter(gfx);

            Document doc = new Document();
            Section  s   = doc.AddSection();
            Table    receipt;
            Column   c;
            Row      r;

            receipt = s.AddTable();
            receipt.Format.Font.Name = "Arial";
            receipt.Format.Font.Size = new Unit(12, UnitType.Point);
            receipt.Borders.Width    = 0;
            receipt.Style            = "Table";
            receipt.BottomPadding    = new Unit(10, UnitType.Point);

            c = receipt.AddColumn(new Unit(60, UnitType.Point));
            c = receipt.AddColumn(new Unit(125, UnitType.Point));
            c.Format.Alignment = ParagraphAlignment.Right;
            c = receipt.AddColumn(new Unit(225, UnitType.Point));
            c.Format.Alignment = ParagraphAlignment.Left;
            c = receipt.AddColumn(new Unit(60, UnitType.Point));
            c.Format.Alignment = ParagraphAlignment.Right;

            r = receipt.AddRow();
            r.BottomPadding             = 0;
            r.Cells[2].MergeRight       = 1;
            r.Cells[2].Format.Font.Size = new Unit(7, UnitType.Point);
            r.Cells[2].Format.Alignment = ParagraphAlignment.Right;
            r.Cells[2].AddParagraph(string.Format("Gerado em: {0}", DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")));

            r = receipt.AddRow();
            r.Borders.Top.Width            = 1;
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.TopPadding = new Unit(10, UnitType.Point);
            var krav_maga_moema_logo = r.Cells[0].AddImage(AppDomain.CurrentDomain.BaseDirectory + "logo_krav_maga_moema.jpg");

            krav_maga_moema_logo.Height          = new Unit(40, UnitType.Point);
            krav_maga_moema_logo.LockAspectRatio = true;

            var krav_maga_sa_logo = r.Cells[3].AddImage(AppDomain.CurrentDomain.BaseDirectory + "logo_kravmaga.png");

            krav_maga_sa_logo.Height          = new Unit(40, UnitType.Point);
            krav_maga_sa_logo.LockAspectRatio = true;

            r.Format.Font.Bold             = true;
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Format.Alignment             = ParagraphAlignment.Center;
            r.Format.Font.Size             = new Unit(15, UnitType.Point);
            r.Cells[1].MergeRight          = 1;
            r.Cells[1].AddParagraph("RECIBO DE PAGAMENTO");

            r = receipt.AddRow();
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Cells[1].AddParagraph("Nome do Aluno:");
            r.Cells[2].MergeRight = 1;
            r.Cells[2].AddParagraph(receiptInfo.StudentName.ToUpper());

            r = receipt.AddRow();
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Cells[1].AddParagraph("Valor do Pagamento:");
            r.Cells[2].AddParagraph(receiptInfo.PaymentValue.ToString("R$ 0,0.00"));

            r = receipt.AddRow();
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Cells[1].AddParagraph("Data do Pagamento:");
            r.Cells[2].AddParagraph(receiptInfo.PaymentDate.ToString("dd/MM/yyyy"));

            r = receipt.AddRow();
            r.Cells[0].Borders.Left.Width  = 1;
            r.Cells[3].Borders.Right.Width = 1;
            r.Cells[1].AddParagraph("Tipo do Pagamento:");
            r.Cells[2].AddParagraph(receiptInfo.PaymentType.ToUpper());
            r.Borders.Bottom.Width = 1;

            MigraDoc.Rendering.DocumentRenderer docRender = new MigraDoc.Rendering.DocumentRenderer(doc);
            docRender.PrepareDocument();

            docRender.RenderObject(gfx, XUnit.FromPoint(50), XUnit.FromPoint(30), XUnit.FromPoint(470), receipt);

            document.Save(filepath);
        }
Exemplo n.º 21
0
        /// <summary>Compiles word list into a PDF document.</summary>
        public BingoCard Create()
        {
            var shuffledWords = Words.OrderBy(w => w.Value).Select(w => w.Key).ToList();

            Gfx.DrawString
            (
                text: InternalDocument.Info.Title,
                font: TitleFont,
                brush: XBrushes.Black,
                layoutRectangle: new XRect(0, 0, Page.Width, Page.Height.Value / 10),
                format: XStringFormats.Center
            );

            //Which word (from the shuffled list) should we use now?
            var index = 0;

            for (int i = 0; i < 5; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    //Don't print anything in the middle cell
                    if (i == 2 && j == 2)
                    {
                        continue;
                    }

                    var parts = shuffledWords[index++].Split(@"\n");

                    for (var partIndex = 0; partIndex < parts.Length; partIndex++)
                    {
                        Gfx.DrawString
                        (
                            text: parts[partIndex],
                            font: Font,
                            brush: XBrushes.Black,
                            layoutRectangle: new XRect
                            (
                                Page.Width.Value / 5 * i,
                                Page.Height.Value / 8 * (2 + j)
                                - XUnit.FromPoint(FontRegularSize) * ((parts.Length - 1) * 0.5 - partIndex) * LineHeight,
                                Page.Width.Value / 5,
                                Page.Height.Value / 8
                            ),
                            format: XStringFormats.Center
                        );
                    }
                }
            }

            //Draw table borders
            var pen = new XPen(XColors.Black, TableBorder);

            for (var i = 0; i <= 5; i++)
            {
                Gfx.DrawLine
                (
                    pen,
                    Page.Width.Value / 5 * i,
                    Page.Height.Value / 8 * 2,
                    Page.Width.Value / 5 * i,
                    Page.Height.Value / 8 * 7
                );
                Gfx.DrawLine
                (
                    pen,
                    0,
                    Page.Height.Value / 8 * (2 + i),
                    Page.Width,
                    Page.Height.Value / 8 * (2 + i)
                );
            }

            return(this);
        }
Exemplo n.º 22
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);
                devicePixelRatio = Math.Round(devicePixelRatio, 1);
                if (devicePixelRatio <= 0)
                {
                    devicePixelRatio = 1;
                }
                if (devicePixelRatio > 2)
                {
                    devicePixelRatio = 2;
                }

                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=\"{Util.SanitizeFilename(title)}.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 - 2019 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=\"{Util.SanitizeFilename(title)}.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;
            }
Exemplo n.º 23
0
        /// <summary>
        /// Renders a single paragraph.
        /// </summary>
        void GenerateReport(PdfDocument document)
        {
            //PdfPage page = document.AddPage();
            PdfPage page = document.Pages[0];

            XGraphics gfx = XGraphics.FromPdfPage(page);

            // HACK²
            gfx.MUH  = PdfFontEncoding.Unicode;
            gfx.MFEH = PdfFontEmbedding.Default;

            XFont font = new XFont("Verdana", 4, XFontStyle.Regular);



            // map image origin
            //gfx.DrawString("O", font, XBrushes.Red, new XRect(5, 5, 108, 161), XStringFormats.Center);


            // ovmap image origin
            //gfx.DrawString("X", font, XBrushes.Red, new XRect(5, 5, 798, 1144), XStringFormats.Center);



            //gfx.DrawString("+", font, XBrushes.Red, new XRect(5, 5, 100, 1299), XStringFormats.Center);



            //XImage ximg = XImage.FromFile(mapImagePth);
            XImage ximg = XImage.FromGdiPlusImage(mimg);

            //ximg.Interpolate = true;
            Point ipt = new Point(58, 86);

            //gfx.SmoothingMode = XSmoothingMode.HighQuality;
            gfx.DrawImage(ximg, ipt);



            //gfx.DrawImage(ximg, ipt.X, ipt.Y, ApplyTransform(ximg.PointWidth), ApplyTransform(ximg.PointHeight));


            /*
             * XImage ximg_ov = XImage.FromFile(ovmapImagePth);
             * Point ov_ipt = new Point(398, 580);
             * gfx.DrawImage(ximg_ov, ov_ipt);
             */

            //String ovmapImageTPth = @"C:\inetpub\wwwroot\ms6\output\ov\ov13_mxd_a.png";

            /*
             * XImage ximg_ov = XImage.FromFile(ovmapImagePth);
             *
             * Point ov_ipt = new Point(408, 570);
             * //gfx.DrawImage(ximg_ov, ov_ipt);
             * gfx.DrawImage(ximg_ov, ov_ipt.X, ov_ipt.Y,97,130);
             */
            /*
             * double rminx = 1218342.661;
             * double rminy = 500202.9879;
             * double rmaxx = 1397365.953;
             * double rmaxy = 738900.7105;
             * double rxw = 179023.292;
             * double rxh = 238697.7226;
             * double img_width = 97.0;
             * double img_height = 130.0;
             */
            double rminx      = 1232659.28962;
            double rminy      = 498047.976697;
            double rmaxx      = 1390211.37295;
            double rmaxy      = 739801.448919;
            double rxw        = 157552.0833;
            double rxh        = 241753.4722;
            double img_width  = 87;
            double img_height = 133;
            double qx         = minx + ((maxx - minx) / 2.0);
            double qy         = miny + ((maxy - miny) / 2.0);

            double pct_x = (qx - rminx) / rxw;
            double pct_y = (qy - rminy) / rxh;

            double px_x = pct_x * img_width;
            double px_y = (1.0 - pct_y) * img_height;

            double ul_px = ((minx - rminx) / rxw) * img_width;
            double ul_py = (1.0 - ((maxy - rminy) / rxh)) * img_height;

            double qwidth_pct = (maxx - minx) / (rmaxx - rminx);
            double qhght_pct  = (maxy - miny) / (rmaxy - rminy);

            double px_width = qwidth_pct * img_width;
            double px_hgt   = qhght_pct * img_height;


            //Debug.Print(String.Format("qx/qy: {0}  {1}    pct_x/pct_y: {2}  {3}   px_x/px_y:  {4}  {5} ", qx, qy, pct_x, pct_y, px_x, px_y));



            // option #1 - using graphics object directly on image
            Image ovImg = Image.FromFile(ovmapImageTPth);

            using (Graphics g = Graphics.FromImage(ovImg))
            {
                Pen myPen = new Pen(System.Drawing.Color.Red, 5);
                System.Drawing.Font myFont = new System.Drawing.Font("Helvetica", 15, FontStyle.Bold);
                Brush myBrush = new SolidBrush(System.Drawing.Color.Red);
                g.DrawString("x", myFont, myBrush, new PointF((float)px_x, (float)px_y));
                g.DrawRectangle(myPen, (float)ul_px, (float)ul_py, (float)px_width, (float)px_hgt);
            }

            ovImg.Save(ovmapImagePth);
            XImage ximg_ov = XImage.FromFile(ovmapImagePth);



            XImage ximgn = XImage.FromFile(northimgpth);

            //ximg.Interpolate = true;
            Point iptn = new Point(520, 570);

            //gfx.SmoothingMode = XSmoothingMode.HighQuality;
            gfx.DrawImage(ximgn, iptn);



            Point ov_ipt = new Point(400, 570);
            //gfx.DrawImage(ximg_ov, ov_ipt);

            //gfx.DrawImage(ximg_ov, ov_ipt.X, ov_ipt.Y, 97, 130);

            RectangleF srcR  = new RectangleF(0, 0, (int)img_width, (int)img_height);
            RectangleF destR = new RectangleF(ov_ipt.X, ov_ipt.Y, (int)img_width, (int)img_height);

            gfx.DrawImage(ximg_ov, destR, srcR, XGraphicsUnit.Point);

            // option #2 - using pdf object directly on report



            // XPen peno = new XPen(XColors.Aqua, 0.5);

            //gfx.DrawRectangle(peno, 408, 570,  95,  128);

            //peno = new XPen(XColors.DodgerBlue, 0.5);

            //gfx.DrawRectangle(peno, 354, 570, 200, 128);



            XPen pen = new XPen(XColors.Black, 0.5);

            gfx.DrawRectangle(pen, 29, 59, 555, 643);


            XPen pen2 = new XPen(XColors.Black, 0.8);

            gfx.DrawRectangle(pen, 29, 566, 555, 136);


            XPen   pen3  = new XPen(XColors.HotPink, 0.5);
            XBrush brush = XBrushes.LightPink;

            gfx.DrawRectangle(pen, brush, 29, 705, 555, 43);



            Document doc = new Document();



            // You always need a MigraDoc document for rendering.

            Section sec = doc.AddSection();
            // Add a single paragraph with some text and format information.
            Paragraph para = sec.AddParagraph();

            para.Format.Alignment  = ParagraphAlignment.Justify;
            para.Format.Font.Name  = "Verdana";
            para.Format.Font.Size  = Unit.FromPoint(6);
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
            //para.AddText("Duisism odigna acipsum delesenisl ");
            //para.AddFormattedText("ullum in velenit", TextFormat.Bold);

            para.AddText("Okaloosa County makes every effort to produce the most accurate information possible. No warranties, expressed or implied, are provided for the data herein, its use or interpretation. The assessment information is from the last certified taxroll. All data is subject to change before the next certified taxroll. PLEASE NOTE THAT THE GIS MAPS ARE FOR ASSESSMENT PURPOSES ONLY NEITHER OKALOOSA COUNTY NOR ITS EMPLOYEES ASSUME RESPONSIBILITY FOR ERRORS OR OMISSIONS ---THIS IS NOT A SURVEY---");


            //para.Format.Borders.Distance = "1pt";
            //para.Format.Borders.Color = Colors.Orange;

            // 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.  29, 705, 555, 43
            docRenderer.RenderObject(gfx, XUnit.FromPoint(38), XUnit.FromPoint(710), XUnit.FromPoint(535), para);



            Section section = doc.AddSection();



            MigraDoc.DocumentObjectModel.Tables.Table table = section.AddTable();
            table.Style         = "Table";
            table.Borders.Color = MigraDoc.DocumentObjectModel.Colors.Black;
            table.Borders.Width = 0.25;

            table.Borders.Left.Width  = 0.5;
            table.Borders.Right.Width = 0.5;
            table.Rows.LeftIndent     = 0;
            table.Format.Font.Name    = "Verdana";
            table.Format.Font.Size    = Unit.FromPoint(6);
            table.Rows.Height         = Unit.FromInch(0.203);

            /*
             * // Before you can add a row, you must define the columns
             * Column 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
             * Row row = table.AddRow();
             * row.HeadingFormat = true;
             * row.Format.Alignment = ParagraphAlignment.Center;
             * row.Format.Font.Bold = true;
             * row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.Blue;
             * row.Cells[0].AddParagraph("Item");
             * row.Cells[0].Format.Font.Bold = false;
             * row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[0].VerticalAlignment = VerticalAlignment.Bottom;
             * row.Cells[0].MergeDown = 1;
             * row.Cells[1].AddParagraph("Title and Author");
             * row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[1].MergeRight = 3;
             * row.Cells[5].AddParagraph("Extended Price");
             * row.Cells[5].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[5].VerticalAlignment = VerticalAlignment.Bottom;
             * row.Cells[5].MergeDown = 1;
             *
             *
             * row = table.AddRow();
             * row.HeadingFormat = true;
             * row.Format.Alignment = ParagraphAlignment.Center;
             * row.Format.Font.Bold = true;
             * row.Shading.Color = MigraDoc.DocumentObjectModel.Colors.BlueViolet;
             * row.Cells[1].AddParagraph("Quantity");
             * row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[2].AddParagraph("Unit Price");
             * row.Cells[2].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[3].AddParagraph("Discount (%)");
             * row.Cells[3].Format.Alignment = ParagraphAlignment.Left;
             * row.Cells[4].AddParagraph("Taxable");
             * row.Cells[4].Format.Alignment = ParagraphAlignment.Left;
             */


            Column column = table.AddColumn(Unit.FromInch(0.31));

            column.Format.Alignment = ParagraphAlignment.Center;

            column = table.AddColumn(Unit.FromInch(2.0));
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn(Unit.FromInch(0.8));
            column.Format.Alignment = ParagraphAlignment.Right;

            column = table.AddColumn(Unit.FromInch(1.0));
            column.Format.Alignment = ParagraphAlignment.Right;

            Row row = table.AddRow();

            row.HeadingFormat    = true;
            row.Format.Alignment = ParagraphAlignment.Center;
            row.Format.Font.Bold = true;
            row.Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Okaloosa County Property Appraiser  -  2013 Certified Values");
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Center;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;

            row = table.AddRow();
            row.Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[0].AddParagraph("Parcel: " + obCama.pinstr);
            row.Cells[0].Format.Font.Bold  = false;
            row.Cells[0].Format.Alignment  = ParagraphAlignment.Left;
            row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
            row.Cells[0].MergeRight        = 3;


            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Name");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.owner);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Land Value:");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.landval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Site");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.site_addr);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Building Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.bldval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("Sale");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[1].AddParagraph(obCama.sale_info);
            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[2].AddParagraph("Misc Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.miscval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            row = table.AddRow();
            row.Cells[0].Shading.Color = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[0].AddParagraph("\nMail\n");
            row.Cells[0].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[0].MergeDown = 3;

            //row.Cells[1].AddParagraph(obCama.mail_addr);
            row.Cells[1].AddParagraph(obCama.mail_addr_1);
            row.Cells[1].AddParagraph(obCama.mail_addr_2);

            row.Cells[1].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[1].Format.Alignment = ParagraphAlignment.Left;
            row.Cells[1].MergeDown        = 3;

            row.Cells[2].AddParagraph("Just Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.justval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            row = table.AddRow();

            row.Cells[2].AddParagraph("Assessed Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.assdval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();

            row.Cells[2].AddParagraph("Exempt Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.exempt_val));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;



            row = table.AddRow();

            row.Cells[2].AddParagraph("Taxable Value");
            row.Cells[2].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)100, (byte)125, (byte)254));
            row.Cells[2].Format.Alignment = ParagraphAlignment.Left;

            row.Cells[3].AddParagraph("$" + String.Format("{0:#,#######0}", obCama.taxblval));
            row.Cells[3].Shading.Color    = MigraDoc.DocumentObjectModel.Color.FromRgbColor((byte)255, new MigraDoc.DocumentObjectModel.Color((byte)255, (byte)236, (byte)255));
            row.Cells[3].Format.Alignment = ParagraphAlignment.Left;


            // 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.FromInch(0.4025), XUnit.FromInch(7.88), XUnit.FromInch(3.85), table);

            //table.SetEdge(0, 0, 2, 2, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Colors.Yellow);

            // table.SetEdge(0, 0, 6, 2, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Colors.Yellow);


            XFont    font2       = new XFont("Verdana", 5, XFontStyle.Regular);
            DateTime tdate       = DateTime.Now;
            String   datestr     = tdate.ToString("MMM dd,yyy");
            String   metadataMSG = String.Format("map created {0}", datestr);

            gfx.DrawString(metadataMSG, font2, XBrushes.Black, new XRect(480, 769, 100, 20), XStringFormats.Center);

            /*
             * double xp = 0;
             * double yp = 0;
             * int numticks = 10;
             *
             * double w_inc = page.Width.Value / (double)numticks;
             * double h_inc = page.Height.Value / (double)numticks;
             *
             * for (int x = 0; x < numticks; x++)
             * {
             * for (int y = 0; y < numticks; y++)
             * {
             *
             *     xp = (double)x * w_inc;
             *     yp = (double)y * h_inc;
             *
             *     XUnit xu_x = new XUnit(xp, XGraphicsUnit.Point);
             *     XUnit xu_y = new XUnit(yp, XGraphicsUnit.Point);
             *
             *     xu_x.ConvertType(XGraphicsUnit.Inch);
             *     xu_y.ConvertType(XGraphicsUnit.Inch);
             *
             *     gfx.DrawString("+", font, XBrushes.Red, new XRect( xp,  yp, 5, 5), XStringFormats.Center);
             *     String lbl = String.Format("{0},{1}-{2},{3}", (int)xp, (int)yp, xu_x.Value, xu_y.Value);
             *     gfx.DrawString(lbl, font, XBrushes.Red, new XRect( xp + 5,  yp + 5, 5, 5), XStringFormats.Center);
             *
             *
             * }
             *
             * }
             */
        }
Exemplo n.º 24
0
        public override void StrokePath(double strokeWidth, int color)
        {
            var pen = new XPen(XColor.FromArgb(color), XUnit.FromPoint(strokeWidth).Millimeter);

            XGraphics.DrawPath(pen, CurrentPath);
        }
Exemplo n.º 25
0
        protected void ProduceResponse(string title, Render.RenderContext ctx, Size tileSize,
                                       int rot          = 0, float translateX = 0, float translateY = 0,
                                       bool transparent = false)
        {
            // New-style Options
            // TODO: move to ParseOptions (maybe - requires options to be parsed after stylesheet creation?)
            if (GetBoolOption("sscoords", defaultValue: false))
            {
                ctx.styles.hexCoordinateStyle = Stylesheet.HexCoordinateStyle.Subsector;
            }

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

            double devicePixelRatio = GetDoubleOption("dpr", 1);

            if (Accepts(MediaTypeNames.Application.Pdf))
            {
                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 - 2013 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 XGraphics is Points
                    page.Width  = XUnit.FromPoint(tileSize.Width);
                    page.Height = XUnit.FromPoint(tileSize.Height);

                    PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page);

                    RenderToGraphics(ctx, rot, translateX, translateY, gfx);

                    using (var stream = new MemoryStream())
                    {
                        document.Save(stream, closeStream: false);

                        SetCommonResponseHeaders();

                        Response.ContentType = MediaTypeNames.Application.Pdf;
                        Response.AddHeader("content-length", stream.Length.ToString());
                        Response.AddHeader("content-disposition", "inline;filename=\"map.pdf\"");
                        Response.BinaryWrite(stream.ToArray());
                        Response.Flush();
                        stream.Close();
                    }

                    return;
                }
            }

            using (var bitmap = new Bitmap((int)Math.Floor(tileSize.Width * devicePixelRatio), (int)Math.Floor(tileSize.Height * devicePixelRatio), PixelFormat.Format32bppArgb))
            {
                if (transparent)
                {
                    bitmap.MakeTransparent();
                }

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

                    using (var graphics = XGraphics.FromGraphics(g, new XSize(tileSize.Width * devicePixelRatio, tileSize.Height * devicePixelRatio)))
                    {
                        if (devicePixelRatio != 0)
                        {
                            graphics.ScaleTransform(devicePixelRatio);
                        }

                        RenderToGraphics(ctx, rot, translateX, translateY, graphics);
                    }
                }

                SetCommonResponseHeaders();
                BitmapResponse(ctx.styles, bitmap, transparent ? Util.MediaTypeName_Image_Png : null);
            }
        }
        /// <summary>
        /// Generates a barcode PDF and returns the number of barcodes generated
        /// </summary>
        /// <param name="outputPath"></param>
        /// <param name="numberOfPages"></param>
        /// <returns>The number of barcodes generated</returns>
        public int GenerateBarcodes(string outputPath)
        {
            if (NumberOfPages > 0)
            {
                PdfDocument document = new PdfDocument();
                document.Info.Title = "Inventory Barcodes";
                long barcodeToUse      = GeneratedBarcode.GetLatestBarcodeNumber() + 1;
                var  barcodesGenerated = new List <long>();
                for (int i = 0; i < NumberOfPages; i++)
                {
                    PdfPage page = document.AddPage();
                    page.Size = PageSize;

                    XGraphics gfx    = XGraphics.FromPdfPage(page);
                    XFont     font   = new XFont("Verdana", 20, XFontStyle.Bold);
                    XUnit     yCoord = XUnit.FromInch(1); // pixels
                    gfx.DrawString("Inventory Barcodes", font, XBrushes.Black,
                                   new XRect(0, yCoord, page.Width, page.Height), XStringFormats.TopCenter);

                    yCoord += XUnit.FromInch(0.7);

                    // Generate a barcode
                    var barcodeCreator = new BarcodeLib.Barcode();
                    barcodeCreator.ImageFormat   = ImageFormat.Jpeg;
                    barcodeCreator.IncludeLabel  = true;
                    barcodeCreator.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                    barcodeCreator.Alignment     = BarcodeLib.AlignmentPositions.CENTER;

                    bool  isPageFull  = false;
                    XUnit imageHeight = XUnit.FromPoint(60);
                    while (!isPageFull)
                    {
                        var   isWidthFull = false;
                        XUnit xCoord      = XUnit.FromInch(1);
                        while (!isWidthFull)
                        {
                            var image = barcodeCreator.Encode(BarcodeType, barcodeToUse.ToString());
                            if (image != null)
                            {
                                // make sure images are a good size based on DPI
                                // TODO: There has got to be a better way to make things fairly consistent across computers
                                // with different DPI. This is ridiculous. I love WPF most of the time with its DPI
                                // help, but in this case.......ugh. Images come out a little blurry this way
                                // on computers with a non-192 DPI.
                                double ratioTo192   = (192 / image.VerticalResolution);
                                int    resizeHeight = (int)(image.Height / ratioTo192);
                                int    resizeWidth  = (int)(image.Width / ratioTo192);
                                image = ResizeImage(image, resizeWidth, resizeHeight, (int)image.VerticalResolution);
                                // ok, now we can draw.
                                XImage pdfImage = XImage.FromBitmapSource(ConvertImageToBitmapImage(image));
                                gfx.DrawImage(pdfImage, xCoord, yCoord);
                                xCoord     += XUnit.FromPoint(pdfImage.PointWidth);
                                imageHeight = XUnit.FromPoint(pdfImage.PointHeight);
                                var   blah = XUnit.FromPoint(image.Width);
                                XUnit spaceBetweenBarcodes = XUnit.FromInch(0.75);
                                if (xCoord + XUnit.FromPoint(pdfImage.PointWidth) + spaceBetweenBarcodes > page.Width - XUnit.FromInch(1))
                                {
                                    isWidthFull = true;
                                }
                                barcodesGenerated.Add(barcodeToUse);
                                barcodeToUse++;
                                xCoord += spaceBetweenBarcodes;
                            }
                            else
                            {
                                // failure case
                                isWidthFull = true;
                                isPageFull  = true;
                                break;
                            }
                        }
                        yCoord += imageHeight;
                        yCoord += XUnit.FromInch(0.7);
                        if (yCoord + imageHeight > page.Height - XUnit.FromInch(1))
                        {
                            isPageFull = true;
                        }
                    }
                }
                if (!IsDryRun)
                {
                    // save the fact that we generated barcodes
                    GeneratedBarcode.AddGeneratedCodes(barcodesGenerated, DateTime.Now, 1);
                    // save the document and start the process for viewing the pdf
                    document.Save(outputPath);
                    Process.Start(outputPath);
                }
                return(barcodesGenerated.Count);
            }
            return(0);
        }
Exemplo n.º 27
0
        void GenerateReport(PdfDocument document)
        {
            //PdfPage page = document.AddPage();
            PdfPage page = document.Pages[0];

            XGraphics gfx = XGraphics.FromPdfPage(page);

            // HACK²
            gfx.MUH  = PdfFontEncoding.Unicode;
            gfx.MFEH = PdfFontEmbedding.Default;

            XFont font = new XFont("Verdana", 4, XFontStyle.Regular);

            // map image origin
            //gfx.DrawString("O", font, XBrushes.Red, new XRect(20, 42, 12, 12), XStringFormats.Center);

            //gfx.DrawString("O", font, XBrushes.Blue, new XRect(220,  42, 12, 12), XStringFormats.Center);

            //gfx.DrawString("O", font, XBrushes.Green, new XRect(20, 120, 12, 12), XStringFormats.Center);
            //XPen penn = new XPen(XColors.DarkSeaGreen, 1.5);
            //gfx.DrawRectangle(penn, 420, 42, 153, 63);


            // ovmap image origin
            //gfx.DrawString("X", font, XBrushes.Red, new XRect(5, 5, 798, 1144), XStringFormats.Center);



            //gfx.DrawString("+", font, XBrushes.Red, new XRect(5, 5, 100, 1299), XStringFormats.Center);


            XPen pen = new XPen(XColors.DarkTurquoise, 0.5);

            //gfx.DrawRectangle(pen, 20, 42, 150, 40);

            Document doc = new Document();

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



            int numlabels = label_al.Count;
            int pagenum   = 1;

            double xp = 0;
            double yp = 0;

            double x_marg = 20.0;
            double y_marg = 42.0;

            double w_inc = 200;
            double h_inc = 78;

            double label_width = 150.0;

            double rows = 3;
            double cols = 10;

            //Debug.Print(String.Format("{0} labels", numlabels));

            for (int l = 0; l < numlabels; l++)
            {
                // get label
                MailingLabel ml = (MailingLabel)label_al[l];

                // get col and row

                int irow = 1;
                int icol = 1;

                if ((l + 1) <= ((int)rows * (int)cols))
                {
                    try
                    {
                        irow = (((int)l / 3));
                        icol = (l % 3);
                    }
                    catch (Exception ex)
                    {
                    }

                    //Debug.Print(String.Format("{0}  ->  {1}   {2}", l, irow, icol));
                }
                else if ((l + 1) > (((int)rows * (int)cols)))
                {
                    //if ((l + 1) == (((int)rows * (int)cols) + 1))

                    int recpp = ((int)rows * (int)cols);
                    int modpp = (l - 1) % (recpp);
                    //Debug.Print(String.Format("{0}   mod {1}", l, modpp));
                    if (modpp == 0)
                    {
                        // print second page
                        page = document.Pages.Add();
                        //page = document.Pages[1];
                        gfx = XGraphics.FromPdfPage(page);
                        // HACK²
                        gfx.MUH  = PdfFontEncoding.Unicode;
                        gfx.MFEH = PdfFontEmbedding.Default;
                        pagenum++;
                        Debug.Print(String.Format("   pagenum {0}", pagenum));
                    }

                    try
                    {
                        irow = (((l - ((pagenum - 1) * 30)) / 3)) - 1;
                        icol = ((l - ((pagenum - 1) * 30)) % 3);
                    }
                    catch (Exception ex)
                    {
                    }
                }

                double xloc = x_marg + (icol * w_inc);
                double yloc = y_marg + (irow * h_inc);

                //Debug.Print(String.Format("          {0}   {1}", xloc, yloc));

                //gfx.DrawRectangle(pen, xloc, yloc, 150, 60);


                Section sec = doc.AddSection();
                // Add a single paragraph with some text and format information.
                Paragraph para = sec.AddParagraph();
                para.Format.Alignment    = ParagraphAlignment.Justify;
                para.Format.KeepTogether = true;

                para.Format.Font.Name  = "Verdana";
                para.Format.Font.Size  = Unit.FromPoint(6);
                para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;
                para.Format.Font.Bold  = true;
                //para.AddText("Duisism odigna acipsum delesenisl ");
                //para.AddFormattedText("ullum in velenit", TextFormat.Bold);

                //para.AddText(ml.lname + "\r\n" + ml.laddr);

                String lbltext = "";
                lbltext += ml.lname;
                para.AddText(ml.lname);



                Paragraph para2 = sec.AddParagraph();
                if (ml.laddr_1 != "")
                {
                    lbltext += "\r\n" + ml.laddr_1;
                    //para.AddText(ml.laddr_1);
                    //para.AddLineBreak();


                    para2.Format.Alignment    = ParagraphAlignment.Justify;
                    para2.Format.KeepTogether = true;

                    para2.Format.Font.Name  = "Verdana";
                    para2.Format.Font.Size  = Unit.FromPoint(6);
                    para2.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;
                    para2.Format.Font.Bold  = true;
                    para2.AddText(ml.laddr_1);
                }
                if (ml.laddr_2 != "")
                {
                    lbltext += "\r\n" + ml.laddr_2;
                }
                if (ml.laddr_3 != "")
                {
                    lbltext += "\r\n" + ml.laddr_3;
                }
                if (ml.lcity != "")
                {
                    lbltext += "\r\n" + ml.lcity + ", " + ml.lstate;
                }
                if (ml.lcntry != "")
                {
                    lbltext += "\r\n" + ml.lcntry;
                }
                if (ml.zip != "")
                {
                    lbltext += "\r\n" + ml.zip;
                }

                //para.AddText(ml.lcity + ", " + ml.lstate + " " + ml.zip);
                //para.AddLineBreak();

                //para.AddText(lbltext);

                Paragraph para3 = sec.AddParagraph();
                para3.Format.Alignment    = ParagraphAlignment.Justify;
                para3.Format.KeepTogether = true;

                para3.Format.Font.Name  = "Verdana";
                para3.Format.Font.Size  = Unit.FromPoint(6);
                para3.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black;
                para3.Format.Font.Bold  = true;
                para3.AddText(ml.lcity + ", " + ml.lstate + " " + ml.zip);


                //para.Format.Borders.Distance = "1pt";
                //para.Format.Borders.Color = Colors.Orange;

                // 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.  29, 705, 555, 43
                docRenderer.RenderObject(gfx, XUnit.FromPoint(xloc), XUnit.FromPoint(yloc + 15.0), XUnit.FromPoint((int)label_width), para);
                docRenderer.RenderObject(gfx, XUnit.FromPoint(xloc), XUnit.FromPoint(yloc + 23.0), XUnit.FromPoint((int)label_width), para2);
                docRenderer.RenderObject(gfx, XUnit.FromPoint(xloc), XUnit.FromPoint(yloc + 31.0), XUnit.FromPoint((int)label_width), para3);
            }



            // You always need a MigraDoc document for rendering.

            /*
             * Section sec = doc.AddSection();
             * // Add a single paragraph with some text and format information.
             * Paragraph para = sec.AddParagraph();
             * para.Format.Alignment = ParagraphAlignment.Justify;
             * para.Format.Font.Name = "Verdana";
             * para.Format.Font.Size = Unit.FromPoint(6);
             * para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
             * para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
             * //para.AddText("Duisism odigna acipsum delesenisl ");
             * //para.AddFormattedText("ullum in velenit", TextFormat.Bold);
             *
             * para.AddText("BillyBob\r\n123 Deep Elem Lane");
             *
             *
             * //para.Format.Borders.Distance = "1pt";
             * //para.Format.Borders.Color = Colors.Orange;
             *
             * // 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.  29, 705, 555, 43
             * docRenderer.RenderObject(gfx, XUnit.FromPoint(38), XUnit.FromPoint(710), XUnit.FromPoint(535), para);
             *
             */


            /*
             * double xp = 0;
             * double yp = 0;
             * int numticks = 8;
             *
             * double w_inc = page.Width.Value / (double)numticks;
             * double h_inc = page.Height.Value / (double)numticks;
             *
             * for (int x = 0; x < numticks; x++)
             * {
             * for (int y = 0; y < numticks; y++)
             * {
             *
             *     xp = (double)x * w_inc;
             *     yp = (double)y * h_inc;
             *
             *     XUnit xu_x = new XUnit(xp, XGraphicsUnit.Point);
             *     XUnit xu_y = new XUnit(yp, XGraphicsUnit.Point);
             *
             *     xu_x.ConvertType(XGraphicsUnit.Inch);
             *     xu_y.ConvertType(XGraphicsUnit.Inch);
             *
             *     gfx.DrawString("+", font, XBrushes.Red, new XRect( xp,  yp, 5, 5), XStringFormats.Center);
             *     //String lbl = String.Format("{0}    \r\n{1}   {2}\r\n    {3}", (int)xp, (int)yp, xu_x.Value, xu_y.Value);
             *     String lbl = String.Format("{0}  {1}",xu_x.Value, xu_y.Value);
             *     gfx.DrawString(lbl, font, XBrushes.Red, new XRect( xp + 5,  yp + 5, 5, 5), XStringFormats.Center);
             *
             *
             * }
             *
             * }
             */
        }
Exemplo n.º 28
0
        public static void DrawGraphics()
        {
            var document = new PdfDocument();
            var page     = document.AddPage();
            var formGfx  = PdfSharpCore.Drawing.XGraphics.FromPdfPage(page);
            // Create an empty XForm object with the specified width and height
            // A form is bound to its target document when it is created. The reason is that the form can
            // share fonts and other objects with its target document.
            XForm form = new XForm(document, XUnit.FromPoint(40), XUnit.FromPoint(600));

            // Create an XGraphics object for drawing the contents of the form.
            // XGraphics formGfx = XGraphics.FromForm(form);
            // Draw a large transparent rectangle to visualize the area the form occupies
            XColor back = XColors.Orange;

            back.A = 0.2;
            XSolidBrush brush = new XSolidBrush(back);

            formGfx.DrawRectangle(brush, 40, 600, 200, 80);

            // On a form you can draw...
            // ... text
            formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("OpenSans", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormats.TopLeft);

            //XPen pen = XPens.LightBlue.Clone();
            //pen.Width = 2.5;

            // ... graphics like Bézier curves
            //  formGfx.DrawBeziers(pen, XPoint.ParsePoints("30,120 80,20 100,140 175,33.3"));

            // ... raster images like GIF files
            // XGraphicsState state = formGfx.Save();
            //formGfx.RotateAtTransform(17, new XPoint(30, 30));
            //var pathName = Path.GetFullPath("Rotating_earth_(large).gif");
            //var xImage = XImage.FromFile(pathName);
            //formGfx.DrawImage(xImage, 20, 20);
            //formGfx.Restore(state);

            //// ... and forms like XPdfForm objects
            //state = formGfx.Save();
            //formGfx.RotateAtTransform(-8, new XPoint(165, 115));
            //formGfx.DrawImage(XPdfForm.FromFile("SomeLayout.pdf"), new XRect(140, 80, 50, 50 * Math.Sqrt(2)));
            //formGfx.Restore(state);

            // When you finished drawing on the form, dispose the XGraphic object.
            //formGfx.Dispose();



            //step 2
            //// Draw the form on the page of the document in its original size
            //formGfx.DrawImage(form, 20, 50);

            //// Draw it stretched
            //formGfx.DrawImage(form, 300, 100, 250, 40);
            //// Draw and rotate it
            //const int d = 25;
            //for (int idx = 0; idx < 360; idx += d)
            //{
            //    formGfx.DrawImage(form, 300, 480, 200, 200);
            //    formGfx.RotateAtTransform(d, new XPoint(300, 480));
            //}

            document.Save("graphics.pdf");
            //formGfx.Dispose();
        }