Exemplo n.º 1
0
        /// <summary>
        /// Demonstrates the use of XGraphics.DrawBeziers.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            int n     = 2;
            int count = 1 + 3 * n;

            XPoint[] points = new XPoint[count];
            Random   rnd    = new Random(42);

            for (int idx = 0; idx < count; idx++)
            {
                points[idx].X = 20 + rnd.Next(600);
                points[idx].Y = 50 + rnd.Next(800);
            }

            // Draw the points
            XPen pen = new XPen(XColors.Red, 0.5);

            pen.DashStyle = XDashStyle.Dash;
            for (int idx = 0; idx + 3 < count; idx += 3)
            {
                gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx]));
                gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 1]));
                gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 2]));
                gfx.DrawEllipse(XBrushes.Red, MakeRect(points[idx + 3]));
                gfx.DrawLine(pen, points[idx], points[idx + 1]);
                gfx.DrawLine(pen, points[idx + 2], points[idx + 3]);
            }

            // Draw the curve
            gfx.DrawBeziers(properties.Pen2.Pen, points);
        }
Exemplo n.º 2
0
        private static void PrepareFooter(XGraphics formGfx)
        {
            DrawRectangle(formGfx, 0.5, 200, 15, 20, 609);
            DrawText("Notes", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 25, 612);
            DrawRectangle(formGfx, 0.5, 200, 80, 20, 624);
            //DrawText("Notes", formGfx, New XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 25, 637)
            DrawText("Thank you for your business!!", formGfx, new XFont(PdfFont, 12, XFontStyle.Bold), XBrushes.SteelBlue, 350, 750);
            //DrawLine(formGfx, 20, 590, 756, "Black", 0.5)
            //DrawLine(formGfx, 20, 590, 757, "SteelBlue", 0.5)
            //DrawLine(formGfx, 20, 590, 758, "Maroon", 0.5)
            XPen pen1 = new XPen(XColors.Black);
            XPen pen2 = new XPen(XColors.SteelBlue);
            XPen pen3 = new XPen(XColors.Maroon);

            formGfx.DrawBeziers(pen1, XPoint.ParsePoints("20,715 134,810 476,635 590,775"));
            formGfx.DrawBeziers(pen2, XPoint.ParsePoints("20,730 134,815 476,640 590,775"));
            formGfx.DrawBeziers(pen3, XPoint.ParsePoints("20,745 134,820 476,645 590,775"));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draws Bézier curves.
        /// </summary>
        void RenderBéziers(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XPoint[] points = { new XPoint(20,  30), new XPoint(40,  120), new XPoint(80,  20), new XPoint(110, 90),
                                new XPoint(180, 40), new XPoint(210,  40), new XPoint(220, 80) };
            XPen     pen = new XPen(XColors.Firebrick, 4);

            //pen.DashStyle = XDashStyle.Dot;
            gfx.DrawBeziers(pen, points);
        }
Exemplo n.º 4
0
        static void DrawBeziers(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawBeziers");

            XPoint[] points = new XPoint[] { new XPoint(20, 30), new XPoint(40, 120), new XPoint(80, 20), new XPoint(110, 90),
                                             new XPoint(180, 40), new XPoint(210, 40), new XPoint(220, 80) };
            XPen pen = new XPen(XColors.Firebrick, 4);

            gfx.DrawBeziers(pen, points);

            EndBox(gfx);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws two Bézier curves.
        /// </summary>
        void DrawBeziers(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawBeziers");

            var points = new[] { new XPoint(20, 30), new XPoint(40, 120), new XPoint(80, 20), new XPoint(110, 90),
                                 new XPoint(180, 40), new XPoint(210, 40), new XPoint(220, 80) };
            var pen = new XPen(XColors.Firebrick, 4);

            //pen.DashStyle = XDashStyle.Dot;
            gfx.DrawBeziers(pen, points);

            EndBox(gfx);
        }
Exemplo n.º 6
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
        }
        private void DrawBeziers(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "DrawBeziers");
            XPoint[] points = new XPoint[]
            {
                new XPoint(20.0, 30.0),
                new XPoint(40.0, 120.0),
                new XPoint(80.0, 20.0),
                new XPoint(110.0, 90.0),
                new XPoint(180.0, 40.0),
                new XPoint(210.0, 40.0),
                new XPoint(220.0, 80.0)
            };
            XPen pen = new XPen(XColors.Firebrick, 4.0);

            gfx.DrawBeziers(pen, points);
            base.EndBox(gfx);
        }
