Esempio n. 1
0
        public XBrush Gradient(Rect rect, Color color1, Color color2)
        {
            var brush = new XLinearGradientBrush(rect.ToRectangleF(), color1, color2, XLinearGradientMode.ForwardDiagonal);

            //m_items.Add(brush);
            return(brush);
        }
Esempio n. 2
0
        public void BeginBox(XGraphics gfx, int number, string title)
        {
            XRect xRect = new XRect(0.0, 20.0, 300.0, 200.0);
            bool  flag  = number % 2 == 0;

            if (flag)
            {
                xRect.X = 295.0;
            }
            xRect.Y = (double)(40 + (number - 1) / 2 * 195);
            xRect.Inflate(-10.0, -10.0);
            XRect rect = xRect;

            rect.Offset(this.borderWidth, this.borderWidth);
            gfx.DrawRoundedRectangle(new XSolidBrush(this.shadowColor), rect, new XSize(23.0, 23.0));
            XLinearGradientBrush brush = new XLinearGradientBrush(xRect, this.backColor, this.backColor2, XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(this.borderPen, brush, xRect, new XSize(15.0, 15.0));
            xRect.Inflate(-5.0, -5.0);
            XFont font = new XFont("Verdana", 12.0, XFontStyle.Regular);

            gfx.DrawString(title, font, XBrushes.Navy, xRect, XStringFormats.TopCenter);
            xRect.Inflate(-10.0, -5.0);
            xRect.Y      += 20.0;
            xRect.Height -= 20.0;
            this.state    = gfx.Save();
            gfx.TranslateTransform(xRect.X, xRect.Y);
        }
Esempio n. 3
0
        private void BeginBox(XGraphics gfx, int number, string title)
        {
            const int dEllipse = 15;
            XRect     rect     = new XRect(0, 20, 300, 200);

            if (number % 2 == 0)
            {
                rect.X = 300 - 5;
            }
            rect.Y = 40 + ((number - 1) / 2) * (200 - 5);
            rect.Inflate(-10, -10);
            XRect rect2 = rect;

            rect2.Offset(2, 2);
            XColor xColor1 = XColors.DarkGoldenrod;
            XColor xColor2 = XColors.Chocolate;

            gfx.DrawRoundedRectangle(new XSolidBrush(XColor.FromArgb(9, XColors.DarkGoldenrod)), rect2, new XSize(dEllipse + 8, dEllipse + 8));
            XLinearGradientBrush brush = new XLinearGradientBrush(rect, xColor1, xColor2, XLinearGradientMode.Vertical);

            gfx.DrawRoundedRectangle(brush, rect, new XSize(dEllipse, dEllipse));
            rect.Inflate(-5, -5);
            XFont font = new XFont("Verdana", 14, XFontStyle.Bold);

            gfx.DrawString(title, font, XBrushes.Black, rect, XStringFormats.TopCenter);
            rect.Inflate(-10, -5);
            rect.Y      += 20;
            rect.Height -= 20;
            gfx.Save();
            gfx.TranslateTransform(rect.X, rect.Y);
        }
Esempio n. 4
0
    public void BeginBox(XGraphics gfx, int number, string title)
    {
        const int dEllipse = 15;
        XRect     rect     = new XRect(0, 20, 300, 200);

        if (number % 2 == 0)
        {
            rect.X = 300 - 5;
        }
        rect.Y = 40 + ((number - 1) / 2) * (200 - 5);
        rect.Inflate(-10, -10);
        XRect rect2 = rect;

        rect2.Offset(this.BorderWidth, this.BorderWidth);
        gfx.DrawRoundedRectangle(new XSolidBrush(this.ShadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8));
        XLinearGradientBrush brush = new XLinearGradientBrush(rect, this.BackColor, this.BackColor2, XLinearGradientMode.Vertical);

        gfx.DrawRoundedRectangle(this.BorderPen, brush, rect, new XSize(dEllipse, dEllipse));
        rect.Inflate(-5, -5);

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

        gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter);

        rect.Inflate(-10, -5);
        rect.Y      += 20;
        rect.Height -= 20;

        this.state = gfx.Save();
        gfx.TranslateTransform(rect.X, rect.Y);
    }
Esempio n. 5
0
        public IBrush LinearGradientBrush(Rectangle rect, Color color1, Color color2, float angle)
        {
            var xbrush = new XLinearGradientBrush(rect, color1, color2, XLinearGradientMode.Horizontal);

            xbrush.RotateTransform(angle);

            return(new PdfBrush(xbrush));
        }
