예제 #1
1
        /// <summary>
        /// Renders the matrix code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
                case CodeDirection.RightToLeft:
                    gfx.RotateAtTransform(180, position);
                    break;

                case CodeDirection.TopToBottom:
                    gfx.RotateAtTransform(90, position);
                    break;

                case CodeDirection.BottomToTop:
                    gfx.RotateAtTransform(-90, position);
                    break;
            }

            XPoint pos = position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            if (MatrixImage == null)
                MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);

            if (QuietZone > 0)
            {
                XSize sizeWithZone = new XSize(Size.Width, Size.Height);
                sizeWithZone.Width = sizeWithZone.Width / (Columns + 2 * QuietZone) * Columns;
                sizeWithZone.Height = sizeWithZone.Height / (Rows + 2 * QuietZone) * Rows;

                XPoint posWithZone = new XPoint(pos.X, pos.Y);
                posWithZone.X += Size.Width / (Columns + 2 * QuietZone) * QuietZone;
                posWithZone.Y += Size.Height / (Rows + 2 * QuietZone) * QuietZone;

                gfx.DrawRectangle(XBrushes.White, pos.X, pos.Y, Size.Width, Size.Height);
                gfx.DrawImage(MatrixImage, posWithZone.X, posWithZone.Y, sizeWithZone.Width, sizeWithZone.Height);
            }
            else
                gfx.DrawImage(MatrixImage, pos.X, pos.Y, Size.Width, Size.Height);

            gfx.Restore(state);
        }
예제 #2
0
        private static XPoint DrawLineArrowInternal(XGraphics gfx, XPen pen, XSolidBrush brush, double x, double y, double angle, Core2D.Style.ArrowStyle style)
        {
            XPoint pt;
            var    rt = new XMatrix();
            var    c  = new XPoint(x, y);

            rt.RotateAtPrepend(angle, c);
            double rx = style.RadiusX;
            double ry = style.RadiusY;
            double sx = 2.0 * rx;
            double sy = 2.0 * ry;

            switch (style.ArrowType)
            {
            default:
            case Core2D.Style.ArrowType.None:
            {
                pt = new XPoint(x, y);
            }
            break;

            case Core2D.Style.ArrowType.Rectangle:
            {
                pt = rt.Transform(new XPoint(x - sx, y));
                var rect = new XRect(x - sx, y - ry, sx, sy);
                gfx.Save();
                gfx.RotateAtTransform(angle, c);
                DrawRectangleInternal(gfx, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                gfx.Restore();
            }
            break;

            case Core2D.Style.ArrowType.Ellipse:
            {
                pt = rt.Transform(new XPoint(x - sx, y));
                gfx.Save();
                gfx.RotateAtTransform(angle, c);
                var rect = new XRect(x - sx, y - ry, sx, sy);
                DrawEllipseInternal(gfx, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                gfx.Restore();
            }
            break;

            case Core2D.Style.ArrowType.Arrow:
            {
                pt = rt.Transform(new XPoint(x, y));
                var p11 = rt.Transform(new XPoint(x - sx, y + sy));
                var p21 = rt.Transform(new XPoint(x, y));
                var p12 = rt.Transform(new XPoint(x - sx, y - sy));
                var p22 = rt.Transform(new XPoint(x, y));
                DrawLineInternal(gfx, pen, style.IsStroked, ref p11, ref p21);
                DrawLineInternal(gfx, pen, style.IsStroked, ref p12, ref p22);
            }
            break;
            }

            return(pt);
        }
        private static void CrateBack(XUnit pageWdith, XUnit pageHeight, PdfDocument document, string currentCardType)
        {
            PdfPage page = document.AddPage();

            page.Width  = new XUnit(pageWdith.Millimeter, XGraphicsUnit.Millimeter);
            page.Height = new XUnit(pageHeight.Millimeter, XGraphicsUnit.Millimeter);


            XGraphics gfx = XGraphics.FromPdfPage(page);

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

            gfx.ScaleAtTransform(-1, 1, page.Width / 2, page.Height / 2);

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



            var costSize = new XSize(new XUnit(23, XGraphicsUnit.Millimeter), font.Height);

            var costMarginRight = new XUnit(5, XGraphicsUnit.Millimeter);



            var actionRect     = new XRect(costMarginRight, new XUnit(5, XGraphicsUnit.Millimeter), pageHeight * 2, costSize.Height * 2);
            var actionTextRect = actionRect;

            actionTextRect.Height = costSize.Height;
            actionTextRect.Offset(new XUnit(3, XGraphicsUnit.Millimeter), 0);

            gfx.TranslateTransform(new XUnit(3, XGraphicsUnit.Millimeter), 0);
            gfx.RotateAtTransform(90, actionRect.TopLeft);

            gfx.DrawRoundedRectangle(XPens.MidnightBlue, XBrushes.DarkSlateBlue, actionRect, new XSize(10, 10));

            gfx.ScaleAtTransform(1, -1, actionTextRect.Center);

            gfx.DrawString(currentCardType, font, XBrushes.White,
                           actionTextRect, XStringFormats.TopLeft);
            gfx.ScaleAtTransform(1, -1, actionTextRect.Center);


            gfx.RotateAtTransform(-90, actionRect.TopLeft);
            gfx.TranslateTransform(new XUnit(-3, XGraphicsUnit.Millimeter), 0);

            var circle = new XRect(new XUnit(-3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(10, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter));

            gfx.DrawEllipse(XPens.MidnightBlue, XBrushes.White, circle);
        }
예제 #4
0
        private static void DrawQrCode(int imageSize, int qrCodeSize, int offsetLeft, int offsetTop, XRect rectangle, Uri uri, string iconPath)
        {
            var icon   = new Bitmap(Image.FromFile(iconPath));
            var bitmap = new QrCode().GenerateImage(uri, icon);
            var ms     = new MemoryStream();

            bitmap.Save(ms, ImageFormat.Bmp);

            var image = XImage.FromStream(ms);

            var state = gfx.Save();

            gfx.RotateAtTransform(-90, new XPoint(rectangle.Left + offsetLeft, rectangle.Top + offsetTop));
            gfx.DrawImage(image, rectangle.Left + offsetLeft, rectangle.Top + offsetTop, qrCodeSize, qrCodeSize);
            gfx.Restore(state);
        }
예제 #5
0
        protected XRect DrawTickLabel(XGraphics gfx, string tickLabel, XPoint point, XSize size, AxisRendererInfo xari)
        {
            XRect  labelArea   = new XRect(point, size);
            double rotateAngle = xari._axis.TickLabelAngle;

            // Draw rotated text.
            gfx.RotateAtTransform(rotateAngle, labelArea.Center);
            gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, point);
            gfx.RotateAtTransform(-rotateAngle, labelArea.Center);

            // Simulate rotation to get the rotated bounding box
            var transformation = RotateByDegrees(rotateAngle, labelArea.Center);

            labelArea.Transform(transformation);
            return(labelArea);
        }
예제 #6
0
 protected void PreRender(ref XGraphics gfx, double offsetLeft, double offsetTop, double scaleX, double scaleY)
 {
     gfx.Save();
     gfx.RotateAtTransform(Angle, new XPoint(Util.MillimeterToPoint(offsetLeft + Left + (Width / 2.0)),
                                             Util.MillimeterToPoint(offsetTop + Top + (Height / 2.0))));
     hasExecutedPreRender = true;
 }
예제 #7
0
        public static void CreateBarcodeAsText()
        {
            using (PdfDocument document = PdfReader.Open("BarCodeTest3.pdf", PdfDocumentOpenMode.Modify))
            {
                //create new pdf page
                PdfPage page = document.Pages[0];
                //page.Width = XUnit.FromMillimeter(210);
                //page.Height = XUnit.FromMillimeter(297);

                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 font = new XFont(FontNames.MrvCode39S, 20, XFontStyle.Regular, options);

                    XTextFormatter tf = new XTextFormatter(gfx);
                    tf.DrawString("*00112001*", font, XBrushes.Black, new XRect(10, 100, 20, 232), XStringFormats.TopLeft);
                    gfx.RotateAtTransform(270, new XPoint(page.Height / 2d, page.Width / 2d));
                    tf.DrawString("*00112001*", font, XBrushes.Black, new XRect(-30, -80, 100, 232), XStringFormats.TopLeft);
                    //var stringFormat = new XStringFormat();
                    ////create the barcode from string
                    //var point1 = new XPoint(10, 10);
                    //var point2 = new XPoint(100, 130);
                    //gfx.DrawString("*00112001*", font, XBrushes.Black, new XRect(40, 100, 250, 232), stringFormat);
                    //gfx.RotateAtTransform(-90, new XPoint(page.Height / 2d, page.Width / 2d));
                    ////create the barcode from string
                    //gfx.DrawString("*00112001*", font, XBrushes.Black, new XRect(point1, point2), stringFormat);
                }


                document.Save("BarCodeTest38.pdf");
            }
        }
예제 #8
0
        public static void DrawImageOnPage(PdfPage page, XImage image, double x, double y, double page_rotation)
        {
            XGraphics gfx = XGraphics.FromPdfPage(page);

            // there is a bug for landscape PDF files
            Console.WriteLine("orientation {0}", page.Orientation);
            if (page.Orientation == PdfSharp.PageOrientation.Landscape)
            {
                // Translate coordinate system. To solve a strange problem.
                gfx.RotateTransform(-90);
                gfx.TranslateTransform(-page.Height, 0);
            }

            // rotate
            if (page_rotation != 0.0)
            {
                Console.WriteLine("rotate {0} degree", page_rotation);

                XPoint centerPoint = new XPoint(page.Width / 2, page.Height / 2);
                gfx.RotateAtTransform(-page_rotation, centerPoint);
            }

            gfx.DrawImage(image, x, y);
            gfx.Dispose();
        }
예제 #9
0
        public static void DrawBeziers()
        {
            string fn = @"input.pdf";

            using (PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(fn))
            {
                // 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.
                using (XForm form = new XForm(document, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55)))
                {
                    // Create an XGraphics object for drawing the contents of the form.
                    using (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, -10000, -10000, 20000, 20000);

                        // On a form you can draw...

                        // ... text
                        formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 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));
                        formGfx.DrawImage(XImage.FromFile("../../../../../../dev/XGraphicsLab/images/Test.gif"), 20, 20);
                        formGfx.Restore(state);

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

                        // When you finished drawing on the form, dispose the XGraphic object.
                    } // End Using formGfx
                }     // End Using form
            }         // End Using document
        }