Exemplo n.º 8
0
        private static void DrawSignature(XGraphics gfx, int StartLeft, int StartTop, string Color, double Thickness)
        {
            XPen Main = new XPen(XColor.FromName(Color));

            Main.Width = Thickness;

            string LinePoints = null;
            int    val1       = 0;
            int    val2       = 0;
            int    val3       = 0;
            int    val4       = 0;
            int    val5       = 0;
            int    val6       = 0;
            int    val7       = 0;
            int    val8       = 0;

            //----- Top Line
            val1       = StartLeft;
            val2       = StartTop;
            val3       = val1 + 10;
            val4       = val2 + 10;
            val5       = val1 + 40;
            val6       = val2 - 10;
            val7       = val1 + 50;
            val8       = val2;
            LinePoints = "" + val1.ToString() + "," + val2.ToString() + " " + val3.ToString() + "," + val4.ToString() + " " + val5.ToString() + "," + val6.ToString() + " " + val7.ToString() + "," + val8.ToString() + "";
            gfx.DrawBeziers(Main, XPoint.ParsePoints(LinePoints));
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("300,100 310,110 340,90 350,100"))

            //----- Top Center Line
            val1       = val1 + 12;
            val2       = val2 + 8;
            val3       = val1 + 10;
            val4       = val2 + 10;
            val5       = val1 + 20;
            val6       = val2 - 9;
            val7       = val1 + 30;
            val8       = val2 + 2;
            LinePoints = "" + val1.ToString() + "," + val2.ToString() + " " + val3.ToString() + "," + val4.ToString() + " " + val5.ToString() + "," + val6.ToString() + " " + val7.ToString() + "," + val8.ToString() + "";
            gfx.DrawBeziers(Main, XPoint.ParsePoints(LinePoints));
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("312,108 322,118 332,99 342,110"))

            //----- Bottom Center Line
            val1       = val1 + 2;
            val2       = val2 + 10;
            val3       = val1 + 10;
            val4       = val2 + 10;
            val5       = val1 + 20;
            val6       = val2 - 9;
            val7       = val1 + 30;
            val8       = val2 + 2;
            LinePoints = "" + val1.ToString() + "," + val2.ToString() + " " + val3.ToString() + "," + val4.ToString() + " " + val5.ToString() + "," + val6.ToString() + " " + val7.ToString() + "," + val8.ToString() + "";
            gfx.DrawBeziers(Main, XPoint.ParsePoints(LinePoints));
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center

            //----- Bottom Line
            val1 = val1 - 4;
            //310
            val2 = val2 + 12;
            //130
            val3 = val1 + 10;
            //320
            val4 = val2 + 10;
            //140
            val5 = val1 + 15;
            //325
            val6 = val2 - 10;
            //120
            val7 = val1 + 25;
            //335
            val8 = val2;
            //130
            LinePoints = "" + val1.ToString() + "," + val2.ToString() + " " + val3.ToString() + "," + val4.ToString() + " " + val5.ToString() + "," + val6.ToString() + " " + val7.ToString() + "," + val8.ToString() + "";
            gfx.DrawBeziers(Main, XPoint.ParsePoints(LinePoints));
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom

            //----- Center Line
            val1 = val1 + 15;
            //325
            val2 = val2 - 30;
            //100
            val3 = val1 + 10;
            //335
            val4 = val2 + 10;
            //110
            val5 = val1;
            //325
            val6 = val2 + 20;
            //120
            val7 = val1 + 10;
            //335
            val8 = val2 + 30;
            //110
            LinePoints = "" + val1.ToString() + "," + val2.ToString() + " " + val3.ToString() + "," + val4.ToString() + " " + val5.ToString() + "," + val6.ToString() + " " + val7.ToString() + "," + val8.ToString() + "";
            gfx.DrawBeziers(Main, XPoint.ParsePoints(LinePoints));
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center

            //gfx.DrawBeziers(Main, XPoint.ParsePoints("300,100 310,110 340,90 350,100"))  'Top
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("310,130 320,140 325,120 335,130")) 'Bottom
            //gfx.DrawBeziers(Main, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center
        }
