コード例 #1
0
ファイル: LinesCircleArc.cs プロジェクト: jgshumate1/Migradoc
        public void Arc(XGraphics gfx, RectangleF rect, float startAngle, float sweepAngle)
        {
            RectangleF rect2 = RectangleF.Inflate(rect, rect.Width, 0);

            Box2(gfx, rect2, startAngle, sweepAngle);
            Box1(gfx, rect, startAngle, sweepAngle);
            //Box(gfx, rect, startAngle, sweepAngle);
            gfx.DrawArc(properties.Pen2.Pen, rect, startAngle, sweepAngle);
            gfx.DrawArc(properties.Pen3.Pen, rect2, 0, 90);
            gfx.DrawArc(properties.Pen2.Pen, rect2, startAngle, sweepAngle);

            float delta = (float)(Math.PI / 360);
            float rx    = rect2.Width / 2;
            float ry    = rect2.Height / 2;
            float dx    = rect2.X + rx;
            float dy    = rect2.Y + ry;

            for (float rad = 0; rad < Math.PI * 2; rad += delta)
            {
                gfx.DrawLine(XPens.LawnGreen, (float)(dx + rx * Math.Cos(rad)), (float)(dy + ry * Math.Sin(rad)),
                             (float)(dx + rx * Math.Cos(rad + delta)), (float)(dy + ry * Math.Sin(rad + delta)));
            }

            double gamma1 = (ry * Math.Cos(20 * 0.017453292519943295)) / (rx * Math.Sin(20 * 0.017453292519943295));

            gamma1 = Math.Atan(gamma1);
            gamma1 = 90 - gamma1 / 0.017453292519943295;
            double gamma2 = (ry * Math.Cos(70 * 0.017453292519943295)) / (rx * Math.Sin(70 * 0.017453292519943295));

            gamma2 = Math.Atan(gamma2);
            gamma2 = 90 - gamma2 / 0.017453292519943295 - gamma1;
            gfx.DrawArc(XPens.Black, rect2, (float)gamma1, (float)gamma2);
        }
コード例 #2
0
        /// <summary>
        /// Tutorial Link http://www.pdfsharp.net/wiki/HelloWorld-sample.ashx
        /// </summary>
        public static void HelloWorld()
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

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

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

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

            // Create a font
            XFont font = new XFont("Verdana", 48, XFontStyle.BoldItalic);

            // Draw the text
            gfx.DrawString("Hello, World!", font, XBrushes.Plum, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);

            //Draw Square
            gfx.DrawLines(XPens.DarkRed, new XPoint[] { new XPoint(200, 500), new XPoint(300, 500), new XPoint(300, 600), new XPoint(200, 600), new XPoint(200, 500) });
            gfx.DrawLines(XPens.DarkRed, new XPoint[] { new XPoint(250, 479.5), new XPoint(320.5, 550), new XPoint(250, 620.5), new XPoint(179.5, 550), new XPoint(250, 479.5) });
            gfx.DrawArc(XPens.DarkRed, new XRect(180, 480, 140, 140), 90, 0);
            //gfx.DrawArc(XPens.DarkCyan, new XRect(180, 485, 145, 145), 90, 0);

            // Save the document...
            const string filename = @"..\..\..\HelloWorld.pdf";

            document.Save(filename);

            // ...and start a viewer.
            Process.Start(filename);
        }
コード例 #3
0
        public void Arc(XGraphics gfx, XRect rect, double startAngle, double sweepAngle)
        {
            Box(gfx, rect, startAngle, sweepAngle);

            gfx.DrawArc(properties.Pen3.Pen, rect, startAngle, sweepAngle);

            DrawHandMadeArc(gfx, XPens.Red, rect, startAngle, sweepAngle);
        }
コード例 #4
0
        /// <summary>
        /// Draws Arcs.
        /// </summary>
        void RenderArcs(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XPen pen = new XPen(XColors.Plum, 4.7);

            gfx.DrawArc(pen, 0, 0, 250, 140, 190, 200);
        }