예제 #10
0
        /// <summary>
        /// Renders the matrix code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
            case CodeDirection.RightToLeft:
                gfx.RotateAtTransform(180, position);
                break;

            case CodeDirection.TopToBottom:
                gfx.RotateAtTransform(90, position);
                break;

            case CodeDirection.BottomToTop:
                gfx.RotateAtTransform(-90, position);
                break;
            }

            XPoint pos = position + CalcDistance(Anchor, AnchorType.TopLeft, Size);

            if (MatrixImage == null)
            {
                MatrixImage = DataMatrixImage.GenerateMatrixImage(Text, Encoding, Rows, Columns);
            }

            if (QuietZone > 0)
            {
                XSize sizeWithZone = new XSize(Size.Width, Size.Height);
                sizeWithZone.Width  = sizeWithZone.Width / (Columns + 2 * QuietZone) * Columns;
                sizeWithZone.Height = sizeWithZone.Height / (Rows + 2 * QuietZone) * Rows;

                XPoint posWithZone = new XPoint(pos.X, pos.Y);
                posWithZone.X += Size.Width / (Columns + 2 * QuietZone) * QuietZone;
                posWithZone.Y += Size.Height / (Rows + 2 * QuietZone) * QuietZone;

                gfx.DrawRectangle(XBrushes.White, pos.X, pos.Y, Size.Width, Size.Height);
                gfx.DrawImage(MatrixImage, posWithZone.X, posWithZone.Y, sizeWithZone.Width, sizeWithZone.Height);
            }
            else
            {
                gfx.DrawImage(MatrixImage, pos.X, pos.Y, Size.Width, Size.Height);
            }

            gfx.Restore(state);
        }
예제 #11
0
        /// <summary>
        /// Renders the OMR code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (this.direction)
            {
            case CodeDirection.RightToLeft:
                gfx.RotateAtTransform(180, position);
                break;

            case CodeDirection.TopToBottom:
                gfx.RotateAtTransform(90, position);
                break;

            case CodeDirection.BottomToTop:
                gfx.RotateAtTransform(-90, position);
                break;
            }

            //XPoint pt = center - this.size / 2;
            XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, this.anchor, this.size);
            uint   value;

            uint.TryParse(this.text, out value);
#if true
            // HACK: Project Wallenwein: set LK
            value |= 1;
            this.synchronizeCode = true;
#endif
            if (this.synchronizeCode)
            {
                XRect rect = new XRect(pt.x, pt.y, this.makerThickness, this.size.height);
                gfx.DrawRectangle(brush, rect);
                pt.x += 2 * this.makerDistance;
            }
            for (int idx = 0; idx < 32; idx++)
            {
                if ((value & 1) == 1)
                {
                    XRect rect = new XRect(pt.x + idx * this.makerDistance, pt.y, this.makerThickness, this.size.height);
                    gfx.DrawRectangle(brush, rect);
                }
                value = value >> 1;
            }
            gfx.Restore(state);
        }
예제 #12
0
파일: CodeOmr.cs 프로젝트: Core2D/PDFsharp
        /// <summary>
        /// Renders the OMR code.
        /// </summary>
        protected internal override void Render(XGraphics gfx, XBrush brush, XFont font, XPoint position)
        {
            XGraphicsState state = gfx.Save();

            switch (Direction)
            {
                case CodeDirection.RightToLeft:
                    gfx.RotateAtTransform(180, position);
                    break;

                case CodeDirection.TopToBottom:
                    gfx.RotateAtTransform(90, position);
                    break;

                case CodeDirection.BottomToTop:
                    gfx.RotateAtTransform(-90, position);
                    break;
            }

            //XPoint pt = center - size / 2;
            XPoint pt = position - CodeBase.CalcDistance(AnchorType.TopLeft, Anchor, Size);
            uint value;
            uint.TryParse(Text, out value);
#if true
            // HACK: Project Wallenwein: set LK
            value |= 1;
            _synchronizeCode = true;
#endif
            if (_synchronizeCode)
            {
                XRect rect = new XRect(pt.X, pt.Y, _makerThickness, Size.Height);
                gfx.DrawRectangle(brush, rect);
                pt.X += 2 * _makerDistance;
            }
            for (int idx = 0; idx < 32; idx++)
            {
                if ((value & 1) == 1)
                {
                    XRect rect = new XRect(pt.X + idx * _makerDistance, pt.Y, _makerThickness, Size.Height);
                    gfx.DrawRectangle(brush, rect);
                }
                value = value >> 1;
            }
            gfx.Restore(state);
        }
예제 #13
0
파일: Page.cs 프로젝트: Joris-Pieters/MCDRI
        public void PdfDraw(XGraphics g)
        {
            XStringFormat formatDec = new XStringFormat();

            formatDec.Alignment     = XStringAlignment.Near;
            formatDec.LineAlignment = XLineAlignment.Center;
            XSolidBrush b = new XSolidBrush(Color.Black);

            for (int i = 0; i < ParentTest.Paper.Blocks.X - 1; i += 7)
            {
                g.DrawEllipse(b, new Rectangle(DesignZone.Left + ((Settings.blockWidth - Settings.blockHeight) / 2) + (i * Settings.blockWidth),
                                               DesignZone.Bottom - 1 - Settings.blockHeight, Settings.blockHeight, Settings.blockHeight));
            }
            for (int i = 0; i < ParentTest.Paper.Blocks.Y - 1; i += 7)
            {
                g.DrawEllipse(b, new Rectangle(DesignZone.Right - 1 - Settings.blockHeight, DesignZone.Top + (i * Settings.blockHeight),
                                               Settings.blockHeight, Settings.blockHeight));
            }
            g.DrawEllipse(b, new Rectangle(DesignZone.Right - 1 - Settings.blockHeight, DesignZone.Bottom - 1 - Settings.blockHeight,
                                           Settings.blockHeight, Settings.blockHeight));

            XGraphicsState gs = g.Save();

            g.RotateAtTransform(90, new XPoint(DesignZone.Right - 1 - (int)(Settings.blockHeight / 2), DesignZone.Top + (2 * Settings.blockHeight)));
            XStringFormat pageNumFormat = new XStringFormat();

            pageNumFormat.LineAlignment = XLineAlignment.Far;

            g.Restore(gs);

            var   barcode = BarCode.CreateArray(Hash());
            Point start   = new Point(DesignZone.Left + (4 * Settings.blockWidth) - 57, DesignZone.Bottom - 25);

            XBrush bGray = new XSolidBrush(XColor.FromArgb(Program.Test.BarCodeGray, Program.Test.BarCodeGray, Program.Test.BarCodeGray));

            for (int i = 0; i < 19; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (barcode[i, j] == 0)
                    {
                        g.DrawRectangle(bGray, start.X + (i * 6), start.Y + (j * 6), 6, 6);
                    }
                }
            }

            foreach (TestElement testElement in TestElements)
            {
                testElement.PdfDraw(g);
            }
        }