Esempio n. 6
0
        public void RealizeBrush(XBrush brush, PdfColorMode colorMode, int renderingMode, double fontEmSize)
        {
            // Rendering mode 2 is used for bold simulation.
            // Reference: TABLE 5.3  Text rendering modes / Page 402

            XSolidBrush solidBrush = brush as XSolidBrush;

            if (solidBrush != null)
            {
                XColor color     = solidBrush.Color;
                bool   overPrint = solidBrush.Overprint;

                if (renderingMode == 0)
                {
                    RealizeFillColor(color, overPrint, colorMode);
                }
                else if (renderingMode == 2)
                {
                    // Come here in case of bold simulation.
                    RealizeFillColor(color, false, colorMode);
                    //color = XColors.Green;
                    RealizePen(new XPen(color, fontEmSize * Const.BoldEmphasis), colorMode);
                }
                else
                {
                    throw new InvalidOperationException("Only rendering modes 0 and 2 are currently supported.");
                }
            }
            else
            {
                if (renderingMode != 0)
                {
                    throw new InvalidOperationException("Rendering modes other than 0 can only be used with solid color brushes.");
                }

                XLinearGradientBrush gradientBrush = brush as XLinearGradientBrush;
                if (gradientBrush != null)
                {
                    Debug.Assert(UnrealizedCtm.IsIdentity, "Must realize ctm first.");
                    XMatrix matrix = _renderer.DefaultViewMatrix;
                    matrix.Prepend(EffectiveCtm);
                    PdfShadingPattern pattern = new PdfShadingPattern(_renderer.Owner);
                    pattern.SetupFromBrush(gradientBrush, matrix, _renderer);
                    string name = _renderer.Resources.AddPattern(pattern);
                    _renderer.AppendFormatString("/Pattern cs\n", name);
                    _renderer.AppendFormatString("{0} scn\n", name);

                    // Invalidate fill color.
                    _realizedFillColor = XColor.Empty;
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Setups the shading pattern from the specified brush.
        /// </summary>
        internal void SetupFromBrush(XLinearGradientBrush brush, XMatrix matrix, XGraphicsPdfRenderer renderer)
        {
            if (brush == null)
            {
                throw new ArgumentNullException("brush");
            }

            PdfShading shading = new PdfShading(_document);

            shading.SetupFromBrush(brush, renderer);
            Elements[Keys.Shading] = shading;
            //Elements[Keys.Matrix] = new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]");
            Elements.SetMatrix(Keys.Matrix, matrix);
        }
Esempio n. 8
0
        /// <summary>
        /// Setups the shading pattern from the specified brush.
        /// </summary>
        public void SetupFromBrush(XLinearGradientBrush brush, XMatrix matrix)
        {
            if (brush == null)
            {
                throw new ArgumentNullException("brush");
            }

            PdfShading shading = new PdfShading(this.document);

            shading.SetupFromBrush(brush);
            Elements[Keys.Shading] = shading;
            //Elements[Keys.Matrix] = new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]");
            Elements.SetMatrix(Keys.Matrix, matrix);
        }
Esempio n. 9
0
        private XBrush GetXBrush(Brush b)
        {
            XBrush brush = null;
            LinearGradientBrush lgBrush;

            if ((lgBrush = b as LinearGradientBrush) != null)
            {
                if (lgBrush.LinearColors.Length == 2)
                {
                    brush = new XLinearGradientBrush(lgBrush.Rectangle,
                                                     lgBrush.LinearColors[0], lgBrush.LinearColors[1],
                                                     XLinearGradientMode.ForwardDiagonal);
                }
            }
            else if (b is SolidBrush && (b as SolidBrush).Color.A != 0)
            {
                brush = b;
            }
            return(brush);
        }
Esempio n. 10
0
        /// <summary>
        /// Converts a GDI-Brush to a PDF-XBrush.
        /// </summary>
        /// <remarks>
        /// Only Solid- and LinearGradientBrushes are supported.
        /// </remarks>
        /// <param name="brush">The GDI-Brush to convert.</param>
        /// <returns>The converted PDF-XBrush.</returns>
        private static XBrush BrushToXBrush(Brush brush)
        {
            XBrush              xbrush;
            SolidBrush          solidBrush;
            LinearGradientBrush lgBrush;

            if ((solidBrush = brush as SolidBrush) != null)
            {
                xbrush = new XSolidBrush(solidBrush.Color);
            }
            else if ((lgBrush = brush as LinearGradientBrush) != null)
            {
                //There is no way to extract the angle of the gradient out of the GDI-brush.
                //It only has a transformation matrix. To create a new gradient for pdfsharp,
                //we use this matrix as follows:
                //Create a "line" (start and end point) through the rectangle at the half of
                //the heigth. The two points are p1 and p2. Transform these points with the
                //matrix. The transformed points are located on the border of the rectangle.
                PointF   p1     = new PointF(lgBrush.Rectangle.Left, lgBrush.Rectangle.Top + lgBrush.Rectangle.Height / 2.0f);
                PointF   p2     = new PointF(lgBrush.Rectangle.Right, lgBrush.Rectangle.Top + lgBrush.Rectangle.Height / 2.0f);
                PointF[] points = new[] { p1, p2 };
                lgBrush.Transform.TransformPoints(points);
                p1 = points[0];
                p2 = points[1];

                //The direction is ok now. But the line might be to short. That is the case if
                //the line is neither horizontal, nor vertical, nor diagonal. To fill the whole
                //rectangle with the gradient, the start and end point of the line must be located
                //outside the rectangle. To determine this gap we have to use some trigonometry.
                //This will happily never the case in NClass. So we don't have to do this here.

                xbrush = new XLinearGradientBrush(p1, p2, lgBrush.LinearColors[0], lgBrush.LinearColors[1]);
            }
            else
            {
                throw new NotImplementedException("Brush type not supported by PDFsharp.");
            }
            return(xbrush);
        }
Esempio n. 11
0
        public void BeginHeader(XGraphics gfx, int number)
        {
            XRect rect = new XRect(50, 30, 104, 20);

            rect.X += 104 * (number % 7);


            XLinearGradientBrush brush = new XLinearGradientBrush(new XPoint(1, 1), new XPoint(3, 3), this.backColor, this.backColor2);

            XBrush b = XBrushes.Transparent;

            gfx.DrawRectangle(borderPen, b, rect);


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


            gfx.DrawString($"{ZP.days[number]}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);



            state = gfx.Save();
        }
Esempio n. 12
0
        /// <summary>
        /// Draws all charts inside the ChartFrame.
        /// </summary>
        public void Draw(XGraphics gfx)
        {
            // Draw frame of ChartFrame. First shadow frame.
            int dx = 5;
            int dy = 5;

            gfx.DrawRoundedRectangle(XBrushes.Gainsboro,
                                     this.location.X + dx, this.location.Y + dy,
                                     this.size.Width, this.size.Height, 20, 20);

            XRect chartRect            = new XRect(this.location.X, this.location.Y, this.size.Width, this.size.Height);
            XLinearGradientBrush brush = new XLinearGradientBrush(chartRect, XColor.FromArgb(0xFFD0DEEF), XColors.White,
                                                                  XLinearGradientMode.Vertical);
            XPen penBorder = new XPen(XColors.SteelBlue, 2.5);

            gfx.DrawRoundedRectangle(penBorder, brush,
                                     this.location.X, this.location.Y, this.size.Width, this.size.Height,
                                     15, 15);

            XGraphicsState state = gfx.Save();

            gfx.TranslateTransform(this.location.X, this.location.Y);

            // Calculate rectangle for all charts. Y-Position will be moved for each chart.
            int   charts          = this.chartList.Count;
            uint  dxChart         = 20;
            uint  dyChart         = 20;
            uint  dyBetweenCharts = 30;
            XRect rect            = new XRect(dxChart, dyChart,
                                              this.size.Width - 2 * dxChart,
                                              (this.size.Height - (charts - 1) * dyBetweenCharts - 2 * dyChart) / charts);

            // draw each chart in list
            foreach (Chart chart in this.chartList)
            {
                RendererParameters parms = new RendererParameters(gfx, rect);
                parms.DrawingItem = chart;

                ChartRenderer renderer = GetChartRenderer(chart, parms);
                renderer.Init();
                renderer.Format();
                renderer.Draw();

                rect.Y += rect.Height + dyBetweenCharts;
            }
            gfx.Restore(state);

//      // Calculate rectangle for all charts. Y-Position will be moved for each chart.
//      int charts = this.chartList.Count;
//      uint dxChart = 0;
//      uint dyChart = 0;
//      uint dyBetweenCharts = 0;
//      XRect rect = new XRect(dxChart, dyChart,
//        this.size.Width - 2 * dxChart,
//        (this.size.Height - (charts - 1) * dyBetweenCharts - 2 * dyChart) / charts);
//
//      // draw each chart in list
//      foreach (Chart chart in this.chartList)
//      {
//        RendererParameters parms = new RendererParameters(gfx, rect);
//        parms.DrawingItem = chart;
//
//        ChartRenderer renderer = GetChartRenderer(chart, parms);
//        renderer.Init();
//        renderer.Format();
//        renderer.Draw();
//
//        rect.Y += rect.Height + dyBetweenCharts;
//      }
        }
        /// <summary>
        /// Demonstrates the use of XLinearGradientBrush.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            XRect rect;
            XLinearGradientBrush brush;
            Graphics             grfx = gfx.Internals.Graphics;

            XLinearGradientBrush brush2 =
                new XLinearGradientBrush(
                    new XPoint(100, 100),
                    new XPoint(300, 300),
                    XColors.DarkRed, XColors.Yellow);

            //gfx.FillRectangle(brush, 0, 0, 600, 600);
            //gfx.TranslateTransform(35, 200);
            //gfx.RotateTransform(17);

            rect  = new XRect(20, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.DarkRed, XColors.Yellow, XLinearGradientMode.Horizontal);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(140, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.DarkRed, XColors.Yellow, XLinearGradientMode.Vertical);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(260, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.DarkRed, XColors.Yellow, XLinearGradientMode.ForwardDiagonal);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(380, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.DarkRed, XColors.Yellow, XLinearGradientMode.BackwardDiagonal);
            gfx.DrawRectangle(XPens.Red, brush, rect);


            gfx.TranslateTransform(80, 250);
            gfx.ScaleTransform(1.1);
            gfx.RotateTransform(20);

            rect  = new XRect(20, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.Orange, XColors.DarkBlue, XLinearGradientMode.Horizontal);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(140, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.Orange, XColors.DarkBlue, XLinearGradientMode.Vertical);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(260, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.Orange, XColors.DarkBlue, XLinearGradientMode.ForwardDiagonal);
            gfx.DrawRectangle(XPens.Red, brush, rect);

            rect  = new XRect(380, 50, 100, 200);
            brush = new XLinearGradientBrush(rect,
                                             XColors.Orange, XColors.DarkBlue, XLinearGradientMode.BackwardDiagonal);
            gfx.DrawRectangle(XPens.Red, brush, rect);
        }
Esempio n. 14
0
        static void Main()
        {
            const string watermark = "PDFsharp";
            const int    emSize    = 150;

            // Get a fresh copy of the sample PDF file
            const string filename = "Portable Document Format.pdf";

            File.Copy(Path.Combine("../../../../../PDFs/", filename),
                      Path.Combine(Directory.GetCurrentDirectory(), filename), true);

            // Create the font for drawing the watermark
            XFont font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic);

            // Open an existing document for editing and loop through its pages
            PdfDocument document = PdfReader.Open(filename);

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

            for (int idx = 0; idx < document.Pages.Count; idx++)
            {
                //if (idx == 1) break;
                PdfPage page = document.Pages[idx];

                switch (idx % 3)
                {
                case 0:
                {
                    // Variation 1: Draw watermark as text string

                    // Get an XGraphics object for drawing beneath the existing content
                    XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

#if true_
                    // Fill background with linear gradient color
                    XRect rect = page.MediaBox.ToXRect();
                    XLinearGradientBrush gbrush = new XLinearGradientBrush(rect,
                                                                           XColors.LightSalmon, XColors.WhiteSmoke, XLinearGradientMode.Vertical);
                    gfx.DrawRectangle(gbrush, rect);
#endif

                    // Get the size (in point) of the text
                    XSize size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a string format
                    XStringFormat format = new XStringFormat();
                    format.Alignment     = XStringAlignment.Near;
                    format.LineAlignment = XLineAlignment.Near;

                    // Create a dimmed red brush
                    XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));

                    // Draw the string
                    gfx.DrawString(watermark, font, brush,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   format);
                }
                break;

                case 1:
                {
                    // Variation 2: Draw watermark as outlined graphical path

                    // Get an XGraphics object for drawing beneath the existing content
                    XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

                    // Get the size (in point) of the text
                    XSize size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a graphical path
                    XGraphicsPath path = new XGraphicsPath();

                    // Add the text to the path
                    path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   XStringFormats.Default);

                    // Create a dimmed red pen
                    XPen pen = new XPen(XColor.FromArgb(128, 255, 0, 0), 2);

                    // Stroke the outline of the path
                    gfx.DrawPath(pen, path);
                }
                break;

                case 2:
                {
                    // Variation 3: Draw watermark as transparent graphical path above text

                    // Get an XGraphics object for drawing above the existing content
                    XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

                    // Get the size (in point) of the text
                    XSize size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a graphical path
                    XGraphicsPath path = new XGraphicsPath();

                    // Add the text to the path
                    path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   XStringFormats.Default);

                    // Create a dimmed red pen and brush
                    XPen   pen   = new XPen(XColor.FromArgb(50, 75, 0, 130), 3);
                    XBrush brush = new XSolidBrush(XColor.FromArgb(50, 106, 90, 205));

                    // Stroke the outline of the path
                    gfx.DrawPath(pen, brush, path);
                }
                break;
                }
            }
            // Save the document...
            document.Save(filename);
            // ...and start a viewer
            Process.Start(filename);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public void GeneratePdfReport(string path, double poolVolume, double filterDiameter)
        {
            var chartView = new ChartView("");

            chartView.AddCurve(Pump.ModellName, Pump.GetPerformanceFlowValues(), Pump.GetPerformanceHeadValues());
            chartView.PowerPoint = new Tuple <double, double>(SystemFlowRate, SystemHead);

            var pklImage   = chartView.GetChartImage();
            var filterArea = Math.PI * Math.Pow(filterDiameter, 2) / 400;


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

            document.Info.CreationDate = DateTime.Now;
            document.Info.Creator      = GetTitle();
            if (!CurrentPresets.DisableUserName)
            {
                document.Info.Author = CurrentPresets.UserName;
            }
            document.Info.Title    = "FlowCalc Report";
            document.Info.Keywords = "FlowCalc Pumpenkennlinie Volumenstrom Filtergeschwindigkeit";
            document.Info.Subject  = $"{Pump.ModellName} @ {SystemHead.ToString("f2")} mWS";

            document.PageLayout = PdfPageLayout.SinglePage;


            var pageA4 = new PdfPage();

            pageA4.Width       = new XUnit(210, XGraphicsUnit.Millimeter);
            pageA4.Height      = new XUnit(297, XGraphicsUnit.Millimeter);
            pageA4.Orientation = PdfSharp.PageOrientation.Portrait;

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


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

            var font = new XFont("Barlow", 11, XFontStyle.Regular);


            #region Frame

            var framePen = new XPen(XColors.Black, 0.7);

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

            //background
            var headerLeft      = new XRect(s, new XPoint(new XUnit(210 / 2, XGraphicsUnit.Millimeter), new XUnit(30, XGraphicsUnit.Millimeter)));
            var headerBrushLeft = new XLinearGradientBrush(
                new XPoint(new XUnit(5, XGraphicsUnit.Millimeter), new XUnit(5, XGraphicsUnit.Millimeter)),
                new XPoint(new XUnit(210 / 2, XGraphicsUnit.Millimeter), new XUnit(5, XGraphicsUnit.Millimeter)),
                XColor.FromArgb(0xff, 0x2e, 0x64),
                XColor.FromArgb(0xe1, 0x00, 0x72)
                );
            var headerRight = new XRect(
                new XPoint(new XUnit(210 / 2, XGraphicsUnit.Millimeter), new XUnit(5, XGraphicsUnit.Millimeter)),
                new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(30, XGraphicsUnit.Millimeter))
                );
            var headerBrushRight = new XLinearGradientBrush(
                new XPoint(new XUnit(210 / 2, XGraphicsUnit.Millimeter), new XUnit(5, XGraphicsUnit.Millimeter)),
                new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(5, XGraphicsUnit.Millimeter)),
                XColor.FromArgb(0xe1, 0x00, 0x72),
                XColor.FromArgb(0xfa, 0x00, 0x41)
                );
            gfx.DrawRectangle(headerBrushLeft, headerLeft);
            gfx.DrawRectangle(headerBrushRight, headerRight);


            var footer = new XRect(
                new XPoint(new XUnit(5, XGraphicsUnit.Millimeter), new XUnit(276, XGraphicsUnit.Millimeter)),
                new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(292, XGraphicsUnit.Millimeter))
                );
            var footerBrush = new XSolidBrush(XColor.FromArgb(0xf7, 0xf8, 0xf9));
            gfx.DrawRectangle(footerBrush, footer);

            var outerFrame = new XRect(s, new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(292, XGraphicsUnit.Millimeter)));
            gfx.DrawRectangle(framePen, outerFrame);


            gfx.DrawLine(framePen,
                         new XPoint(new XUnit(5, XGraphicsUnit.Millimeter), new XUnit(30, XGraphicsUnit.Millimeter)),
                         new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(30, XGraphicsUnit.Millimeter)));

            gfx.DrawString("FlowCalc Report", new XFont("Barlow", 32, XFontStyle.Bold), XBrushes.White,
                           new XRect(s, new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(30, XGraphicsUnit.Millimeter))),
                           XStringFormats.Center);

            int footerCol = 62;

            gfx.DrawLine(framePen,
                         new XPoint(new XUnit(5, XGraphicsUnit.Millimeter), new XUnit(276, XGraphicsUnit.Millimeter)),
                         new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(276, XGraphicsUnit.Millimeter)));
            gfx.DrawLine(framePen,
                         new XPoint(new XUnit(footerCol, XGraphicsUnit.Millimeter), new XUnit(276, XGraphicsUnit.Millimeter)),
                         new XPoint(new XUnit(footerCol, XGraphicsUnit.Millimeter), new XUnit(292, XGraphicsUnit.Millimeter)));
            gfx.DrawLine(framePen,
                         new XPoint(new XUnit(210 - footerCol, XGraphicsUnit.Millimeter), new XUnit(276, XGraphicsUnit.Millimeter)),
                         new XPoint(new XUnit(210 - footerCol, XGraphicsUnit.Millimeter), new XUnit(292, XGraphicsUnit.Millimeter)));

            var footerTextBrush = new XSolidBrush(XColor.FromArgb(0x18, 0x19, 0x37));

            var footerArea1 = new XRect(
                new XPoint(new XUnit(5, XGraphicsUnit.Millimeter), new XUnit(278, XGraphicsUnit.Millimeter)),
                new XPoint(new XUnit(footerCol, XGraphicsUnit.Millimeter), new XUnit(284, XGraphicsUnit.Millimeter)));

            page.AddWebLink(new PdfRectangle(footerArea1), @"http://www.100prznt.de/");

            gfx.DrawString("www.100prznt.de", font, footerTextBrush,
                           footerArea1,
                           XStringFormats.Center);
            gfx.DrawString("Elias Ruemmler", font, footerTextBrush,
                           new XRect(
                               new XPoint(new XUnit(5, XGraphicsUnit.Millimeter), new XUnit(284, XGraphicsUnit.Millimeter)),
                               new XPoint(new XUnit(footerCol, XGraphicsUnit.Millimeter), new XUnit(290, XGraphicsUnit.Millimeter))),
                           XStringFormats.Center);



            gfx.DrawString(GetTitle(), new XFont("Barlow", 16, XFontStyle.Bold), footerTextBrush,
                           new XRect(
                               new XPoint(new XUnit(footerCol, XGraphicsUnit.Millimeter), new XUnit(277, XGraphicsUnit.Millimeter)),
                               new XPoint(new XUnit(210 - footerCol, XGraphicsUnit.Millimeter), new XUnit(284, XGraphicsUnit.Millimeter))),
                           XStringFormats.Center);

            var footerArea4 = new XRect(
                new XPoint(new XUnit(footerCol, XGraphicsUnit.Millimeter), new XUnit(284, XGraphicsUnit.Millimeter)),
                new XPoint(new XUnit(210 - footerCol, XGraphicsUnit.Millimeter), new XUnit(291, XGraphicsUnit.Millimeter)));

            page.AddWebLink(new PdfRectangle(footerArea4), @"http://www.github.com/100prznt/Flowcalc");
            gfx.DrawString("www.github.com/100prznt/FlowCalc", font, footerTextBrush,
                           footerArea4,
                           XStringFormats.Center);

            if (CurrentPresets.DisableUserName)
            {
                gfx.DrawString(DateTime.Now.ToString(), font, footerTextBrush,
                               new XRect(
                                   new XPoint(new XUnit(210 - footerCol, XGraphicsUnit.Millimeter), new XUnit(276, XGraphicsUnit.Millimeter)),
                                   new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(292, XGraphicsUnit.Millimeter))),
                               XStringFormats.Center);
            }
            else
            {
                gfx.DrawString(DateTime.Now.ToString(), font, footerTextBrush,
                               new XRect(
                                   new XPoint(new XUnit(210 - footerCol, XGraphicsUnit.Millimeter), new XUnit(278, XGraphicsUnit.Millimeter)),
                                   new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(284, XGraphicsUnit.Millimeter))),
                               XStringFormats.Center);
                gfx.DrawString(CurrentPresets.UserName, font, footerTextBrush,
                               new XRect(
                                   new XPoint(new XUnit(210 - footerCol, XGraphicsUnit.Millimeter), new XUnit(284, XGraphicsUnit.Millimeter)),
                                   new XPoint(new XUnit(205, XGraphicsUnit.Millimeter), new XUnit(290, XGraphicsUnit.Millimeter))),
                               XStringFormats.Center);
            }
            #endregion Frame


            var p  = new XFont("Barlow", 10.5, XFontStyle.Regular);
            var h2 = new XFont("Barlow", 17, XFontStyle.Bold);
            var h3 = new XFont("Barlow", 13, XFontStyle.Bold);
            var p3 = new XFont("Barlow", 13, XFontStyle.Regular);

            var t1  = new XUnit(10, XGraphicsUnit.Millimeter);
            var t2  = new XUnit(13, XGraphicsUnit.Millimeter);
            var t3  = new XUnit(20, XGraphicsUnit.Millimeter);
            var t10 = new XUnit(72, XGraphicsUnit.Millimeter);
            var t16 = new XUnit(140, XGraphicsUnit.Millimeter);

            int yLineH3 = 7;
            int yOffsH3 = -1;
            int yBd     = 40;

            gfx.DrawString("System", h2, XBrushes.Black, new XPoint(t1, new XUnit(yBd + yOffsH3, XGraphicsUnit.Millimeter)));

            gfx.DrawString("Pumpe:", p3, XBrushes.Black, new XPoint(t2, new XUnit(yBd + yLineH3, XGraphicsUnit.Millimeter)));
            gfx.DrawString("Filterkessel Durchmesser:", p3, XBrushes.Black, new XPoint(t2, new XUnit(yBd + yLineH3 * 2, XGraphicsUnit.Millimeter)));
            gfx.DrawString("Poolvolumen:", p3, XBrushes.Black, new XPoint(t2, new XUnit(yBd + yLineH3 * 3, XGraphicsUnit.Millimeter)));
            gfx.DrawString("Saugseitige Rohrleitung:", p3, XBrushes.Black, new XPoint(t2, new XUnit(yBd + yLineH3 * 4, XGraphicsUnit.Millimeter)));
            gfx.DrawString("Systemdruck (Filterkessel):", p3, XBrushes.Black, new XPoint(t2, new XUnit(yBd + yLineH3 * 5, XGraphicsUnit.Millimeter)));

            if (string.IsNullOrEmpty(Pump.Manufacturer))
            {
                gfx.DrawString($"{Pump.ModellName}", h3, XBrushes.Black, new XPoint(t10, new XUnit(yBd + yLineH3, XGraphicsUnit.Millimeter)));
            }
            else
            {
                gfx.DrawString($"{Pump.ModellName} ({Pump.Manufacturer})", h3, XBrushes.Black, new XPoint(t10, new XUnit(yBd + yLineH3, XGraphicsUnit.Millimeter)));
            }
            gfx.DrawString(filterDiameter.ToString("f0") + " mm (A = " + filterArea.ToString("f1") + " cm²)", h3, XBrushes.Black, new XPoint(t10, new XUnit(yBd + yLineH3 * 2, XGraphicsUnit.Millimeter)));
            gfx.DrawString(poolVolume.ToString("f1") + " m³", h3, XBrushes.Black, new XPoint(t10, new XUnit(yBd + yLineH3 * 3, XGraphicsUnit.Millimeter)));
            if (SuctionPipe != null)
            {
                gfx.DrawString(SuctionPipe.ToString(), h3, XBrushes.Black, new XPoint(t10, new XUnit(yBd + yLineH3 * 4, XGraphicsUnit.Millimeter)));
            }
            else
            {
                gfx.DrawString("nicht angegeben", p3, XBrushes.Black, new XPoint(t10, new XUnit(yBd + yLineH3 * 4, XGraphicsUnit.Millimeter)));
            }
            gfx.DrawString(FilterPressure.ToString("f2") + " bar", h3, XBrushes.Black, new XPoint(t10, new XUnit(yBd + yLineH3 * 5, XGraphicsUnit.Millimeter)));


            int yCalc = 89;

            gfx.DrawString("Berechnung", h2, XBrushes.Black, new XPoint(t1, new XUnit(yCalc + yOffsH3, XGraphicsUnit.Millimeter)));

            gfx.DrawString("Pumpenvordruck:", p3, XBrushes.Black, new XPoint(t2, new XUnit(yCalc + yLineH3, XGraphicsUnit.Millimeter)));
            gfx.DrawString("Förderhöhe:", p3, XBrushes.Black, new XPoint(t2, new XUnit(yCalc + yLineH3 * 2, XGraphicsUnit.Millimeter)));
            gfx.DrawString("Volumenstrom:", p3, XBrushes.Black, new XPoint(t2, new XUnit(yCalc + yLineH3 * 3, XGraphicsUnit.Millimeter)));
            gfx.DrawString("Arbeitspunkt auf Pumpenkennlinie", p3, XBrushes.Black, new XPoint(t2, new XUnit(yCalc + yLineH3 * 4, XGraphicsUnit.Millimeter)));

            if (SuctionPipe != null)
            {
                gfx.DrawString(SuctionPressureDrop.ToString("f3") + " bar", h3, XBrushes.Black, new XPoint(t10, new XUnit(yCalc + yLineH3, XGraphicsUnit.Millimeter)));
            }
            else
            {
                gfx.DrawString("0 bar (nicht berechnet)", p3, XBrushes.Black, new XPoint(t10, new XUnit(yCalc + yLineH3, XGraphicsUnit.Millimeter)));
            }
            gfx.DrawString($"{SystemHead.ToString("f2")} mWS ({SystemPressure.ToString("f3")} bar)", h3, XBrushes.Black, new XPoint(t10, new XUnit(yCalc + yLineH3 * 2, XGraphicsUnit.Millimeter)));
            gfx.DrawString(SystemFlowRate.ToString("f2") + " m³/h", h3, XBrushes.Black, new XPoint(t10, new XUnit(yCalc + yLineH3 * 3, XGraphicsUnit.Millimeter)));



            var stream = new System.IO.MemoryStream();
            pklImage.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            stream.Position = 0;

            var pkl = XImage.FromStream(stream);

            var imageFrame = new XRect(
                new XPoint(t3, new XUnit(yCalc + 32, XGraphicsUnit.Millimeter)),
                new XPoint(new XUnit(180, XGraphicsUnit.Millimeter), new XUnit(yCalc + 127, XGraphicsUnit.Millimeter)));
            gfx.DrawImage(pkl, imageFrame);


            var filter           = new Pipe(1, filterDiameter, 0.01);
            var filterSpeed      = filter.CalcFlowVelocity(SystemFlowRate) * 3600;
            var filterSpeedBrush = XBrushes.Green;
            if (filterSpeed > 60 || filterSpeed < 40)
            {
                filterSpeedBrush = XBrushes.Red;
            }
            else if (filterSpeed > 55 || filterSpeed < 45)
            {
                filterSpeedBrush = XBrushes.Orange;
            }

            var tCycle1 = TimeSpan.FromHours(poolVolume / SystemFlowRate);
            var tCycle3 = TimeSpan.FromHours(poolVolume / SystemFlowRate * 3);

            int yRes = 225;

            gfx.DrawString("Auswertung", h2, XBrushes.Black, new XPoint(t1, new XUnit(yRes + yOffsH3, XGraphicsUnit.Millimeter)));

            gfx.DrawString("Umwälzzeiten", p3, XBrushes.Black, new XPoint(t2, new XUnit(yRes + yLineH3, XGraphicsUnit.Millimeter)));
            gfx.DrawString("1-fach:", p3, XBrushes.Black, new XPoint(t10 - 50, new XUnit(yRes + yLineH3, XGraphicsUnit.Millimeter)));
            gfx.DrawString("3-fach:", p3, XBrushes.Black, new XPoint(t10 - 50, new XUnit(yRes + yLineH3 * 2, XGraphicsUnit.Millimeter)));
            gfx.DrawString("Filtergeschwindigkeit:", p3, XBrushes.Black, new XPoint(t2, new XUnit(yRes + yLineH3 * 3, XGraphicsUnit.Millimeter)));

            if (tCycle1.TotalHours > 24)
            {
                gfx.DrawString($"> 24 Stunden", h3, XBrushes.Red, new XPoint(t10, new XUnit(yRes + yLineH3, XGraphicsUnit.Millimeter)));
            }
            else
            {
                gfx.DrawString($"{tCycle1.Hours} Stunden {tCycle1.Minutes} Minuten", h3, XBrushes.Black, new XPoint(t10, new XUnit(yRes + yLineH3, XGraphicsUnit.Millimeter)));
                if (Pump.PowerInput > 0)
                {
                    gfx.DrawString($"({(tCycle1.TotalHours * Pump.PowerInput).ToString("f1")} kWh)", h3, XBrushes.Black, new XPoint(t16, new XUnit(yRes + yLineH3, XGraphicsUnit.Millimeter)));
                }
            }

            if (tCycle3.TotalHours > 24)
            {
                gfx.DrawString($"> 24 Stunden", h3, XBrushes.Red, new XPoint(t10, new XUnit(yRes + yLineH3 * 2, XGraphicsUnit.Millimeter)));
            }
            else
            {
                gfx.DrawString($"{tCycle3.Hours} Stunden {tCycle3.Minutes} Minuten", h3, XBrushes.Black, new XPoint(t10, new XUnit(yRes + yLineH3 * 2, XGraphicsUnit.Millimeter)));
                if (Pump.PowerInput > 0)
                {
                    gfx.DrawString($"({(tCycle3.TotalHours * Pump.PowerInput).ToString("f1")} kWh)", h3, XBrushes.Black, new XPoint(t16, new XUnit(yRes + yLineH3 * 2, XGraphicsUnit.Millimeter)));
                }
            }

            gfx.DrawString(filterSpeed.ToString("f2") + " m/h", h3, filterSpeedBrush, new XPoint(t10, new XUnit(yRes + yLineH3 * 3, XGraphicsUnit.Millimeter)));


            var tf = new XTextFormatter(gfx);

            tf.DrawString("Im privaten Poolbereich sollte die Filtergeschwindigkeit nicht über 50 m/h betragen.\r\n" +
                          "Mit einer langsameren Filtergeschwindigkeit von rund 30 m/h würde das Ergebnis der Filtration zwar verbessert werden. " +
                          "Jedoch sind für Rückspülung (Reinigung des Filters) Spülgeschwindigkeiten von 50-60 m/h erforderlich. Da die Filterpumpe " +
                          "in privaten Pool für Filtration und Rückspülung ausgelegt wird, wählt man als Kompromiss eine Filtergeschwindigkeit um 50 m/h.",
                          p, XBrushes.Black,
                          new XRect(
                              new XPoint(t2, new XUnit(yRes + yLineH3 * 4 - 4, XGraphicsUnit.Millimeter)),
                              new XPoint(new XUnit(200, XGraphicsUnit.Millimeter), new XUnit(276, XGraphicsUnit.Millimeter))),
                          XStringFormats.TopLeft);


            // Save the document
            document.Save(path);

            // Start a viewer.
            Process.Start(path);
        }