コード例 #5
0
        private void DrawArc(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "DrawArc");
            XPen pen = new XPen(XColors.Plum, 4.7);

            gfx.DrawArc(pen, 0, 0, 250, 140, 190, 200);
            base.EndBox(gfx);
        }
コード例 #6
0
        /// <summary>
        /// Draws an arc.
        /// </summary>
        void DrawArc(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawArc");

            var pen = new XPen(XColors.Plum, 4.7);

            gfx.DrawArc(pen, 0, 0, 250, 140, 190, 200);

            EndBox(gfx);
        }
コード例 #7
0
        /// <summary>
        /// Renders the content of the page.
        /// </summary>
        public void Render(XGraphics gfx)
        {
            XRect  rect;
            XPen   pen;
            double x = 50, y = 100;
            XFont  fontH1     = new XFont("Times", 18, XFontStyle.Bold);
            XFont  font       = new XFont("Times", 12);
            XFont  fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
            double ls         = font.GetHeight(gfx);

            // Draw some text
            gfx.DrawString("Create PDF on the fly with PDFsharp",
                           fontH1, XBrushes.Black, x, x);
            gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " +
                           "text and images on different targets.", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("The object used for drawing is the XGraphics object.",
                           font, XBrushes.Black, x, y);
            y += 2 * ls;

            // Draw an arc
            pen           = new XPen(XColors.Red, 4);
            pen.DashStyle = XDashStyle.Dash;
            gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120);

            // Draw a star
            XGraphicsState gs = gfx.Save();

            gfx.TranslateTransform(x + 140, y + 30);
            for (int idx = 0; idx < 360; idx += 10)
            {
                gfx.RotateTransform(10);
                gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0);
            }
            gfx.Restore(gs);

            // Draw a rounded rectangle
            rect = new XRect(x + 230, y, 100, 60);
            pen  = new XPen(XColors.DarkBlue, 2.5);
            XColor color1 = XColor.FromKnownColor(KnownColor.DarkBlue);
            XColor color2 = XColors.Red;
            XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2,
                                                                   XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10));

            // Draw a pie
            pen           = new XPen(XColors.DarkOrange, 1.5);
            pen.DashStyle = XDashStyle.Dot;
            gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135);

            // Draw some more text
            y += 60 + 2 * ls;
            gfx.DrawString("With XGraphics you can draw on a PDF page as well as " +
                           "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y);
            y += ls * 1.1;
            gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y);
            x += 10;
            y += ls * 1.1;
            gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw above or beneath of the content of an existing PDF page",
                           font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y);
            x -= 10;
            y += ls * 1.1;
            gfx.DrawString("You can also import an existing PDF page and use it like " +
                           "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y);
            y += ls * 1.1 * 2;
            gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " +
                           "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            gfx.DrawString("Below this text is a PDF form that will be visible when " +
                           "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            XGraphicsState state   = gfx.Save();
            XRect          rcImage = new XRect(100, y, 100, 100 * Math.Sqrt(2));

            gfx.DrawRectangle(XBrushes.Snow, rcImage);
            gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage);
            gfx.Restore(state);
        }