예제 #14
0
        private void DrawBody(XGraphics gfx)
        {
            for (int x = 0; x < 15; x++)
            {
                XGraphicsState state1 = gfx.Save();
                gfx.RotateAtTransform(-70, new XPoint(200 + (x * 20), 250));
                gfx.DrawString("Long Text Here : Always expect more " + (x + 1), FontUtility.HeaderContentNormal, XBrushes.Black, new XPoint(200 + (x * 20), 250));
                gfx.Restore(state1);
            }

            for (int x = 0; x < 15; x++)
            {
                XPen pen = new XPen(XColors.Gray, 1);
                gfx.DrawRectangle(pen, XBrushes.White, new XRect(195 + (x * 20), 260, 8, 25));
                if (x % 2 == 0)
                {
                    gfx.DrawRectangle(XBrushes.LightGray, new XRect(195 + (x * 20), 270, 8, 15));
                }
            }

            int lineHeight = 20;
            int topHeight  = 0;

            for (int x = 0; x < 20; x++)
            {
                topHeight = 300 + lineHeight * x;
                gfx.DrawLine(XPens.LightGray, 50, topHeight, 490, topHeight);

                if (x % 2 == 0)
                {
                    gfx.DrawString("&", FontUtility.BodyContentTick, XBrushes.Green, new XRect(50, topHeight + 8, 10, 0));
                }
                else
                {
                    gfx.DrawString("#", FontUtility.BodyContentTick, XBrushes.Green, new XRect(50, topHeight + 8, 10, 0));
                }
                gfx.DrawString("Associate Consultant " + (x + 1), FontUtility.BodyContentNormal, XBrushes.Black, new XRect(60, topHeight + 8, 100, 0));
                gfx.DrawString("8/2011 - present", FontUtility.BodyContentNormal, XBrushes.Black, new XRect(50, topHeight + 16, 100, 0));
                for (int y = 0; y < 16; y++)
                {
                    XPen pen = new XPen(XColors.Gray, 1);
                    gfx.DrawLine(pen, new XPoint(190 + (y * 20), topHeight), new XPoint(190 + (y * 20), (topHeight + 20)));
                    if (y % 2 == 0)
                    {
                        gfx.DrawImage(XImage.FromFile("../Images/Green-Tick.png"), new XRect(190 + (y * 20) + 5, topHeight + 6, 10, 10));
                    }
                }
            }
            gfx.DrawLine(XPens.LightGray, 50, topHeight + lineHeight, 490, topHeight + lineHeight);
        }
예제 #15
0
        public static IDisposable RotateTransform(this XGraphics gfx, Elements.Element element, XElement context, IXmlNamespaceResolver resolver)
        {
            //rotation = Math.PI * 2 * rotation / 360.0;
            var state    = gfx.SaveState();
            var rotation = element.Rotation.GetValue(context, resolver);
            var origin   = element.RotationOrigin.GetValue(context, resolver);

            var frame = element.Position.GetValue(context, resolver);

            origin = new XPoint(origin.X * frame.Width + frame.X, origin.Y * frame.Height + frame.Y);

            gfx.RotateAtTransform(rotation, origin);
            return(state);
        }
예제 #16
0
        private void Draw8UpPageFor8PageBooklet(XGraphics gfx, int pageNumber, double xorigin, double yorigin)
        {
            var state = gfx.Save();

            _inputPdf.PageNumber = pageNumber;
            var box = new XRect(xorigin, yorigin, _paperWidth / 4, _paperHeight / 2);

            if (yorigin == 0)
            {
                var pagePoint = new XPoint(xorigin + _paperWidth / 8, yorigin + _paperHeight / 4);
                gfx.RotateAtTransform(180, pagePoint);
            }
            gfx.DrawImage(_inputPdf, box);
            gfx.Restore(state);
        }
예제 #17
0
        public static void DrawFormWithOptions(XGraphics gfx, XForm form)
        {
            // Draw the form on the page of the document in its original size
            gfx.DrawImage(form, 20, 50);

            // Draw it stretched
            gfx.DrawImage(form, 300, 100, 250, 40);

            // Draw and rotate it
            const int d = 25;

            for (int idx = 0; idx < 360; idx += d)
            {
                gfx.DrawImage(form, 300, 480, 200, 200);
                gfx.RotateAtTransform(d, new XPoint(300, 480));
            }
        }
예제 #18
0
        static void Main()
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

            // Create a font
            XFont font = new XFont("Verdana", 16);

            // Create a new page
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page, XPageDirection.Downwards);

            gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormats.Default);

            // Step 1: Create an XForm and draw some graphics on it

            // 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.FromMillimeter(70), XUnit.FromMillimeter(55));

            // 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, -10000, -10000, 20000, 20000);

            // On a form you can draw...

            // ... text
            formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 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));
            formGfx.DrawImage(XImage.FromFile("../../../../../../dev/XGraphicsLab/images/Test.gif"), 20, 20);
            formGfx.Restore(state);

            // ... and forms like XPdfForm objects
            state = formGfx.Save();
            formGfx.RotateAtTransform(-8, new XPoint(165, 115));
            formGfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/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 XPdfForm on your PDF page like an image

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

#if true
            // Draw it stretched
            gfx.DrawImage(form, 300, 100, 250, 40);

            // Draw and rotate it
            const int d = 25;
            for (int idx = 0; idx < 360; idx += d)
            {
                gfx.DrawImage(form, 300, 480, 200, 200);
                gfx.RotateAtTransform(d, new XPoint(300, 480));
            }
#endif

            // Save the document...
            const string filename = "XForms_tempfile.pdf";
            document.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);
        }
        public override void RenderPage(XGraphics gfx)
        {
#if true_
            // Create a new PDF document
            //PdfDocument document = new PdfDocument();

            // Create a font
            XFont font = new XFont("Verdana", 16);

            // Create a new page
            //PdfPage page = document.AddPage();
            //XGraphics gfx = XGraphics.FromPdfPage(page);
            //gfx.DrawString("XPdfForm Sample", font, XBrushes.DarkGray, 15, 25, XStringFormat.Default);

            // Step 1: Create an XForm and draw some graphics on it

            // 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(gfx, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55));

            // 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, -10000, -10000, 20000, 20000);


            // On a form you can draw...

            //// ... text
            //formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormat.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));
            //formGfx.DrawImage(XImage.FromFile("../../../../XGraphicsLab/images/Test.gif"), 20, 20);
            //formGfx.Restore(state);

            //// ... and forms like XPdfForm objects
            //state = formGfx.Save();
            //formGfx.RotateAtTransform(-8, new XPoint(165, 115));
            //formGfx.DrawImage(XPdfForm.FromFile("../../../../PDFs/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 XPdfForm on your PDF page like an image

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

#if true_
            // Draw it stretched
            gfx.DrawImage(form, 300, 100, 250, 40);

            // Draw and rotate it
            int d = 25;
            for (int idx = 0; idx < 360; idx += d)
            {
                gfx.DrawImage(form, 300, 480, 200, 200);
                gfx.RotateAtTransform(d, new XPoint(300, 480));
            }
#endif

            //// Save the document...
            //string filename = "XForms.pdf";
            //document.Save(filename);
            //// ...and start a viewer.
            //Process.Start(filename);
#else
            //base.RenderPage(gfx);

            int   cx = 300;
            int   cy = 240;
            XForm form;
            //if (gfx.PdfPage == null)
            form = new XForm(gfx, cx, cy);
            //else
            //  form = new XForm(gfx.PdfPage.Owner, cx, cy);

            double dx = gfx.PageSize.Width;
            double dy = gfx.PageSize.Height;

            XGraphics   formgfx = XGraphics.FromForm(form);
            XSolidBrush brush   = new XSolidBrush(XColor.FromArgb(128, 0, 255, 255));
            formgfx.DrawRectangle(brush, -1000, -1000, 2000, 2000);
            formgfx.DrawLine(XPens.Red, 0, 0, cx, cy);
            formgfx.DrawLine(XPens.Red, cx, 0, 0, cy);

            XFont font = new XFont("Times", 16, XFontStyle.BoldItalic);
            formgfx.DrawString("Text", font, XBrushes.DarkOrange, 0, 0, XStringFormats.TopLeft);
            formgfx.DrawString("Text", font, XBrushes.DarkOrange, new XRect(0, 0, cx, cy), XStringFormats.Center);

            // Required to finish drawing the form. Both cases are correct.
#if true
            formgfx.Dispose();
#else
            form.DrawingFinished();
#endif
            gfx.DrawImage(form, 50, 50);

#if true_
            gfx.TranslateTransform(dx / 2, dy / 2);
            gfx.RotateTransform(-25);
            gfx.TranslateTransform(-dx / 2, -dy / 2);

            gfx.DrawImage(form, (dx - form.Width) / 2, (dy - form.Height) / 2, form.Width, form.Height);
#endif
#endif
        }