Esempio n. 17
0
        private void BeginBox(XGraphics gfx, int number, int dayStart, int dayEnd, int month, int year)
        {
            XRect rect = new XRect(50, 50, 104, 60);

            rect.X += 104 * (number % 7);
            rect.Y += 60 * (number / 7);

            XLinearGradientBrush brush = new XLinearGradientBrush(new XPoint(1, 1), new XPoint(3, 3), this.backColor, this.backColor2);

            XBrush b = XBrushes.Transparent;

            gfx.DrawRectangle(borderPen, b, rect);



            var      day  = number - dayStart + 1;
            DateTime date = new DateTime();

            if (day < 1)
            {
                date = new DateTime(year, month, 1).AddDays(day - 1);
            }
            else if (day > dayEnd)
            {
                date = new DateTime(year, month, dayEnd).AddDays(day - dayEnd);
            }
            else
            {
                date = new DateTime(year, month, day);
            }

            var jobs = db.CleaningJobs.Include(x => x.Client).Where(x => x.CleanerId == CleanerId && x.Date.Date == date.Date)?.ToList();

            if (jobs != null && jobs.Count() == 1)
            {
                XFont font = new XFont("Verdana", 12, XFontStyle.Regular);
                gfx.DrawString($"{date.ToShortDateString()}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);
                rect.Y += 14;
                gfx.DrawString($"{jobs[0].TimeStart.ToString("HH:mm")}-{jobs[0].TimeEnd.ToString("HH:mm")}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);

                rect.Y += 14;
                gfx.DrawString($"{shorten(jobs[0].Client.Name, 15)}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);
                rect.Y += 14;
                gfx.DrawString($"{shorten(jobs[0].Client.Surname, 15)}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);
            }
            else if (jobs != null && jobs.Count() == 2)
            {
                XFont font = new XFont("Verdana", 10, XFontStyle.Regular);
                gfx.DrawString($"{date.ToShortDateString()}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);
                rect.Y += 11;
                gfx.DrawString($"{jobs[0].TimeStart.ToString("HH:mm")}-{jobs[0].TimeEnd.ToString("HH:mm")}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);

                rect.Y += 11;
                var name = shorten($"{jobs[0].Client.Name} {jobs[0].Client.Surname}", 19);
                gfx.DrawString(name, font, XBrushes.Navy, rect, XStringFormats.TopCenter);
                rect.Y += 11;
                gfx.DrawString($"{jobs[1].TimeStart.ToString("HH:mm")}-{jobs[1].TimeEnd.ToString("HH:mm")}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);
                rect.Y += 11;
                name    = shorten($"{jobs[1].Client.Name} {jobs[1].Client.Surname}", 19);
                gfx.DrawString(name, font, XBrushes.Navy, rect, XStringFormats.TopCenter);
            }
            else if (jobs != null && jobs.Count() > 2)
            {
                XFont font = new XFont("Verdana", 12, XFontStyle.Regular);
                gfx.DrawString($"{date.ToShortDateString()}", font, XBrushes.Navy, rect, XStringFormats.TopCenter);
                rect.Y += 14;
                gfx.DrawString($"Cant show more", font, XBrushes.Navy, rect, XStringFormats.TopCenter);
                rect.Y += 14;
                gfx.DrawString($"than 2 jobs!", font, XBrushes.Navy, rect, XStringFormats.TopCenter);
            }
            if (jobs != null)
            {
                foreach (var job in jobs)
                {
                    if (job.LocationId == 0)
                    {
                        addresses.Add($"{job.Client.Name} {job.Client.Surname} - {job.Client.Address}");
                    }
                    if (job.LocationId == 1)
                    {
                        addresses.Add($"{job.Client.Name} {job.Client.Surname} - {job.Client.Address2}");
                    }
                    if (job.LocationId == 2)
                    {
                        addresses.Add($"{job.Client.Name} {job.Client.Surname} - {job.Client.Address3}");
                    }
                    if (job.LocationId == 3)
                    {
                        addresses.Add($"{job.Client.Name} {job.Client.Surname} - {job.Client.Address4}");
                    }
                }
            }
            state = gfx.Save();
        }
Esempio n. 18
0
        /// <summary>
        /// Draws the content of the column plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            XRect plotAreaBox = cri.plotAreaRendererInfo.Rect;

            if (plotAreaBox.IsEmpty)
            {
                return;
            }

            XGraphics gfx = this.rendererParms.Graphics;

            double xMin = cri.xAxisRendererInfo.MinimumScale;
            double xMax = cri.xAxisRendererInfo.MaximumScale;
            double yMin = cri.yAxisRendererInfo.MinimumScale;
            double yMax = cri.yAxisRendererInfo.MaximumScale;

            LineFormatRenderer lineFormatRenderer;

            // Under some circumstances it is possible that no zero base line will be drawn,
            // e. g. because of unfavourable minimum/maximum scale and/or major tick, so force to draw
            // a zero base line if necessary.
            if (cri.yAxisRendererInfo.MajorGridlinesLineFormat != null ||
                cri.yAxisRendererInfo.MinorGridlinesLineFormat != null)
            {
                if (yMin < 0 && yMax > 0)
                {
                    XPoint[] points = new XPoint[2];
                    points[0].X = xMin;
                    points[0].Y = 0;
                    points[1].X = xMax;
                    points[1].Y = 0;
                    cri.plotAreaRendererInfo.matrix.TransformPoints(points);

                    if (cri.yAxisRendererInfo.MinorGridlinesLineFormat != null)
                    {
                        lineFormatRenderer = new LineFormatRenderer(gfx, cri.yAxisRendererInfo.MinorGridlinesLineFormat);
                    }
                    else
                    {
                        lineFormatRenderer = new LineFormatRenderer(gfx, cri.yAxisRendererInfo.MajorGridlinesLineFormat);
                    }

                    lineFormatRenderer.DrawLine(points[0], points[1]);
                }
            }

            // Draw columns
            XGraphicsState state = gfx.Save();

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                foreach (ColumnRendererInfo column in sri.pointRendererInfos)
                {
                    // Do not draw column if value is outside yMin/yMax range. Clipping does not make sense.
                    if (IsDataInside(yMin, yMax, column.point.value))
                    {
                        XLinearGradientBrush brush = new XLinearGradientBrush(column.Rect.BottomLeft, column.Rect.TopLeft, _orange, _orangeGradientEnd);
                        gfx.DrawRectangle(brush, column.Rect);
                    }
                }
            }

            // Draw borders around column.
            // A border can overlap neighbor columns, so it is important to draw borders at the end.
            //foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            //{
            //  foreach (ColumnRendererInfo column in sri.pointRendererInfos)
            //  {
            //    // Do not draw column if value is outside yMin/yMax range. Clipping does not make sense.
            //    if (IsDataInside(yMin, yMax, column.point.value) && column.LineFormat.Width > 0)
            //    {
            //      lineFormatRenderer = new LineFormatRenderer(gfx, column.LineFormat);
            //      lineFormatRenderer.DrawRectangle(column.Rect);
            //    }
            //  }
            //}
            gfx.Restore(state);
        }
Esempio n. 19
0
        void RealizeLinearGradientBrush(LinearGradientBrush brush, XForm xform)
        {
            XMatrix           matrix  = currentTransform;
            PdfShadingPattern pattern = new PdfShadingPattern(writer.Owner);

            pattern.Elements[PdfShadingPattern.Keys.PatternType] = new PdfInteger(2); // shading pattern

            // Setup shading
            PdfShading   shading   = new PdfShading(writer.Owner);
            PdfColorMode colorMode = PdfColorMode.Rgb; //this.document.Options.ColorMode;

            PdfDictionary function = BuildShadingFunction(brush.GradientStops, colorMode);

            function.Elements.SetString("/@", "This is the shading function of a LinearGradientBrush");
            shading.Elements[PdfShading.Keys.Function] = function;

            shading.Elements[PdfShading.Keys.ShadingType] = new PdfInteger(2); // Axial shading
            //if (colorMode != PdfColorMode.Cmyk)
            shading.Elements[PdfShading.Keys.ColorSpace] = new PdfName("/DeviceRGB");
            //else
            //shading.Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK");

            //double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
            double x1 = brush.StartPoint.X;
            double y1 = brush.StartPoint.Y;
            double x2 = brush.EndPoint.X;
            double y2 = brush.EndPoint.Y;

            shading.Elements[PdfShading.Keys.Coords] = new PdfLiteral("[{0:0.###} {1:0.###} {2:0.###} {3:0.###}]", x1, y1, x2, y2);

            // old: Elements[Keys.Background] = new PdfRawItem("[0 1 1]");
            // old: Elements[Keys.Domain] =
            shading.Elements[PdfShading.Keys.Extend] = new PdfLiteral("[true true]");

            // Setup pattern
            pattern.Elements[PdfShadingPattern.Keys.Shading] = shading;
            pattern.Elements[PdfShadingPattern.Keys.Matrix]  = PdfLiteral.FromMatrix(matrix); // new PdfLiteral("[" + PdfEncoders.ToString(matrix) + "]");

            string name = writer.Resources.AddPattern(pattern);

            writer.WriteLiteral("/Pattern cs\n", name);
            writer.WriteLiteral("{0} scn\n", name);

            double alpha = brush.Opacity * brush.GradientStops.GetAverageAlpha();

            if (alpha < 1 && writer.renderMode == RenderMode.Default)
            {
#if true
                PdfExtGState extGState = writer.Owner.ExtGStateTable.GetExtGStateNonStroke(alpha);
                string       gs        = writer.Resources.AddExtGState(extGState);
                writer.WriteLiteral("{0} gs\n", gs);
#else
#if true
                if (xform == null)
                {
                    PdfExtGState extGState = this.writer.Owner.ExtGStateTable.GetExtGStateNonStroke(alpha);
                    string       gs        = this.writer.Resources.AddExtGState(extGState);
                    this.writer.WriteGraphicState(extGState);
                }
                else
                {
                    //PdfFormXObject pdfForm = this.writer.Owner.FormTable.GetForm(form);
                    PdfFormXObject pdfForm = xform.pdfForm;
                    pdfForm.Elements.SetString("/@", "This is the Form XObject of the soft mask");

                    string formName = this.writer.Resources.AddForm(pdfForm);

                    PdfTransparencyGroupAttributes tgAttributes = new PdfTransparencyGroupAttributes(this.writer.Owner);
                    //this.writer.Owner.Internals.AddObject(tgAttributes);
                    tgAttributes.Elements.SetName(PdfTransparencyGroupAttributes.Keys.CS, "/DeviceRGB");

                    // Set reference to transparency group attributes
                    pdfForm.Elements.SetObject(PdfFormXObject.Keys.Group, tgAttributes);
                    pdfForm.Elements[PdfFormXObject.Keys.Matrix] = new PdfLiteral("[1.001 0 0 1.001 0.001 0.001]");


                    PdfSoftMask softmask = new PdfSoftMask(this.writer.Owner);
                    this.writer.Owner.Internals.AddObject(softmask);
                    softmask.Elements.SetString("/@", "This is the soft mask");
                    softmask.Elements.SetName(PdfSoftMask.Keys.S, "/Luminosity");
                    softmask.Elements.SetReference(PdfSoftMask.Keys.G, pdfForm);
                    //pdfForm.Elements.SetName(PdfFormXObject.Keys.Type, "Group");
                    //pdfForm.Elements.SetName(PdfFormXObject.Keys.ss.Ss.Type, "Group");

                    PdfExtGState extGState = new PdfExtGState(this.writer.Owner);
                    this.writer.Owner.Internals.AddObject(extGState);
                    extGState.Elements.SetReference(PdfExtGState.Keys.SMask, softmask);
                    this.writer.WriteGraphicState(extGState);
                }
#else
                XForm     form    = new XForm(this.writer.Owner, 220, 140);
                XGraphics formGfx = XGraphics.FromForm(form);

                // draw something
                //XSolidBrush xbrush = new XSolidBrush(XColor.FromArgb(128, 128, 128));
                XLinearGradientBrush xbrush = new XLinearGradientBrush(new XPoint(0, 0), new XPoint(220, 0), XColors.White, XColors.Black);
                formGfx.DrawRectangle(xbrush, -10000, -10000, 20000, 20000);
                //formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormat.TopLeft);
                formGfx.Dispose();

                // Close form
                form.Finish();
                PdfFormXObject pdfForm  = this.writer.Owner.FormTable.GetForm(form);
                string         formName = this.writer.Resources.AddForm(pdfForm);

                //double x = 20, y = 20;
                //double cx = 1;
                //double cy = 1;

                //this.writer.AppendFormat("q {2:0.###} 0 0 -{3:0.###} {0:0.###} {4:0.###} cm 100 Tz {5} Do Q\n",
                //  x, y, cx, cy, y + 0, formName);

                //this.writer.AppendFormat("q {2:0.###} 0 0 -{3:0.###} {0:0.###} {4:0.###} cm 100 Tz {5} Do Q\n",
                //  x, y, cx, cy, y + 220/1.5, formName);

                PdfTransparencyGroupAttributes tgAttributes = new PdfTransparencyGroupAttributes(this.writer.Owner);
                this.writer.Owner.Internals.AddObject(tgAttributes);

                tgAttributes.Elements.SetName(PdfTransparencyGroupAttributes.Keys.CS, "/DeviceRGB");


                // Set reference to transparency group attributes
                pdfForm.Elements.SetReference(PdfFormXObject.Keys.Group, tgAttributes);


                PdfSoftMask softmask = new PdfSoftMask(this.writer.Owner);
                this.writer.Owner.Internals.AddObject(softmask);
                softmask.Elements.SetName(PdfSoftMask.Keys.S, "/Luminosity");
                softmask.Elements.SetReference(PdfSoftMask.Keys.G, pdfForm);
                //pdfForm.Elements.SetName(PdfFormXObject.Keys.Type, "Group");
                //pdfForm.Elements.SetName(PdfFormXObject.Keys.ss.Ss.Type, "Group");

                PdfExtGState extGState = new PdfExtGState(this.writer.Owner);
                this.writer.Owner.Internals.AddObject(extGState);
                extGState.Elements.SetReference(PdfExtGState.Keys.SMask, softmask);
                this.writer.WriteGraphicState(extGState);
#endif
#endif
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Setups the shading from the specified brush.
        /// </summary>
        public void SetupFromBrush(XLinearGradientBrush brush)
        {
            if (brush == null)
            {
                throw new ArgumentNullException("brush");
            }

            PdfColorMode colorMode = this.document.Options.ColorMode;
            XColor       color1    = ColorSpaceHelper.EnsureColorMode(colorMode, brush.color1);
            XColor       color2    = ColorSpaceHelper.EnsureColorMode(colorMode, brush.color2);

            PdfDictionary function = new PdfDictionary();

            Elements[Keys.ShadingType] = new PdfInteger(2);
            if (colorMode != PdfColorMode.Cmyk)
            {
                Elements[Keys.ColorSpace] = new PdfName("/DeviceRGB");
            }
            else
            {
                Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK");
            }

            double x1 = 0, y1 = 0, x2 = 0, y2 = 0;

            if (brush.useRect)
            {
                switch (brush.linearGradientMode)
                {
                case XLinearGradientMode.Horizontal:
                    x1 = brush.rect.x;
                    y1 = brush.rect.y;
                    x2 = brush.rect.x + brush.rect.width;
                    y2 = brush.rect.y;
                    break;

                case XLinearGradientMode.Vertical:
                    x1 = brush.rect.x;
                    y1 = brush.rect.y;
                    x2 = brush.rect.x;
                    y2 = brush.rect.y + brush.rect.height;
                    break;

                case XLinearGradientMode.ForwardDiagonal:
                    x1 = brush.rect.x;
                    y1 = brush.rect.y;
                    x2 = brush.rect.x + brush.rect.width;
                    y2 = brush.rect.y + brush.rect.height;
                    break;

                case XLinearGradientMode.BackwardDiagonal:
                    x1 = brush.rect.x + brush.rect.width;
                    y1 = brush.rect.y;
                    x2 = brush.rect.x;
                    y2 = brush.rect.y + brush.rect.height;
                    break;
                }
            }
            else
            {
                x1 = brush.point1.x;
                y1 = brush.point1.y;
                x2 = brush.point2.x;
                y2 = brush.point2.y;
            }
            Elements[Keys.Coords] = new PdfLiteral("[{0:0.###} {1:0.###} {2:0.###} {3:0.###}]", x1, y1, x2, y2);

            //Elements[Keys.Background] = new PdfRawItem("[0 1 1]");
            //Elements[Keys.Domain] =
            Elements[Keys.Function] = function;
            //Elements[Keys.Extend] = new PdfRawItem("[true true]");

            string clr1 = "[" + PdfEncoders.ToString(color1, colorMode) + "]";
            string clr2 = "[" + PdfEncoders.ToString(color2, colorMode) + "]";

            function.Elements["/FunctionType"] = new PdfInteger(2);
            function.Elements["/C0"]           = new PdfLiteral(clr1);
            function.Elements["/C1"]           = new PdfLiteral(clr2);
            function.Elements["/Domain"]       = new PdfLiteral("[0 1]");
            function.Elements["/N"]            = new PdfInteger(1);
        }
Esempio n. 21
0
        /// <summary>
        /// Setups the shading from the specified brush.
        /// </summary>
        internal void SetupFromBrush(XLinearGradientBrush brush, XGraphicsPdfRenderer renderer)
        {
            if (brush == null)
            {
                throw new ArgumentNullException("brush");
            }

            PdfColorMode colorMode = _document.Options.ColorMode;
            XColor       color1    = ColorSpaceHelper.EnsureColorMode(colorMode, brush._color1);
            XColor       color2    = ColorSpaceHelper.EnsureColorMode(colorMode, brush._color2);

            PdfDictionary function = new PdfDictionary();

            Elements[Keys.ShadingType] = new PdfInteger(2);
            if (colorMode != PdfColorMode.Cmyk)
            {
                Elements[Keys.ColorSpace] = new PdfName("/DeviceRGB");
            }
            else
            {
                Elements[Keys.ColorSpace] = new PdfName("/DeviceCMYK");
            }

            double x1 = 0, y1 = 0, x2 = 0, y2 = 0;

            if (brush._useRect)
            {
                XPoint pt1 = renderer.WorldToView(brush._rect.TopLeft);
                XPoint pt2 = renderer.WorldToView(brush._rect.BottomRight);

                switch (brush._linearGradientMode)
                {
                case XLinearGradientMode.Horizontal:
                    x1 = pt1.X;
                    y1 = pt1.Y;
                    x2 = pt2.X;
                    y2 = pt1.Y;
                    break;

                case XLinearGradientMode.Vertical:
                    x1 = pt1.X;
                    y1 = pt1.Y;
                    x2 = pt1.X;
                    y2 = pt2.Y;
                    break;

                case XLinearGradientMode.ForwardDiagonal:
                    x1 = pt1.X;
                    y1 = pt1.Y;
                    x2 = pt2.X;
                    y2 = pt2.Y;
                    break;

                case XLinearGradientMode.BackwardDiagonal:
                    x1 = pt2.X;
                    y1 = pt1.Y;
                    x2 = pt1.X;
                    y2 = pt2.Y;
                    break;
                }
            }
            else
            {
                XPoint pt1 = renderer.WorldToView(brush._point1);
                XPoint pt2 = renderer.WorldToView(brush._point2);

                x1 = pt1.X;
                y1 = pt1.Y;
                x2 = pt2.X;
                y2 = pt2.Y;
            }

            const string format = Config.SignificantFigures3;

            Elements[Keys.Coords] = new PdfLiteral("[{0:" + format + "} {1:" + format + "} {2:" + format + "} {3:" + format + "}]", x1, y1, x2, y2);

            //Elements[Keys.Background] = new PdfRawItem("[0 1 1]");
            //Elements[Keys.Domain] =
            Elements[Keys.Function] = function;
            //Elements[Keys.Extend] = new PdfRawItem("[true true]");

            string clr1 = "[" + PdfEncoders.ToString(color1, colorMode) + "]";
            string clr2 = "[" + PdfEncoders.ToString(color2, colorMode) + "]";

            function.Elements["/FunctionType"] = new PdfInteger(2);
            function.Elements["/C0"]           = new PdfLiteral(clr1);
            function.Elements["/C1"]           = new PdfLiteral(clr2);
            function.Elements["/Domain"]       = new PdfLiteral("[0 1]");
            function.Elements["/N"]            = new PdfInteger(1);
        }
Esempio n. 22
0
        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);
        }