Exemplo n.º 9
0
        private static void PrepareInvoiceTop(XGraphics formGfx, XGraphicsState state, string InvoiceNumber)
        {
            string Headline            = "Service Invoice " + InvoiceNumber + "";
            string MyName              = TimeConnector.Data.Variables.SelectedContractor["CmpName"];
            string Phone               = TimeConnector.Data.Variables.SelectedContractorContact["ConPhone"];
            string MyPhone             = "Phone (" + Phone.Substring(0, 3) + ") " + Phone.Substring(4, 3) + "-" + Phone.Substring(7, 4) + "";
            string MyEmail             = "Email: " + TimeConnector.Data.Variables.SelectedContractorContact["ConEmail"] + "";
            string MyAddress           = TimeConnector.Data.Variables.SelectedContractor["CmpAddress"];
            string MyCityStateZip      = "" + TimeConnector.Data.Variables.SelectedContractor["CmpCity"] + ", " + TimeConnector.Data.Variables.SelectedContractor["CmpState"] + "  " + TimeConnector.Data.Variables.SelectedContractor["CmpZip"] + "";
            string WeekEnding          = TimeConnector.Data.Variables.SelectedPaydate["WeekEnd"];
            string PayDate             = TimeConnector.Data.Variables.SelectedPaydate["PayDate"];
            string CompanyName         = TimeConnector.Data.Variables.SelectedCompany["CmpName"];
            string CompanyContact      = "c/o " + TimeConnector.Data.Variables.SelectedContact["ConName"] + "";
            string CompanyContactPhone = "" + TimeConnector.Data.Variables.SelectedContact["ConPhone"] + "";
            string CompanyContactEmail = "" + TimeConnector.Data.Variables.SelectedContact["ConEmail"] + "";
            string CompanyAddress      = TimeConnector.Data.Variables.SelectedCompany["CmpAddress"];
            string CompanyCityStateZip = "" + TimeConnector.Data.Variables.SelectedCompany["CmpCity"] + ", " + TimeConnector.Data.Variables.SelectedCompany["CmpState"] + "  " + TimeConnector.Data.Variables.SelectedCompany["CmpZip"] + "";

            //----- Invoice Header
            XFont         HeaderFont = new XFont("Imprint MT Shadow", 30, XFontStyle.Bold);
            string        HeaderText = "I N V O I C E";
            XStringFormat format     = new XStringFormat();

            format.Alignment     = XStringAlignment.Near;
            format.LineAlignment = XLineAlignment.Near;
            XColor color = default(XColor);

            color   = XColor.FromName("SteelBlue");
            color.A = 0.5;
            XBrush brush = default(XBrush);

            brush = new XSolidBrush(color);
            XPoint point = new XPoint(410, 20);

            formGfx.DrawString(HeaderText, HeaderFont, brush, point, format);

            //..... My Company Icon
            state = formGfx.Save();
            formGfx.DrawImage(XImage.FromFile("Images\\logo.png"), 20, 20, 65, 65);
            formGfx.Restore(state);

            //..... My Company Information
            DrawText(MyName, formGfx, new XFont(PdfFontMyInfo, 15, XFontStyle.Bold), XBrushes.SteelBlue, 95, 20);
            DrawText(MyAddress, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 45);
            DrawText(MyCityStateZip, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 55);
            DrawText(MyPhone, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 65);
            DrawText(MyEmail, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 75);

            XPen pen1 = new XPen(XColors.Maroon);

            pen1.Width = 1;
            //Dim pen2 As New XPen(XColors.Maroon)
            XPen pen2 = new XPen(XColors.SteelBlue);

            pen2.Width = 2;
            //Dim pen3 As New XPen(XColors.SteelBlue)
            XPen pen3 = new XPen(XColors.Maroon);

            pen3.Width = 1;
            formGfx.DrawBeziers(pen1, XPoint.ParsePoints("20,95 80,140 190,70 250,110"));

            DrawSignature(formGfx, 531, 696, "LightGray", 1);
            DrawSignature(formGfx, 530, 695, "Black", 1.5);
            DrawSignature(formGfx, 530, 695, "SteelBlue", 1);

            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("300,100 310,110 340,90 350,100"))  'Top
            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center
            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center
            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom
            //formGfx.DrawBeziers(pen2, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center

            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("300,100 310,110 340,90 350,100"))  'Top
            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("312,108 322,118 332,99 342,110")) 'Top Center
            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("314,118 324,128 334,109 344,120")) 'Bottom Center
            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("310,130 315,140 330,120 335,130")) 'Bottom
            //formGfx.DrawBeziers(pen3, XPoint.ParsePoints("325,100 335,110 325,120 335,130")) 'Center

            //..... ACS Company Icon
            DrawText("B I L L   T O :", formGfx, new XFont(PdfFont, 9, XFontStyle.Bold), XBrushes.Black, 60, 95);
            state = formGfx.Save();
            formGfx.DrawImage(XImage.FromFile("Images\\ACSIcon.jpg"), 20, 115, 65, 65);
            formGfx.Restore(state);

            //..... ACS Company Information
            DrawText(CompanyName, formGfx, new XFont(PdfFontMyInfo, 15, XFontStyle.Bold), XBrushes.Green, 95, 115);
            DrawText(CompanyContact, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 135);
            DrawText(CompanyAddress, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 145);
            DrawText(CompanyCityStateZip, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 155);
            DrawText(CompanyContactPhone, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 165);
            DrawText(CompanyContactEmail, formGfx, new XFont(PdfFontMyInfo, 7, XFontStyle.Regular), XBrushes.Black, 95, 175);

            //..... Invoice Information
            DrawLine(formGfx, 450, 590, 80, "SteelBlue", 0.5);
            DrawText("Invoice #:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 71);
            DrawText(InvoiceNumber, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Maroon, 530, 71);
            DrawLine(formGfx, 450, 590, 90, "SteelBlue", 0.5);
            DrawText("Week Ending:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 81);
            DrawText(WeekEnding, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 81);
            DrawLine(formGfx, 450, 590, 100, "SteelBlue", 0.5);
            DrawText("Pay Date:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 91);
            DrawText(PayDate, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 91);
            DrawLine(formGfx, 450, 590, 110, "SteelBlue", 0.5);
            DrawText("Hours Worked:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 101);
            DrawText(TimeConnector.Data.Invoice.FinHour, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 101);
            DrawLine(formGfx, 450, 590, 120, "SteelBlue", 0.5);
            DrawText("Balance Due:", formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 452, 111);
            DrawText(TimeConnector.Data.Invoice.FinCost, formGfx, new XFont(PdfFont, 7, XFontStyle.Bold), XBrushes.Black, 530, 111);
        }
Exemplo n.º 10
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);
        }