예제 #20
0
        public bool generatePdf()
        {
            if (!File.Exists(scaleNamesPath))
            {
                MessageBox.Show(scaleNamesPath + " is not a valid scale names file");
                return(false);
            }
            string[] scaleNames = File.ReadAllLines(scaleNamesPath);

            PdfDocument pdf = new PdfDocument();

            pdf.Info.Title = "My First PDF";
            XFont font = new XFont("Microsoft Sans Serif", 12, XFontStyle.Regular);

            // Set all the page sizes and orientation
            PdfPage basicPage = pdf.AddPage();

            basicPage.Orientation = PageOrientation.Landscape;
            basicPage.Width       = XUnit.FromInch(11);
            basicPage.Height      = XUnit.FromInch(8.5);
            XGraphics graphBasic = XGraphics.FromPdfPage(basicPage);

            PdfPage page2 = pdf.AddPage();

            page2.Orientation = PageOrientation.Landscape;
            page2.Width       = XUnit.FromInch(11);
            page2.Height      = XUnit.FromInch(8.5);
            XGraphics graph2 = XGraphics.FromPdfPage(page2);

            PdfPage page3 = pdf.AddPage();

            page3.Orientation = PageOrientation.Landscape;
            page3.Width       = XUnit.FromInch(11);
            page3.Height      = XUnit.FromInch(8.5);
            XGraphics graph3 = XGraphics.FromPdfPage(page3);

            PdfPage page4 = pdf.AddPage();

            page4.Orientation = PageOrientation.Landscape;
            page4.Width       = XUnit.FromInch(11);
            page4.Height      = XUnit.FromInch(8.5);
            XGraphics graph4 = XGraphics.FromPdfPage(page4);

            PdfPage page5 = pdf.AddPage();

            page5.Orientation = PageOrientation.Landscape;
            page5.Width       = XUnit.FromInch(11);
            page5.Height      = XUnit.FromInch(8.5);
            XGraphics      gfx = XGraphics.FromPdfPage(page5);
            XGraphicsState gs  = gfx.Save();

            gfx.TranslateTransform(600, 750);
            gfx.RotateTransform(-90);
            gfx.TranslateTransform(-600, -750);
            XTextFormatter tf = new XTextFormatter(gfx);

            tf.DrawString(critOutputPrimary, font, XBrushes.Black, new XRect(800, 200, 500, 500), XStringFormats.TopLeft);
            gfx.Restore(gs);

            // If the person has too many entries on the crit items page
            // It overflows here to another page
            if (critOutputSecondary != "")
            {
                PdfPage page6 = pdf.AddPage();
                page6.Orientation = PageOrientation.Landscape;
                page6.Width       = XUnit.FromInch(11);
                page6.Height      = XUnit.FromInch(8.5);
                XGraphics      gfx2 = XGraphics.FromPdfPage(page6);
                XGraphicsState gs2  = gfx2.Save();
                gfx2.TranslateTransform(600, 750);
                //gfx.ScaleTransform(0.6);
                gfx2.RotateTransform(-90);
                gfx2.TranslateTransform(-600, -750);
                XTextFormatter tf2 = new XTextFormatter(gfx2);
                tf2.DrawString(critOutputSecondary, font, XBrushes.Black, new XRect(800, 200, 500, 500), XStringFormats.TopLeft);
                //gfx.RotateTransform(-90);
                gfx2.Restore(gs2);
            }

            string[] userInfo = { "Name: " + testTaker.lastName + ", " + testTaker.firstName,
                                  "Gender: " + gender + "  Address:______________________________",
                                  "Occupation:____________________   Date Tested: " + testTaker.date,
                                  "Education:_______  Age: " + testTaker.age + "  Marital Status:________________",
                                  "Referred By:_________________________________________",
                                  "MMPI Code:_________________________________________" };

            for (int i = 0; i < 6; i++)
            {
                graphBasic.DrawString(userInfo[i], font, XBrushes.Black, new XRect(430, (i * 15) + 15, 0, 0), XStringFormats.TopLeft);
            }

            // Logo in upper left
            graphBasic.DrawImage(XImage.FromFile(baseFolder + "logo.jpg"), new XRect(40, 15, 250, 110));

            // Draw the charts onto the pdf
            try
            {
                graphBasic.DrawImage(XImage.FromFile(indivBasePath + "\\" + testTaker.lastName + testTaker.firstName + "1.png"), new XRect(30, 120, 760, 450));
                graph2.DrawImage(XImage.FromFile(indivBasePath + "\\" + testTaker.lastName + testTaker.firstName + "2.png"), new XRect(-25, 0, 830, 615));
                graph3.DrawImage(XImage.FromFile(indivBasePath + "\\" + testTaker.lastName + testTaker.firstName + "3.png"), new XRect(-25, 0, 830, 615));
                graph4.DrawImage(XImage.FromFile(indivBasePath + "\\" + testTaker.lastName + testTaker.firstName + "4.png"), new XRect(-25, 0, 830, 615));
            }
            catch (Exception)
            {
                MessageBox.Show("PDF Failed: Image in use - Try restarting the program");
                return(false);
            }

            if (barLabel.Checked)
            {
                graph2.RotateAtTransform(-90, new XPoint(430, 430));
                graph3.RotateAtTransform(-90, new XPoint(430, 430));
                graph4.RotateAtTransform(-90, new XPoint(430, 430));

                for (int i = 0; i < 26; i++)
                {
                    graph2.DrawString(scaleNames[i], font, XBrushes.White, new XRect(330, (i * 28.66) + 41, 0, 0), XStringFormats.TopLeft);
                    graph3.DrawString(scaleNames[i + 26], font, XBrushes.White, new XRect(328, (i * 28.66) + 41, 0, 0), XStringFormats.TopLeft);
                }


                for (int i = 0; i < 22; i++)
                {
                    graph4.DrawString(scaleNames[i + 52], font, XBrushes.White, new XRect(328, (i * 33.96) + 43, 0, 0), XStringFormats.TopLeft);
                }
            }

            string pdfFilename = indivBasePath + testTaker.lastName + testTaker.firstName + ".pdf";

            pdf.Save(pdfFilename);
            if (File.Exists(pdfFilename))
            {
                MessageBox.Show("PDF Success at " + pdfFilename);
            }
            else
            {
                MessageBox.Show("PDF Failed at " + pdfFilename);
                return(false);
            }

            return(true);
        }