コード例 #8
0
ファイル: UnitTest1.cs プロジェクト: tofilagman/PDFSharp
        public void Shapes()
        {
            string filename = "Shapes.pdf";

            PdfDocument document = new PdfDocument();
            //document.Options.ColorMode = PdfColorMode.Cmyk;

            // Set version to PDF 1.4 (Acrobat 5) because we use transparency.
            //if (document.Version < 14)
            //    document.Version = 14;

            //PdfPage page = document.Pages[0];

            //// Get an XGraphics object for drawing beneath the existing content

            //XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

            LayoutHelper helper = new LayoutHelper(document, XUnit.FromCentimeter(2.5), XUnit.FromCentimeter(29.7 - 2.5));
            XUnit        left   = XUnit.FromCentimeter(2.5);

            helper.CreatePage();

            XGraphics gfx = helper.Gfx;

            XRect  rect;
            XPen   pen;
            double x = 50, y = 100;
            XFont  fontH1     = new XFont("Times", 18, XFontStyle.Bold);
            XFont  font       = new XFont("Times", 12);
            XFont  fontItalic = new XFont("Times", 12, XFontStyle.BoldItalic);
            double ls         = font.GetHeight(); //gfx

            // Draw some text
            gfx.DrawString("Create PDF on the fly with PDFsharp",
                           fontH1, XBrushes.Black, x, x);
            gfx.DrawString("With PDFsharp you can use the same code to draw graphic, " +
                           "text and images on different targets.", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("The object used for drawing is the XGraphics object.",
                           font, XBrushes.Black, x, y);
            y += 2 * ls;

            // Draw an arc
            pen           = new XPen(XColors.Red, 4);
            pen.DashStyle = XDashStyle.Dash;
            gfx.DrawArc(pen, x + 20, y, 100, 60, 150, 120);

            // Draw a star
            XGraphicsState gs = gfx.Save();

            gfx.TranslateTransform(x + 140, y + 30);
            for (int idx = 0; idx < 360; idx += 10)
            {
                gfx.RotateTransform(10);
                gfx.DrawLine(XPens.DarkGreen, 0, 0, 30, 0);
            }
            gfx.Restore(gs);

            // Draw a rounded rectangle
            rect = new XRect(x + 230, y, 100, 60);
            pen  = new XPen(XColors.DarkBlue, 2.5);
            XColor color1 = XColor.FromKnownColor(KnownColor.DarkBlue);
            XColor color2 = XColors.Red;
            XLinearGradientBrush lbrush = new XLinearGradientBrush(rect, color1, color2,
                                                                   XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(pen, lbrush, rect, new XSize(10, 10));

            // Draw a pie
            pen           = new XPen(XColors.DarkOrange, 1.5);
            pen.DashStyle = XDashStyle.Dot;
            gfx.DrawPie(pen, XBrushes.Blue, x + 360, y, 100, 60, -130, 135);

            // Draw some more text
            y += 60 + 2 * ls;
            gfx.DrawString("With XGraphics you can draw on a PDF page as well as " +
                           "on any System.Drawing.Graphics object.", font, XBrushes.Black, x, y);
            y += ls * 1.1;
            gfx.DrawString("Use the same code to", font, XBrushes.Black, x, y);
            x += 10;
            y += ls * 1.1;
            gfx.DrawString("• draw on a newly created PDF page", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw above or beneath of the content of an existing PDF page",
                           font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a window", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw on a printer", font, XBrushes.Black, x, y);
            y += ls;
            gfx.DrawString("• draw in a bitmap image", font, XBrushes.Black, x, y);
            x -= 10;
            y += ls * 1.1;
            gfx.DrawString("You can also import an existing PDF page and use it like " +
                           "an image, e.g. draw it on another PDF page.", font, XBrushes.Black, x, y);
            y += ls * 1.1 * 2;
            gfx.DrawString("Imported PDF pages are neither drawn nor printed; create a " +
                           "PDF file to see or print them!", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            gfx.DrawString("Below this text is a PDF form that will be visible when " +
                           "viewed or printed with a PDF viewer.", fontItalic, XBrushes.Firebrick, x, y);
            y += ls * 1.1;
            XGraphicsState state   = gfx.Save();
            XRect          rcImage = new XRect(100, y, 100, 100 * Math.Sqrt(2));

            gfx.DrawRectangle(XBrushes.Snow, rcImage);
            //gfx.DrawImage(XPdfForm.FromFile("../../../../../PDFs/SomeLayout.pdf"), rcImage);
            gfx.Restore(state);

            document.Save(filename);

            LaunchPdf(filename);
        }