예제 #21
0
        private static void GeneratePDF()
        {
            PdfDocument document = new PdfDocument();

            bool enable_pdf_compression = bool.Parse(ConfigurationManager.AppSettings["enablePDFCompression"]);

            if (enable_pdf_compression)
            {
                document.Options.FlateEncodeMode = PdfFlateEncodeMode.BestCompression;
                document.Options.UseFlateDecoderForJpegImages = PdfUseFlateDecoderForJpegImages.Automatic;
                document.Options.NoCompression = false;

                document.Options.CompressContentStreams = true;
            }

            int current_images = 0;
            int progress       = 0;
            int max            = imaged_cards.cards.Count;

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

            bool enable_compression = bool.Parse(ConfigurationManager.AppSettings["enableImageCompression"]);

            ResizeSettings settings = new ResizeSettings();

            string compressionFormat = ConfigurationManager.AppSettings["compressionFormat"];

            switch (compressionFormat)
            {
            case "png":
            case "jpg":
            case "gif":
                settings.Format = compressionFormat;
                break;

            case ".png":
            case ".jpg":
            case ".gif":
                settings.Format = compressionFormat.Substring(1);
                break;

            case "jpeg":
            case ".jpeg":
                settings.Format = "jpg";
                break;
            }

            int maxHeight = int.Parse(ConfigurationManager.AppSettings["maxHeight"]);

            if (maxHeight > 0)
            {
                settings.MaxHeight = maxHeight;
            }

            int quality = int.Parse(ConfigurationManager.AppSettings["imageQuality"]);

            if (quality > 0 && quality <= 100)
            {
                settings.Quality = quality;
            }

            foreach (var entry in imaged_cards.cards)
            {
                ClearCurrentConsoleLine();
                Console.Write("\tProgress: [" + progress.ToString() + "/" + max.ToString() + "]");


                for (int i = 0; i < entry.Value; ++i)
                {
                    XImage img;

                    if (enable_compression)
                    {
                        MemoryStream stream = new MemoryStream();
                        ImageBuilder.Current.Build(entry.Key.GetCachedImage(), stream, settings);
                        img = XImage.FromStream(stream);
                    }
                    else
                    {
                        img = XImage.FromFile(entry.Key.GetCachedImage());
                    }

                    double a4_width  = 210.0;
                    double a4_height = 297.0;

                    double w_factor = gfx.PageSize.Width;
                    double h_factor = gfx.PageSize.Height;

                    // A4 = 210x297 mm , MTG 'CC' format = 54 x 85 mm
                    // 40 mm total, 20 mm side margin horizontal
                    // 27 mm total, 13.5mm side margin vertical

                    double x = 20.0 / a4_width * w_factor;
                    double y = 13.5 / a4_height * h_factor;
                    double w = 85.0 / a4_width * w_factor;
                    double h = 54.0 / a4_height * h_factor;

                    double column = (current_images % 2);
                    double row    = 0.26 + (current_images / 2); // I really don't know why 0.26 is the perfect number, trial and error

                    var state = gfx.Save();

                    gfx.RotateAtTransform(-90.0, new XPoint(x, y));
                    gfx.TranslateTransform(-x - h * row, y + w * column);
                    gfx.DrawImage(img, 0, 0, h, w);

                    gfx.Restore(state);

                    if (++current_images % 10 == 0)
                    {
                        current_images = 0;

                        gfx.Dispose();

                        page = document.AddPage();
                        gfx  = XGraphics.FromPdfPage(page);
                    }
                }

                ++progress;
                ClearCurrentConsoleLine();
                Console.Write("\tProgress: [" + progress.ToString() + "/" + max.ToString() + "]");
            }
            Console.WriteLine(" ");

            document.Save("cards.pdf");
        }
        /// <summary>
        /// Draws the horizontal X axis.
        /// </summary>
        internal override void Draw()
        {
            XGraphics         gfx  = this.rendererParms.Graphics;
            ChartRendererInfo cri  = (ChartRendererInfo)this.rendererParms.RendererInfo;
            AxisRendererInfo  xari = cri.xAxisRendererInfo;

            double xMin          = xari.MinimumScale;
            double xMax          = xari.MaximumScale;
            double xMajorTick    = xari.MajorTick;
            double xMinorTick    = xari.MinorTick;
            double xMaxExtension = xari.MajorTick;

            // Draw tick labels. Each tick label will be aligned centered.
            int    countTickLabels = (int)xMax;
            double tickLabelStep   = xari.Width;

            if (countTickLabels != 0)
            {
                tickLabelStep = xari.Width / countTickLabels;
            }

            //XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + /*xari.TickLabelsHeight +*/ xari.MajorTickMarkWidth);
            XPoint startPos = new XPoint(xari.X + tickLabelStep / 2, xari.Y + xari.TickLabelsHeight);

            if (xari.MajorTickMark != TickMarkType.None)
            {
                startPos.Y += xari.MajorTickMarkWidth;
            }

            foreach (XSeries xs in xari.XValues)
            {
                for (int idx = 0; idx < countTickLabels && idx < xs.Count; ++idx)
                {
                    XValue xv = xs[idx];
                    if (xv != null)
                    {
                        string tickLabel = xv.Value;
                        XSize  size      = gfx.MeasureString(tickLabel, xari.TickLabelsFont);

                        XGraphicsState state  = null;
                        int            margin = 0;
                        if (xs.TextRotation != default)
                        {
                            state  = gfx.Save();
                            margin = 20;
                            gfx.RotateAtTransform(xs.TextRotation, new XPoint(startPos.X - size.Width / 2, startPos.Y + margin));
                        }

                        gfx.DrawString(tickLabel, xari.TickLabelsFont, xari.TickLabelsBrush, startPos.X - size.Width / 2, startPos.Y + margin);

                        if (xs.TextRotation != default && state != null)
                        {
                            gfx.Restore(state);
                        }
                    }
                    startPos.X += tickLabelStep;
                }
            }

            // Draw axis.
            // First draw tick marks, second draw axis.
            double majorTickMarkStart = 0, majorTickMarkEnd = 0,
                   minorTickMarkStart = 0, minorTickMarkEnd = 0;

            GetTickMarkPos(xari, ref majorTickMarkStart, ref majorTickMarkEnd, ref minorTickMarkStart, ref minorTickMarkEnd);

            LineFormatRenderer lineFormatRenderer = new LineFormatRenderer(gfx, xari.LineFormat);

            XPoint[] points = new XPoint[2];

            // Minor ticks.
            if (xari.MinorTickMark != TickMarkType.None)
            {
                int    countMinorTickMarks = (int)(xMax / xMinorTick);
                double minorTickMarkStep   = xari.Width / countMinorTickMarks;
                startPos.X = xari.X;
                for (int x = 0; x <= countMinorTickMarks; x++)
                {
                    points[0].X = startPos.X + minorTickMarkStep * x;
                    points[0].Y = minorTickMarkStart;
                    points[1].X = points[0].X;
                    points[1].Y = minorTickMarkEnd;
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Major ticks.
            if (xari.MajorTickMark != TickMarkType.None)
            {
                int    countMajorTickMarks = (int)(xMax / xMajorTick);
                double majorTickMarkStep   = xari.Width;
                if (countMajorTickMarks != 0)
                {
                    majorTickMarkStep = xari.Width / countMajorTickMarks;
                }
                startPos.X = xari.X;
                for (int x = 0; x <= countMajorTickMarks; x++)
                {
                    points[0].X = startPos.X + majorTickMarkStep * x;
                    points[0].Y = majorTickMarkStart;
                    points[1].X = points[0].X;
                    points[1].Y = majorTickMarkEnd;
                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Axis.
            if (xari.LineFormat != null)
            {
                points[0].X = xari.X;
                points[0].Y = xari.Y;
                points[1].X = xari.X + xari.Width;
                points[1].Y = xari.Y;
                if (xari.MajorTickMark != TickMarkType.None)
                {
                    points[0].X -= xari.LineFormat.Width / 2;
                    points[1].X += xari.LineFormat.Width / 2;
                }
                lineFormatRenderer.DrawLine(points[0], points[1]);
            }

            // Draw axis title.
            AxisTitleRendererInfo atri = xari.axisTitleRendererInfo;

            if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
            {
                XRect rect = new XRect(xari.Rect.Right / 2 - atri.AxisTitleSize.Width / 2, xari.Rect.Bottom,
                                       atri.AxisTitleSize.Width, 0);
                gfx.DrawString(atri.AxisTitleText, atri.AxisTitleFont, atri.AxisTitleBrush, rect);
            }
        }
예제 #23
0
        public IActionResult PrintOrder()
        {
            try
            {
                // Create new PDF document
                PdfDocument document = new PdfDocument();
                var         time     = document.Info.CreationDate;
                document.Info.Title   = "PDFsharp Clock Demo";
                document.Info.Author  = "Arjan van Bavelgem";
                document.Info.Subject = "Server time: " + time.ToString("F", CultureInfo.InvariantCulture);

                for (int i = 0; i < 1; i++)
                {
                    // Create new page
                    PdfPage page = document.AddPage();
                    page.Size        = PageSize.A5;
                    page.Orientation = PageOrientation.Landscape;
                    page.Width       = XUnit.FromMillimeter(170);
                    page.Height      = XUnit.FromMillimeter(170);

                    // Create graphics object and draw clock
                    XGraphics gfx = XGraphics.FromPdfPage(page);
                    gfx.RotateAtTransform(270, new XPoint(170, 270));
                    // Create a font
                    XFont font = new XFont("Times New Roman", 16, XFontStyle.Regular);

                    //get address for test
                    var address = _addressRepository.GetAddressById(i + 6);
                    var naam    = string.Concat(address.Voornaam, address.Tussenvoegsel != null ? " " + address.Tussenvoegsel : " ", address.Achternaan);
                    // Draw the text
                    gfx.DrawString(string.Concat(address.Voornaam, address.Tussenvoegsel != null ? " " + address.Tussenvoegsel + " " : " ", address.Achternaan), font, XBrushes.Black, new XRect(100, 40, page.Width, page.Height), XStringFormats.CenterLeft);
                    gfx.DrawString(string.Concat(address.Straat, " ", address.Huisnummer, " ", address.HuisnummerToevoeging), font, XBrushes.Black, new XRect(100, 60, page.Width, page.Height), XStringFormats.CenterLeft);
                    gfx.DrawString(string.Concat(address.Postcode, "  ", address.Plaats), font, XBrushes.Black, new XRect(100, 80, page.Width, page.Height), XStringFormats.CenterLeft);
                    if (address.LandId != Constants.DefaultCountryNlId)
                    {
                        gfx.DrawString(string.Concat(_countryRepository.GetById(address.LandId)), font, XBrushes.Black, new XRect(100, 100, page.Width, page.Height), XStringFormats.CenterLeft);
                    }
                }


                //voor vierkante enveloppen begin

                //// Create new page
                //PdfPage page = document.AddPage();
                //page.Size = PageSize.A5;
                //page.Width = XUnit.FromMillimeter(170);
                //page.Height = XUnit.FromMillimeter(170);

                //// Create graphics object and draw clock
                //XGraphics gfx = XGraphics.FromPdfPage(page);

                //// Create a font
                //XFont font = new XFont("Times New Roman", 16, XFontStyle.Regular);

                ////get address for test
                //var address = _addressRepository.GetAddressById(i + 6);
                //var naam = string.Concat(address.Voornaam, address.Tussenvoegsel != null ? " " + address.Tussenvoegsel : " ", address.Achternaan);
                //// Draw the text
                //gfx.DrawString(string.Concat(address.Voornaam, address.Tussenvoegsel != null ? " " + address.Tussenvoegsel  + " " : " ", address.Achternaan), font, XBrushes.Black, new XRect(150, 0, page.Width, page.Height), XStringFormats.CenterLeft);
                //gfx.DrawString(string.Concat(address.Straat, " ", address.Huisnummer, " ", address.HuisnummerToevoeging), font, XBrushes.Black, new XRect(150, 20, page.Width, page.Height), XStringFormats.CenterLeft);
                //gfx.DrawString(string.Concat(address.Postcode, "  ", address.Plaats), font, XBrushes.Black, new XRect(150, 40, page.Width, page.Height), XStringFormats.CenterLeft);
                //if (address.LandId != Constants.DefaultCountryNlId)
                //{
                //    gfx.DrawString(string.Concat(_countryRepository.GetById(address.LandId)), font, XBrushes.Black, new XRect(150, 60, page.Width, page.Height), XStringFormats.CenterLeft);
                //}

                //voor vierkante enveloppen eind

                // Send PDF to browser
                MemoryStream stream = new MemoryStream();



                document.Save(stream, false);
                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.Headers.Add("content-length", stream.Length.ToString());

                return(File(stream, "application/pdf", "test.pdf"));

                //byte[] image = Convert.FromBase64String(_base64Image2);
                //Response.Body.WriteAsync(stream.ToArray());
                ////Response.BinaryWrite(stream.ToArray());
                //Response.Body.Flush();
                //stream.Close();
                ////Response.End();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(null);
        }
예제 #24
0
        // draws a single Paper Wallet in to a PdfSharp XForm
        private PdfSharp.Drawing.XForm getSingleWallet(PdfDocument doc, WalletBundle b, XImage imgArtwork, string address, string privkey, int numberWithinBatch, bool layoutDebugging)
        {
            WalletTemplate t = b.template;

            double width  = t.widthMM;
            double height = t.heightMM;

            XUnit walletSizeWide = XUnit.FromMillimeter(width);
            XUnit walletSizeHigh = XUnit.FromMillimeter(height);

            PdfSharp.Drawing.XForm form = new PdfSharp.Drawing.XForm(doc, walletSizeWide, walletSizeHigh);


            using (XGraphics formGfx = XGraphics.FromForm(form))
            {
                XGraphicsState state = formGfx.Save();

                bool interpolateArtwork = true;
                bool interpolateQRcodes = false;

                // XImage imgArtwork is now provided by caller, so this process only has to be done ONCE - because the artwork does not change between Wallets in a run!
                //XImage imgArtwork = XImage.FromGdiPlusImage(b.getArtworkImage());
                imgArtwork.Interpolate = interpolateArtwork;

                formGfx.DrawImage(imgArtwork, new RectangleF(0f, 0f, (float)walletSizeWide.Point, (float)walletSizeHigh.Point));

                // draw the QR codes and legible-text things

                // Address
                // QR
                Bitmap bmpAddress = BtcAddress.QR.EncodeQRCode(address);
                XImage imgAddress = XImage.FromGdiPlusImage(bmpAddress);
                imgAddress.Interpolate = interpolateQRcodes;

                XUnit addressQrLeft = XUnit.FromMillimeter(t.addressQrLeftMM);
                XUnit addressQrTop  = XUnit.FromMillimeter(t.addressQrTopMM);
                XUnit addressQrSize = XUnit.FromMillimeter(t.addressQrSizeMM);

                // only print Address QR if called for
                if (t.addressQrSizeMM > 0.1)
                {
                    XRect addressQrRect = new XRect(addressQrLeft.Point, addressQrTop.Point, addressQrSize.Point, addressQrSize.Point);
                    formGfx.DrawImage(imgAddress, addressQrRect);
                }

                // text address
                string         addressSplitForLines = addressOrReferencePrep(address, t.addressTextCharsPerLine, t.addressTextContentVariant, numberWithinBatch);
                XFont          fontAddress          = new XFont(t.addressTextFontName, t.addressTextFontSize, t.addressTextFontStyle);
                XTextFormatter tf = new XTextFormatter(formGfx);

                XUnit addressTxtLeft   = XUnit.FromMillimeter(t.addressTextLeftMM);
                XUnit addressTxtTop    = XUnit.FromMillimeter(t.addressTextTopMM);
                XUnit addressTxtWidth  = XUnit.FromMillimeter(t.addressTextWidthMM);
                XUnit addressTxtHeight = XUnit.FromMillimeter(t.addressTextHeightMM);

                XRect addressRect = new XRect(addressTxtLeft.Point, addressTxtTop.Point, addressTxtWidth.Point, addressTxtHeight.Point);
                tf.Alignment = XParagraphAlignment.Center;

                TextRotation addressTxtRotation        = t.addressTextRotation;
                double       addressTxtRotationDegrees = RotationMarkerToDegrees(addressTxtRotation);

                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XBrushes.PowderBlue, addressRect);
                }

                XPoint rotateCentre      = new XPoint(addressTxtLeft + (addressTxtWidth / 2), addressTxtTop + (addressTxtHeight / 2));
                XPoint matrixRotatePoint = new XPoint(addressRect.X + (addressRect.Width / 2), addressRect.Y + (addressRect.Height / 2));

                XMatrix rotateMatrix = new XMatrix();
                rotateMatrix.RotateAtAppend(addressTxtRotationDegrees, rotateCentre);
                addressRect.Transform(rotateMatrix);

                if (layoutDebugging)
                {
                    // draw a little tracer dot for where the centre of rotation is going to be
                    double rotateDotSize = 2.0;
                    formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize);
                }

                // maybe even do some rotation of the lovely text!
                formGfx.Save();

                formGfx.RotateAtTransform(addressTxtRotationDegrees, rotateCentre);
                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XPens.OrangeRed, addressRect);
                }

                if (t.addressTextWidthMM > 0.1)
                {
                    tf.DrawString(addressSplitForLines, fontAddress, t.GetBrushAddress, addressRect);
                }
                formGfx.Restore();

                // Privkey
                // QR
                Bitmap bmpPrivkey = BtcAddress.QR.EncodeQRCode(privkey);
                XImage imgPrivkey = XImage.FromGdiPlusImage(bmpPrivkey);
                imgPrivkey.Interpolate = interpolateQRcodes;

                XUnit privkeyQrLeft = XUnit.FromMillimeter(t.privkeyQrLeftMM);
                XUnit privkeyQrTop  = XUnit.FromMillimeter(t.privkeyQrTopMM);
                XUnit privkeyQrSize = XUnit.FromMillimeter(t.privkeyQrSizeMM);

                XRect privkeyQrRect = new XRect(privkeyQrLeft.Point, privkeyQrTop.Point, privkeyQrSize.Point, privkeyQrSize.Point);

                // only print privkey QR if specified - but you'd have to be an UTTER IDIOT to want to exclude this. Still, user input comes first!
                if (t.privkeyQrSizeMM > 0.1)
                {
                    formGfx.DrawImage(imgPrivkey, privkeyQrRect);
                }

                // legible
                string privkeySplitForLines = lineSplitter(privkey, t.privkeyTextCharsPerLine);

                XFont fontPrivkey = new XFont(t.privkeyTextFontName, t.privkeyTextFontSize, t.privkeyTextFontStyle);

                XUnit privkeyTxtLeft   = XUnit.FromMillimeter(t.privkeyTextLeftMM);
                XUnit privkeyTxtTop    = XUnit.FromMillimeter(t.privkeyTextTopMM);
                XUnit privkeyTxtWidth  = XUnit.FromMillimeter(t.privkeyTextWidthMM);
                XUnit privkeyTxtHeight = XUnit.FromMillimeter(t.privkeyTextHeightMM);

                TextRotation privkeyTxtRotation        = t.privkeyTextRotation;
                double       privkeyTxtRotationDegrees = RotationMarkerToDegrees(privkeyTxtRotation);

                XRect privkeyRect = new XRect(privkeyTxtLeft.Point, privkeyTxtTop.Point, privkeyTxtWidth.Point, privkeyTxtHeight.Point);

                if (layoutDebugging)
                {
                    // draw a tracer rectangle for the original un-rotated text rectangle
                    formGfx.DrawRectangle(XBrushes.PowderBlue, privkeyRect);
                }

                // rotate that lovely text around its middle when drawing!
                rotateCentre = new XPoint(privkeyTxtLeft + (privkeyTxtWidth / 2), privkeyTxtTop + (privkeyTxtHeight / 2));

                matrixRotatePoint = new XPoint(privkeyRect.X + (privkeyRect.Width / 2), privkeyRect.Y + (privkeyRect.Height / 2));

                rotateMatrix = new XMatrix();
                rotateMatrix.RotateAtAppend(privkeyTxtRotationDegrees, rotateCentre);
                privkeyRect.Transform(rotateMatrix);

                if (layoutDebugging)
                {
                    // draw a little tracer dot for where the centre of rotation is going to be
                    double rotateDotSize = 2.0;
                    formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize);
                }

                formGfx.Save();

                formGfx.RotateAtTransform(privkeyTxtRotationDegrees, rotateCentre);

                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XPens.OrangeRed, privkeyRect);
                }

                // only print privkey text if specified.
                if (t.privkeyTextWidthMM > 0.1)
                {
                    tf.DrawString(privkeySplitForLines, fontPrivkey, t.GetBrushPrivkey, privkeyRect);
                }

                formGfx.Restore();
            }



            return(form);
        }
        public static (PdfDocument document, (string crisisType, int startIndex)[]) CreateDocument(IEnumerable <CardData> cards, DateTime fileChanged, int currentInstance)
        {
            var pageWdith  = XUnit.FromInch(2.5);
            var pageHeight = XUnit.FromInch(3.5);


            PdfDocument document = new PdfDocument();

            document.Info.Title    = "Forschungs Karten";
            document.Info.Subject  = "Die Forschungskarten des spiels";
            document.Info.Author   = "Arbeitstitel Karthago";
            document.Info.Keywords = "Karten, Forschung, Karthago";


            //var maxOccurenceOfCard = cards.Max(x => x.Metadata.Times);
            int    counter         = 0;
            var    total           = cards.Sum(x => x.Metadata.Times);
            string currentCardType = null;
            var    resultList      = new List <(string crisisType, int startIndex)>();

            foreach (var card in cards)
            {
                if (card.Metadata.Type != null && currentCardType != null)
                {
                    // Create new Back
                    CrateBack(pageWdith, pageHeight, document, currentCardType);
                }

                if (card.Metadata.Type != null)
                {
                    resultList.Add((card.Metadata.Type, document.PageCount));
                }

                currentCardType = card.Metadata.Type ?? currentCardType;
                if (currentCardType is null)
                {
                    Console.WriteLine($"{currentInstance}: Did not found card metadata. SKIP");
                    continue;
                }
                var header = card.Content.FirstOrDefault(x => x is HeaderBlock);
                Console.WriteLine($"{currentInstance}: Working on <{header?.ToString() ?? "UNKNOWN TITLE"}> with {card.Metadata.Times} instances.");
                for (int i = 0; i < card.Metadata.Times; i++)
                {
                    Console.Write($"{i + 1}...");
                    counter++;

                    PdfPage page = document.AddPage();

                    page.Width  = new XUnit(pageWdith.Millimeter, XGraphicsUnit.Millimeter);
                    page.Height = new XUnit(pageHeight.Millimeter, XGraphicsUnit.Millimeter);


                    XGraphics gfx = XGraphics.FromPdfPage(page);
                    // HACK²
                    gfx.MUH = PdfFontEncoding.Unicode;
                    //gfx.MFEH = PdfFontEmbedding.Default;

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



                    var costSize = new XSize(new XUnit(23, XGraphicsUnit.Millimeter), font.Height);

                    var costMarginRight = new XUnit(5, XGraphicsUnit.Millimeter);



                    var actionRect     = new XRect(costMarginRight, new XUnit(5, XGraphicsUnit.Millimeter), pageHeight * 2, costSize.Height * 2);
                    var actionTextRect = actionRect;
                    actionTextRect.Height = costSize.Height;
                    actionTextRect.Offset(new XUnit(3, XGraphicsUnit.Millimeter), 0);

                    gfx.TranslateTransform(new XUnit(3, XGraphicsUnit.Millimeter), 0);
                    gfx.RotateAtTransform(90, actionRect.TopLeft);



                    gfx.DrawRoundedRectangle(XPens.MidnightBlue, XBrushes.DarkSlateBlue, actionRect, new XSize(10, 10));
                    gfx.DrawString(currentCardType, font, XBrushes.White,
                                   actionTextRect, XStringFormats.CenterLeft);

                    gfx.RotateAtTransform(-90, actionRect.TopLeft);
                    gfx.TranslateTransform(new XUnit(-3, XGraphicsUnit.Millimeter), 0);

                    var circle = new XRect(new XUnit(-3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(10, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter));

                    gfx.DrawEllipse(XPens.MidnightBlue, XBrushes.White, circle);

                    gfx.DrawString($"{card.Metadata.Duration:n0}", font, XBrushes.Black,
                                   circle, XStringFormats.Center);


                    var dateRec  = new XRect(new XUnit(13, XGraphicsUnit.Millimeter), pageHeight - new XUnit(2.5, XGraphicsUnit.Millimeter), new XUnit(13, XGraphicsUnit.Millimeter), new XUnit(3, XGraphicsUnit.Millimeter));
                    var dateFont = new XFont("Verdana", 7, XFontStyle.Regular);
                    gfx.DrawString(fileChanged.ToString(), dateFont, XBrushes.Gray, dateRec.TopLeft);
                    gfx.DrawString($"{counter}/{total}", dateFont, XBrushes.Gray, new XRect(0, 0, pageWdith - new XUnit(3, XGraphicsUnit.Millimeter), pageHeight - new XUnit(2.5, XGraphicsUnit.Millimeter)), XStringFormats.BottomRight);

                    // Create a new MigraDoc document
                    var doc = new Document();
                    doc.Info.Title   = "Krisen Karten";
                    doc.Info.Subject = "Die Krisenkarten des spiels";
                    doc.Info.Author  = "Arbeitstitel Karthago";


                    doc.DefaultPageSetup.PageWidth  = new Unit(pageWdith.Inch, UnitType.Inch);
                    doc.DefaultPageSetup.PageHeight = new Unit(pageHeight.Inch, UnitType.Inch);

                    doc.DefaultPageSetup.LeftMargin   = new Unit(13, UnitType.Millimeter);
                    doc.DefaultPageSetup.RightMargin  = new Unit(5, UnitType.Millimeter);
                    doc.DefaultPageSetup.BottomMargin = new Unit(10, UnitType.Millimeter);
                    doc.DefaultPageSetup.TopMargin    = new Unit(6, UnitType.Millimeter);

                    doc.DefineStyles();

                    //Cover.DefineCover(document);
                    //DefineTableOfContents(document);

                    DefineContentSection(doc);
                    card.Content.HandleBlocks(doc);


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

                    //XRect rect = new XRect(new XPoint(Unit.FromCentimeter(1).Value, Unit.FromCentimeter(3).Value), new XSize((pageWdith.Value - Unit.FromCentimeter(2).Value), (pageHeight.Value - Unit.FromCentimeter(4).Value)));

                    // Use BeginContainer / EndContainer for simplicity only. You can naturaly use you own transformations.
                    //XGraphicsContainer container = gfx.BeginContainer(rect, A4Rect, XGraphicsUnit.Point);

                    // Draw page border for better visual representation
                    //gfx.DrawRectangle(XPens.LightGray, A4Rect);

                    // Render the page. Note that page numbers start with 1.
                    docRenderer.RenderPage(gfx, 1);

                    // Note: The outline and the hyperlinks (table of content) does not work in the produced PDF document.

                    // Pop the previous graphical state
                    //gfx.EndContainer(container);
                }
                Console.WriteLine(" Finished card.");
            }
            CrateBack(pageWdith, pageHeight, document, currentCardType);


            //DefineParagraphs(document);
            //DefineTables(document);
            //DefineCharts(document);

            return(document, resultList.ToArray());
        }
예제 #26
0
        public override void PdfDraw(XGraphics g)
        {
            XBrush brush = new XSolidBrush(Color.Black);
            XPen   pen   = new XPen(Color.Black);
            XPen   pen2  = new XPen(Color.Gray);

            XStringFormat formatDec = new XStringFormat();

            formatDec.Alignment     = XStringAlignment.Near;
            formatDec.LineAlignment = XLineAlignment.Center;

            XStringFormat formatAlt = new XStringFormat();

            formatAlt.Alignment     = XStringAlignment.Center;
            formatAlt.LineAlignment = XLineAlignment.Center;

            XStringFormat formatNumber = new XStringFormat();

            formatNumber.Alignment     = XStringAlignment.Far;
            formatNumber.LineAlignment = XLineAlignment.Center;

            for (int i = 0; i < descriptionSplit.Count; i++)
            {
                g.DrawString(descriptionSplit[i], Settings.xfont, brush, new Point(Left + 2, Top + (int)((i + .5) * blockSize.Height)), formatDec);
            }
            if (Border)
            {
                g.DrawLine(new Pen(Color.FromArgb(128, 128, 128)), Left, Top + (descriptionSplit.Count * blockSize.Height), Left + Width - 1, Top + (descriptionSplit.Count * blockSize.Height));
            }

            int itemCount  = 1;
            int blockBegin = 0;

            for (int c = 0; c < Columns; c++)
            {
                int gridBegin = blockBegin * blockSize.Width;

                // Line separating columns
                if (Border)
                {
                    g.DrawLine(new Pen(Color.FromArgb(128, 128, 128)), Left + gridBegin, Top + (descriptionSplit.Count * blockSize.Height), Left + gridBegin, Top + Height - 1);
                }

                for (int a = 0; a < NumberOfAlternatives; a++)
                {
                    if (blocksForAlternatives == 1) // Place alternatives horizontally
                    {
                        g.DrawString(Alternatives[a], Settings.xfont, brush, new Point(Left + (int)(gridBegin + ((a + blocksForItemNames[c] + .5) * blockSize.Width)), Top + (int)((.5 + descriptionSplit.Count) * blockSize.Height)), formatAlt);
                    }
                    else // Place alternatives vertically
                    {
                        XGraphicsState gs = g.Save();
                        g.RotateAtTransform(90, new XPoint(Left + (int)(gridBegin + ((a + blocksForItemNames[c] + .5) * blockSize.Width)), Top + (int)((blocksForAlternatives + descriptionSplit.Count) * blockSize.Height)));
                        formatAlt.Alignment = XStringAlignment.Far;
                        g.DrawString(Alternatives[a], Settings.xfont, brush, new Point(Left + (int)(gridBegin + ((a + blocksForItemNames[c] + .5) * blockSize.Width)), Top + (int)((blocksForAlternatives + descriptionSplit.Count) * blockSize.Height)), formatAlt);
                        g.Restore(gs);
                    }
                    for (int r = 0; r < columnSplit[c]; r++)
                    {
                        g.DrawRectangle(pen2, Left + gridBegin + ((a + blocksForItemNames[c]) * blockSize.Width) + 4, Top + (r + descriptionSplit.Count + blocksForAlternatives) * blockSize.Height + 4, blockSize.Width - 8, blockSize.Height - 8);
                    }
                }
                for (int i = 0; i < columnSplit[c]; i++)
                {
                    g.DrawString(Items[itemCount - 1].Name, Settings.xfont, brush, new Point(Left + gridBegin + (blocksForItemNames[c] * blockSize.Width), Top + (int)((i + descriptionSplit.Count + blocksForAlternatives + .5) * blockSize.Height)), formatNumber);
                    itemCount++;
                }
                blockBegin += blocksForItemNames[c] + NumberOfAlternatives;
            }
            base.PdfDraw(g);
        }
        ///<summary>The only instance of this command.</summary>
        ///<param name="doc" RhinoDoc></param>
        ///<param name="mode" Run mode></param>
        ///<returns>returns sucess if doc is successfully created </returns>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            #region set all the file parameters

            pdfOptionForm = new PDFOptionForm();
            Application.Run(pdfOptionForm);
            getSelectedOption = PDFOptionForm.optionsSelected;

            myUniqueFileName = string.Format(@"{0}" + ext, Guid.NewGuid());
            string logFilePath = Rhino.ApplicationSettings.FileSettings.WorkingFolder + "\\Log-" + DateTime.Now.GetHashCode().ToString() + ".txt";
            string curveType   = "C";
            try
            {
                string[] checkFileName = Rhino.ApplicationSettings.FileSettings.RecentlyOpenedFiles()[0].ToString().Split('\\');
                int      checklength   = checkFileName.Length;
                rhinoFile = Rhino.ApplicationSettings.FileSettings.RecentlyOpenedFiles()[0].ToString().Split('\\')[--checklength];
            }
            catch (FileNotFoundException fnf) { logFile(fnf.Message); }
            catch (IndexOutOfRangeException ioor) { logFile(ioor.Message); }

            string rhinoFileName = rhinoFile.Split('.')[0];
            string filename      = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + rhinoFileName + "-" + myUniqueFileName;

            #endregion

            Rhino.RhinoApp.RunScript("-_Save Enter", false);

            logFile("Process started for ---> " + rhinoFileName + "-" + myUniqueFileName);

            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            XGraphics gfx  = XGraphics.FromPdfPage(page);
            XFont     font = new XFont("Verdana", 20, XFontStyle.Bold);

            #region Check the selected curve
            GetObject go = new GetObject();

            go.GroupSelect     = true;
            go.SubObjectSelect = false;
            go.EnableClearObjectsOnEntry(false);
            go.EnableUnselectObjectsOnExit(false);
            go.DeselectAllBeforePostSelect = false;
            go.EnableSelPrevious(true);
            go.EnablePreSelect(true, false);
            go.GeometryFilter = ObjectType.AnyObject;

            GetResult result = go.GetMultiple(1, -1);

            if (go.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(go.CommandResult());
            }

            RhinoApp.WriteLine("{0} objects are selected.", go.ObjectCount);

            #endregion

            // Process the list of objects
            logFile("Processing List of Object");

            #region set the paramenters for Xgraph to process shapes

            List <GeometryBase> geoList = new List <GeometryBase>();

            double minX, minY, maxX, maxY;
            minX = double.MaxValue;
            minY = double.MaxValue;

            maxX = double.MinValue;
            maxY = double.MinValue;

            List <Curve>      curveList      = new List <Curve>();
            List <TextEntity> textEntityList = new List <TextEntity>();

            List <Circle>   circleList = new List <Circle>();
            List <Polyline> polyList   = new List <Polyline>();
            Circle          circleCurve;
            Polyline        polygon;

            #endregion

            for (int i = 0; i < go.ObjectCount; i++)
            {
                // Check the type of the Object and process differently
                Curve curve = go.Object(i).Curve();

                if (go.Object(i).Curve().TryGetCircle(out circleCurve))
                {
                    circleList.Add(circleCurve);
                }
                if (go.Object(i).Curve().TryGetPolyline(out polygon))
                {
                    polyList.Add(polygon);
                }
                if (curve != null)
                {
                    curveList.Add(curve);
                }

                TextEntity te = go.Object(i).TextEntity();

                if (te != null)
                {
                    textEntityList.Add(te);
                }

                GeometryBase geo  = go.Object(i).Geometry();
                BoundingBox  bbox = geo.GetBoundingBox(Rhino.Geometry.Plane.WorldXY);

                if (bbox.Min.X < minX)
                {
                    minX = bbox.Min.X;
                }
                if (bbox.Min.Y < minY)
                {
                    minY = bbox.Min.Y;
                }
                if (bbox.Max.X > maxX)
                {
                    maxX = bbox.Max.X;
                }
                if (bbox.Max.Y > maxY)
                {
                    maxY = bbox.Max.Y;
                }

                geoList.Add(geo);
            }

            page.Height = maxY - minY;
            page.Width  = maxX - minX;


            foreach (GeometryBase g in geoList)
            {
                if (g.GetType().Equals(typeof(PolyCurve)))
                {
                    //System.Windows.Forms.MessageBox.Show("PolyCurve changed");
                    PolyCurve polyCurve = (PolyCurve)g;
                    curveType = "NC";
                    break;
                }
                else if (g.GetType().Equals(typeof(Curve)))
                {
                    System.Windows.Forms.MessageBox.Show("Curve");
                    Curve curve = (Curve)g;
                }
                else if (g.GetType().Equals(typeof(TextEntity)))
                {
                    System.Windows.Forms.MessageBox.Show("TextEntity");
                    TextEntity textEntity = (TextEntity)g;
                    curveType = "T";
                }
            }

            logFile("Checking the pattern");
            if (curveType.Equals("C") || curveType.Equals("T"))
            {
                logFile("Objects processed sucessfully");

                double x1, y1, width, height;

                logFile("Creating Circles on the PDF");
                //Loop to draw the circles
                foreach (Circle c in circleList)
                {
                    XPen pen = new XPen(XColors.Black, 0.5);
                    x1     = c.BoundingBox.Min.X - minX;
                    y1     = maxY - c.BoundingBox.Max.Y;
                    width  = c.BoundingBox.Max.X - c.BoundingBox.Min.X;
                    height = c.BoundingBox.Max.Y - c.BoundingBox.Min.Y;
                    gfx.DrawEllipse(XBrushes.Black, x1, y1, width, height);
                }

                //Loop used to draw rectangles
                foreach (Polyline p in polyList)
                {
                    XPen pen = new XPen(XColors.Black, 0.5);
                    x1     = p.BoundingBox.Min.X - minX;
                    y1     = maxY - p.BoundingBox.Max.Y;
                    width  = p.BoundingBox.Max.X - p.BoundingBox.Min.X;
                    height = p.BoundingBox.Max.Y - p.BoundingBox.Min.Y;
                    XPoint   p1     = new XPoint(x1, y1);
                    XPoint   p2     = new XPoint(x1 + width, y1);
                    XPoint   p3     = new XPoint(x1, y1 + height);
                    XPoint   p4     = new XPoint(x1 + width, y1 + height);
                    XRect    rect   = new XRect(x1, y1, width, height);
                    XPoint[] xPoint = new XPoint[] { p1, p2, p4, p3 };
                    //XPoint mid = new XPoint( (x1 + x1)/2);
                    XGraphicsState gs = gfx.Save();
                    gfx.RotateAtTransform(-45, p1);
                    gfx.DrawPolygon(pen, XBrushes.Black, xPoint, XFillMode.Alternate);
                    gfx.Restore(gs);
                }



                #region Print the PDF as per the option selected
                if (getSelectedOption.Equals('N'))
                {
                    logFile("Normal PDF feature was selected");
                    document.Save(filename);
                    logFile("Document saved successfully - " + Rhino.ApplicationSettings.FileSettings.WorkingFolder);
                }
                if (getSelectedOption.Equals('C'))
                {
                    logFile("Compressed PDF feature was selected");
                    CompressMyPdf(document);
                    string compressedFileName = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "C-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(compressedFileName);
                }
                if (getSelectedOption.Equals('E'))
                {
                    logFile("Encrypted PDF feature was selected");
                    EncryptMyPdf(document);
                    string encryptPdf = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "E-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(encryptPdf);
                }
                if (getSelectedOption.Equals('P'))
                {
                    logFile("Password Protection PDF feature was selected");
                    PasswordProtectMyPdf(document);
                    string passwordProtectPdf = Rhino.ApplicationSettings.FileSettings.WorkingFolder + '\\' + "PP-" + rhinoFileName + "-" + myUniqueFileName;
                    document.Save(passwordProtectPdf);
                }

                #endregion

                logFile("Document saved successfully - " + Rhino.ApplicationSettings.FileSettings.WorkingFolder);

                logFile("Panel perforated successfully. Check File --> " + rhinoFileName + "-" + myUniqueFileName);
                System.Windows.Forms.MessageBox.Show("         <----SUCCESS---->       " + Environment.NewLine + Environment.NewLine + " Pannels perforated Successfully. ");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("                           ERROR!     " + Environment.NewLine + Environment.NewLine + "The curve you have selected contains some invalid shape." + Environment.NewLine + " Please select the appropriate patterns. ");
                logFile("Please select the appropriate pattern");
            }

            logFile("----------------- WAITING FOR THE NEXT PANEL PERFORATION ---------------------");

            return(Result.Success);
        }
예제 #28
0
 /// <summary>
 /// rotate the following output by some degrees, at the given position
 /// </summary>
 public override void RotateAtTransform(double ADegrees, double XPos, double YPos)
 {
     FXGraphics.RotateAtTransform(ADegrees, new XPoint(XPos, YPos));
 }
예제 #29
0
 /// <summary>
 /// Rotate the context.
 /// </summary>
 /// <param name="angle">The angle to rotate by, in degrees.</param>
 /// <param name="x">The X-coordinate of the centre of rotation.</param>
 /// <param name="y">The Y-coordinate of the centre of rotation.</param>
 public void RotateAt(double angle, double x, double y)
 {
     _core.RotateAtTransform(angle, new XPoint(x, y));
 }