internal override void InitRendering(BarCodeRenderInfo info)
        {
            base.InitRendering(info);
            CalcThinBarWidth(info);
            info.BarHeight = Size.Height;
            // HACK in ThickThinBarCode
            if (TextLocation != TextLocation.None)
                info.BarHeight *= 4.0 / 5;

#if DEBUG_
            XColor back = XColors.LightSalmon;
            back.A = 0.3;
            XSolidBrush brush = new XSolidBrush(back);
            info.Gfx.DrawRectangle(brush, new XRect(info.Center - size / 2, size));
#endif
            switch (Direction)
            {
                case CodeDirection.RightToLeft:
                    info.Gfx.RotateAtTransform(180, info.Position);
                    break;

                case CodeDirection.TopToBottom:
                    info.Gfx.RotateAtTransform(90, info.Position);
                    break;

                case CodeDirection.BottomToTop:
                    info.Gfx.RotateAtTransform(-90, info.Position);
                    break;
            }
        }
    // ----- DrawRectangle ------------------------------------------------------------------------

    public void DrawRectangle(XPen pen, XSolidBrush brush, float x, float y, float width, float height)
    {
      if (this.gfx != null)
      {
        this.gfx.FillRectangle(brush.RealizeGdiBrush(), x, y, width, height);
        this.gfx.DrawRectangle(pen.RealizeGdiPen(), x, y, width, height);
      }
      if (this.pdfPage != null)
        this.pdfPage.PageContent.DrawRectangle(pen, brush, x, y, width, height);
    }
Beispiel #3
0
        private static void AddHeader(XGraphics gfx, AssesmentReportTO report, PdfPage page)
        {
            //Client Header
            XBrush brush       = new XSolidBrush(XColor.FromArgb(0, 188, 188, 188));
            XImage clientImage = XImage.FromFile(HttpContext.Current.Server.MapPath("~/img/" + report.AssesmentInfo.Company.Logo));

            gfx.DrawRectangle(brush, 0, 50, page.Width, 1);
            gfx.DrawImage(clientImage, 2, 2, 180, 45);

            gfx.DrawString("Fecha de finalización:", tinyFont, XBrushes.Black,
                           new XRect(page.Width - 195, 30, 100, 20),
                           XStringFormats.TopLeft);
            gfx.DrawString(report.AssesmentInfo.DateFinished.Value.ToString("MMMM dd yyyy"), tinyFont, XBrushes.Black,
                           new XRect(page.Width - 95, 30, 75, 20),
                           XStringFormats.TopLeft);

            // Evaluation Name
            XFont titleFont = new XFont(fontName, 15, XFontStyle.Bold);

            gfx.DrawString(report.AssesmentInfo.Evaluation.Name.ToUpper(), titleFont, XBrushes.Black,
                           new XRect(0, 70, page.Width, 20),
                           XStringFormats.Center);
        }
Beispiel #4
0
        protected override RBrush CreateSolidBrush(RColor color)
        {
            XBrush solidBrush;

            if (color == RColor.White)
            {
                solidBrush = XBrushes.White;
            }
            else if (color == RColor.Black)
            {
                solidBrush = XBrushes.Black;
            }
            else if (color.A < 1)
            {
                solidBrush = XBrushes.Transparent;
            }
            else
            {
                solidBrush = new XSolidBrush(Utils.Convert(color));
            }

            return(new BrushAdapter(solidBrush));
        }
Beispiel #5
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;

            if (brush is SolidBrush solidBrush)
            {
                xbrush = new XSolidBrush(solidBrush.Color);
            }
            else if (brush is LinearGradientBrush lgBrush)
            {
                //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);
        }
Beispiel #6
0
        private void CreatePdfWithTexts(XImage img, string pdfPath, ParticipantEntity participant)
        {
            var pdfPage = new PdfPage {
                Width = img.PointWidth, Height = img.PointHeight
            };
            var document = new PdfDocument();

            document.AddPage(pdfPage);
            var gfx = XGraphics.FromPdfPage(pdfPage);

            gfx.DrawImage(img, 0, 0);

            var drawFont  = new XFont("Arial", 48);
            var drawBrush = new XSolidBrush(XColors.Black);

            var texts = new List <ImageTextModel>
            {
                new ImageTextModel(participant.User.FullName, 1400f, 1002f),
                new ImageTextModel(participant.School, 1100f, 1124f),
                new ImageTextModel(participant.SchoolCity, 1524f, 1244f),
                new ImageTextModel(participant.MentoringTeacher, 1706f, 1481f)
                {
                    Font = new Font("Arial", 35)
                }
            };

            foreach (var textModel in texts)
            {
                gfx.DrawString(textModel.Text,
                               textModel.Font == null ? drawFont : new XFont("Arial", textModel.Font.Size), drawBrush, textModel.X,
                               textModel.Y);
            }

            document.Save(pdfPath);
            gfx.Dispose();
            document.Dispose();
        }
Beispiel #7
0
        internal override void Render(IRenderData renderData)
        {
            if (IsNotVisible(renderData))
            {
                return;
            }

            renderData.ElementBounds = GetBounds(renderData.ParentBounds);

            if (!IsBackground || renderData.IncludeBackground)
            {
                var pen = new XPen(XColor.FromArgb(BorderColor), BorderWidth.ToXUnit(0));

                if (BackgroundColor != null)
                {
                    var brush = new XSolidBrush(XColor.FromArgb(BackgroundColor.Value));
                    renderData.Graphics.DrawRectangle(pen, brush, renderData.ElementBounds);
                }
                else
                {
                    renderData.Graphics.DrawRectangle(pen, renderData.ElementBounds);
                }
            }
        }
Beispiel #8
0
        private void DrawVectorLayer(XGraphics gfx, Map map, double scaleFactor, VectorLayer lyr, string lineColor, double lineWidth, string fillColor)
        {
            TransformsProvider tp      = new TransformsProvider(gfx);
            BoundingBox        geombox = map.GetExtents();

            XPen        xp = new XPen(XColor.FromName(lineColor), lineWidth);
            XSolidBrush xb = new XSolidBrush(XColor.FromName(fillColor));

            foreach (Geometry geom in (lyr as VectorLayer).DataSource.GetGeometriesInView(geombox))
            {
                if ((geom) is MultiLineString)
                {
                    XGraphicsPath g = tp.TransformGeom(scaleFactor, (MultiLineString)geom, geombox);
                    this._geomCache.Add(new PDFGeom(g, xp, null));
                    gfx.DrawPath(xp, g);
                }
                if ((geom) is MultiPolygon)
                {
                    XGraphicsPath g = tp.TransformGeom(scaleFactor, (MultiPolygon)geom, geombox);
                    this._geomCache.Add(new PDFGeom(g, xp, xb));
                    gfx.DrawPath(xp, xb, g);
                }
            }
        }
Beispiel #9
0
        public void PrintPDF(List <WorkersDTO> workers, string nameOfSection, string month, string year, bool allSection,
                             List <string> sections, List <int> redDays)
        {
            List <int> iRedDays = new List <int>();

            iRedDays = redDays;
            List <string> AllSections = new List <string>();

            AllSections = sections;
            List <WorkersDTO> workersDTO = new List <WorkersDTO>();

            workersDTO = workers;
            string sNameOfSection = "";
            string sMonth         = "";
            string sYear          = "";
            bool   bAllSection    = false;
            int    iDaysInMonth   = 0;

            sNameOfSection = nameOfSection;
            if (string.IsNullOrEmpty(month))
            {
                sMonth = DateTime.Now.Month.ToString();
            }
            else
            {
                sMonth = month;
            }
            if (string.IsNullOrEmpty(year))
            {
                sYear = DateTime.Now.Year.ToString();
            }
            else
            {
                sYear = year;
            }
            bAllSection  = allSection;
            iDaysInMonth = DateTime.DaysInMonth(Convert.ToInt32(sYear), Convert.ToInt32(sMonth));
            sMonth       = CalendarMonth(Convert.ToInt32(sMonth));


            PdfDocument    document = new PdfDocument();
            PdfPage        page;
            XGraphics      gfx;
            XFont          font = new XFont("Cambria", 10, XFontStyle.Bold);
            XPen           pen  = new XPen(XColor.FromName("Black"));
            XTextFormatter tf;
            XBrush         xBrush = new XSolidBrush(XColor.FromArgb(100, 83, 83, 83));

            //drukuje bez nazwisk jeden dział i sortowanie descending by kier był pierwszy
            double x1 = 80;
            double x2 = 80;
            double y1 = 68;
            double y2 = 198;

            double xx1 = 85;

            int iHowMuchWorkers   = 0;
            int iHowMuchWorkersIs = 0;
            int iHowMuchPages     = 0;

            workersDTO = workersDTO.OrderBy(x => x.Section).ThenByDescending(x => x.IsManager).ThenBy(x => x.Surname).ThenBy(x => x.Name).ToList();
            for (int i = 0; i < workersDTO.Count; i++)
            {
                if (string.IsNullOrEmpty(workersDTO[i].Name))
                {
                    workersDTO.RemoveAt(i);
                }
            }
            if (allSection == false)
            {
                workersDTO = workersDTO.FindAll(x => x.Section == sNameOfSection).ToList();
            }
            AllSections = AllSections.OrderBy(x => x).ToList();
            if (allSection == true)
            {
                sNameOfSection = AllSections[0];
                iHowMuchPages  = AllSections.Count;
                string section      = sNameOfSection;
                int    WorkersCount = 0;
                for (int i = 0; i < workersDTO.Count; i++)
                {
                    if (workersDTO[i].Section == section)
                    {
                        WorkersCount++;
                    }
                    else
                    {
                        section = workersDTO[i].Section;
                        if (WorkersCount >= 10)
                        {
                            iHowMuchPages = iHowMuchPages + 1;
                            WorkersCount  = 0;
                        }
                    }
                }
                if (WorkersCount >= 10)
                {
                    iHowMuchPages = iHowMuchPages + 1;
                    WorkersCount  = 0;
                }
            }
            else
            {
                iHowMuchPages = iHowMuchPages + 1;
                string section      = sNameOfSection;
                int    WorkersCount = 0;
                for (int i = 0; i < workersDTO.Count; i++)
                {
                    if (workersDTO[i].Section == section)
                    {
                        WorkersCount++;
                    }
                    else
                    {
                        section = workersDTO[i].Section;
                        if (WorkersCount >= 10)
                        {
                            iHowMuchPages = iHowMuchPages + 1;
                            WorkersCount  = 0;
                        }
                    }
                }
                if (WorkersCount >= 10)
                {
                    iHowMuchPages = iHowMuchPages + 1;
                    WorkersCount  = 0;
                }
            }


            foreach (var worker in workersDTO)
            {
                if (!string.IsNullOrEmpty(worker.Name))
                {
                    iHowMuchWorkers++;
                }
            }
            for (int a = 0; a < iHowMuchPages; a++)
            {
                page = document.AddPage();
                gfx  = XGraphics.FromPdfPage(page);
                tf   = new XTextFormatter(gfx);
                //wiersze co 25 kolumny co

                gfx.DrawLine(pen, 50, 45, 550, 45);
                gfx.DrawLine(pen, 50, 45, 50, 65);
                gfx.DrawLine(pen, 550, 45, 550, 65);
                gfx.DrawLine(pen, 50, 65, 550, 65);

                XRect rect = new XRect(70, 50, 500, 20);
                tf.DrawString("Nazwa komórki organizacyjnej: " + sNameOfSection, font, XBrushes.Black, rect, XStringFormats.TopLeft);

                //linie poziome głownej tabeli
                gfx.DrawLine(pen, 50, 68, 550, 68);
                gfx.DrawLine(pen, 50, 198, 550, 198);


                //poziome
                gfx.DrawLine(pen, 50, 68, 50, 198);
                gfx.Save();
                gfx.RotateAtTransform(270, new XPoint(60, 190));
                XRect rectMiesiac = new XRect(60, 190, 130, 30);
                tf.DrawString("M-c " + sMonth + " " + sYear, font, XBrushes.Black, rectMiesiac, XStringFormats.TopLeft);
                gfx.Restore();
                gfx.DrawLine(pen, 80, 68, 80, 198);


                for (int i = 0; i < 10; i++)
                {
                    if (iHowMuchWorkersIs < workersDTO.Count && workersDTO[iHowMuchWorkersIs].Name != "")
                    {
                        if (workersDTO[iHowMuchWorkersIs].Section == sNameOfSection)
                        {
                            gfx.Save();
                            gfx.RotateAtTransform(270, new XPoint(xx1, 190));
                            XRect rectUserX1 = new XRect(xx1, 190, 130, 20);
                            tf.DrawString(workersDTO[iHowMuchWorkersIs].Surname, font, XBrushes.Black, rectUserX1, XStringFormats.TopLeft);
                            gfx.Restore();
                            gfx.Save();
                            gfx.RotateAtTransform(270, new XPoint(xx1 + 15, 190));
                            XRect rectUserX2 = new XRect(xx1 + 15, 190, 130, 20);
                            tf.DrawString(workersDTO[iHowMuchWorkersIs].Name, font, XBrushes.Black, rectUserX2, XStringFormats.TopLeft);
                            gfx.Restore();
                            iHowMuchWorkersIs++;
                        }
                        else
                        {
                            //sNameOfSection = workersDTO[iHowMuchWorkersIs].Section;
                            //break;
                            //goto endOfWorkers;
                        }
                    }
                    //endOfWorkers:
                    xx1 = xx1 + 43;
                    x1  = x1 + 43;
                    x2  = x2 + 43;
                    gfx.DrawLine(pen, x1, y1, x2, y2);
                }
                if (iHowMuchWorkersIs < workersDTO.Count)
                {
                    sNameOfSection = workersDTO[iHowMuchWorkersIs].Section;
                }
                //iHowMuchWorkersIs++;
                x1 = 80;
                x2 = 80;
                y1 = 68;
                y2 = 198;

                xx1 = 85;

                gfx.Save();
                gfx.RotateAtTransform(270, new XPoint(525, 190));
                XRect rectPodpis = new XRect(525, 190, 130, 40);
                tf.DrawString("Podpis kier. jedn. org.", font, XBrushes.Black, rectPodpis, XStringFormats.TopLeft);
                gfx.Restore();



                gfx.DrawLine(pen, 550, 68, 550, 198);
                //za tabelą
                //522 pixele
                double ysize = 0;
                if (iDaysInMonth == 31)
                {
                    ysize = 16.84;                     //16px
                }
                if (iDaysInMonth == 30)
                {
                    ysize = 17.4;                     //17px
                }
                if (iDaysInMonth == 29)
                {
                    ysize = 18;                     //18px
                }
                if (iDaysInMonth == 28)
                {
                    ysize = 18.64;                     //18px
                }
                double ySizeRows = 198;
                double xSizeRows = 123;
                for (int i = 0; i < iDaysInMonth; i++)
                {
                    //linie poziome dolne
                    gfx.DrawLine(pen, 50, ySizeRows + ysize, 550, ySizeRows + ysize);
                    //pionowe linie wiersza
                    //piersza komorka dwie linie
                    gfx.DrawLine(pen, 50, ySizeRows, 50, ySizeRows + ysize);
                    XRect rectDays = new XRect(55, ySizeRows + 2, 20, 20);
                    tf.DrawString((i + 1).ToString(), font, XBrushes.Black, rectDays, XStringFormats.TopLeft);
                    gfx.DrawLine(pen, 80, ySizeRows, 80, ySizeRows + ysize);
                    //ostatnia linia komórki

                    gfx.DrawLine(pen, 550, ySizeRows, 550, ySizeRows + ysize);

                    //reszta lini
                    foreach (var redDay in iRedDays)
                    {
                        if ((i + 1) == redDay)
                        {
                            XRect rectGray = new XRect(80, ySizeRows, 470, ysize);
                            gfx.DrawRectangle(xBrush, rectGray);
                        }
                    }
                    for (int z = 0; z < 10; z++)
                    {
                        gfx.DrawLine(pen, xSizeRows, ySizeRows, xSizeRows, ySizeRows + ysize);
                        xSizeRows = xSizeRows + 43;
                    }
                    ySizeRows = ySizeRows + ysize;
                    xSizeRows = 123;
                }


                gfx.DrawLine(pen, 50, 720, 550, 720);
                //dolna tabelka
                //linie poziome
                gfx.DrawLine(pen, 50, 730, 550, 730);
                gfx.DrawLine(pen, 50, 780, 550, 780);
                //linie pionowe i pomiedzy zawartosci
                gfx.DrawLine(pen, 50, 730, 50, 780);
                XRect rect1 = new XRect(60, 750, 50, 40);
                tf.DrawString("Razem dni", font, XBrushes.Black, rect1, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 120, 730, 120, 780);


                XRect rect2 = new XRect(138, 737, 50, 40);
                tf.DrawString("C", font, XBrushes.Black, rect2, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 163, 730, 163, 780);


                XRect rect3 = new XRect(178, 737, 50, 40);
                tf.DrawString("C(s)", font, XBrushes.Black, rect3, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 206, 730, 206, 780);



                XRect rect4 = new XRect(224, 737, 50, 40);
                tf.DrawString("K", font, XBrushes.Black, rect4, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 249, 730, 249, 780);



                XRect rect5 = new XRect(263, 737, 50, 40);
                tf.DrawString("M", font, XBrushes.Black, rect5, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 293, 730, 293, 780);



                XRect rect6 = new XRect(311, 737, 50, 40);
                tf.DrawString("P", font, XBrushes.Black, rect6, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 336, 730, 336, 780);



                XRect rect7 = new XRect(354, 737, 50, 40);
                tf.DrawString("S", font, XBrushes.Black, rect7, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 379, 730, 379, 780);



                XRect rect8 = new XRect(397, 737, 50, 40);
                tf.DrawString("O", font, XBrushes.Black, rect8, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 422, 730, 422, 780);



                XRect rect9 = new XRect(440, 737, 50, 40);
                tf.DrawString("R", font, XBrushes.Black, rect9, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 465, 730, 465, 780);



                XRect rect10 = new XRect(483, 737, 50, 40);
                tf.DrawString("U", font, XBrushes.Black, rect10, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 508, 730, 508, 780);



                XRect rect11 = new XRect(526, 737, 50, 40);
                tf.DrawString("N", font, XBrushes.Black, rect11, XStringFormats.TopLeft);
                gfx.DrawLine(pen, 550, 730, 550, 780);

                //pozioma linia tabela dolna linia w środku
                gfx.DrawLine(pen, 120, 755, 550, 755);

                //dolny wpis
                XRect rectDown = new XRect(50, 790, 550, 790);
                tf.DrawString("Razem spóźnienia: usprawiedliwione - min.: ................................... nieusprawiedliwione - min.: ................................... ",
                              font, XBrushes.Black, rectDown, XStringFormats.TopLeft);
            }


            // Save
            const string filename = @"C:\inetpub\wwwroot\ListaObecnosci.pdf";

            //var savePath = Path.Combine(Environment.GetFolderPath((Environment.SpecialFolder.ApplicationData)), "Lista obecności");
            //var path = savePath + "\\" + filename;
            document.Save(filename);
            //PdfFilePrinter.AdobeReaderPath = @"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe";
            //PdfFilePrinter printer = new PdfFilePrinter(pdfFileName, printerName);
            //printer.Print();

            RedirectToPDF = true;
        }
Beispiel #10
0
        // The end goal is to have a user select the path of a PDf in need of watermarks.
        // Submit the file and press GO. Once they press Go, it grabs the pdf and watermarks it, then saves it in the network folder.

        public void markPDF(string filepath, string watermark, string userfile, int fontSize, string destination)
        {
            string userWatermark = watermark;

            // If the watermark field is empty.
            if (string.IsNullOrEmpty(filepath))
            {
                MessageBox.Show("ERROR: No PDF selected. \n \nSelect a correct file.", "WaterPDF", MessageBoxButtons.OK);// Alert the user
            }
            // If the path field is empty.
            else if (string.IsNullOrEmpty(userWatermark))
            {
                MessageBox.Show("ERROR: No Watermark text. \n \nEnter text for the watermark.", "WaterPDF", MessageBoxButtons.OK);  // Alert the user.
            }
            // If the new filename is empty.
            else if (string.IsNullOrWhiteSpace(userfile))
            {
                MessageBox.Show("ERROR: No save filename. \n \nEnter a save filename", "WaterPDF", MessageBoxButtons.OK); // Alert the user.
            }
            else if (string.IsNullOrWhiteSpace(destination))
            {
                MessageBox.Show("ERROR : No destination. \n \nChoose a save folder.", "WaterPDF", MessageBoxButtons.OK); // Alert the user.
            }
            else
            {
                // Creates a new file path to save the watermarked PDF.
                string newFileName = destination + @"\" + userfile + ".pdf";

                // Opens the file from the path provided.
                PdfDocument document = PdfReader.Open(filepath);

                // Counts the amount of pages in the PDF.
                PdfPages pages = document.Pages;

                // foreach page in pdf
                // Paint the pdf and then move onto the next one?

                // Sets the first page as the page to work on.
                PdfPage page  = document.Pages[0];
                string  fonts = Convert.ToString(fontSize);

                int.TryParse(fonts, out int result);

                // Creating the font variable.
                XFont font = new XFont("Arial", result, XFontStyle.Regular);
                // Creating the graphics.
                XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

                var size = gfx.MeasureString(watermark, font);

                // Creating the coordinates.
                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);

                var format = new XStringFormat();
                format.Alignment     = XStringAlignment.Near;
                format.LineAlignment = XLineAlignment.Near;

                // Creating the brush to paint with.
                XBrush brush = new XSolidBrush(XColor.FromKnownColor(XKnownColor.LightSlateGray));

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

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

                // Saves it in the provided location.
                document.Save(newFileName);
                if (MessageBox.Show("Your PDF has been watered.", "WaterPDF") == DialogResult.OK)
                {
                    // Alerts the user that the file was saved and creates an explorer window of the destination.
                    System.Diagnostics.Process.Start("explorer.exe", destination);
                }
            }
        }
    // ----- DrawEllipse --------------------------------------------------------------------------

    //public void DrawEllipse(XPen pen, Rectangle rect);
    //public void DrawEllipse(XPen pen, RectangleF rect);
    //public void DrawEllipse(XPen pen, int x, int y, int width, int height);
    //public void DrawEllipse(XPen pen, float x, float y, float width, float height);

    // ----- DrawPolygon --------------------------------------------------------------------------

    //public void DrawPolygon(XPen pen, Point[] points);
    //public void DrawPolygon(XPen pen, PointF[] points);

    // ----- DrawPath -----------------------------------------------------------------------------

    public void DrawPath(XPen pen, XSolidBrush brush, XGraphicsPath path)
    {
      if (this.gfx != null)
      {
        this.gfx.FillPath(brush.RealizeGdiBrush(), path.RealizeGdiPath());
        this.gfx.DrawPath(pen.RealizeGdiPen(), path.RealizeGdiPath());
      }
      if (this.pdfPage != null)
        this.pdfPage.PageContent.DrawPath(pen, brush, path);
    }
Beispiel #12
0
        XBrush createBrush(PBrush pBrush)
        {
            XBrush brush = new XSolidBrush(pBrush.GetMainColor());

            return(brush);
        }
Beispiel #13
0
        public static void generateAndSavePDF(Session session, string savePath, Stream imageStream)
        {
            //prepare session (load shots into series)
            session.AllSeries.Clear();
            foreach (Shot s in session.Shots)
            {
                session.addLoadedShot(s);
            }

            PdfDocument document = new PdfDocument();

            document.Info.Title = "Session " + session.id;

            PdfPage firstPage = document.AddPage();
            int     pageNo    = 1;
            //dimensions:  595 x 792 - good both for A4 and for Letter

            int  blackRings = 0;
            bool solidInner = false;

            decimal[] rings = null;
            if (session.targetType == Session.TargetType.Pistol)
            {
                blackRings = ISSF.pistolBlackRings;
                rings      = ISSF.ringsPistol;
                solidInner = false;
            }
            else if (session.targetType == Session.TargetType.Rifle)
            {
                blackRings = ISSF.rifleBlackRings;
                rings      = ISSF.ringsRifle;
                solidInner = true;
            }
            else
            {
                Console.WriteLine("WTF");
            }

            XPen   penBlack   = new XPen(XColor.FromKnownColor(XKnownColor.Black), 0.75);
            XBrush brushBlack = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black));
            Font   f          = new Font("Arial", 12, GraphicsUnit.World);

            //session target
            if (session.targetType == Session.TargetType.Pistol)
            {
                paintTarget(250, 20, 20, blackRings, rings, 1, solidInner, session.Shots, firstPage);
            }
            else
            {
                paintTarget(250, 20, 20, blackRings, rings, 0.29m, solidInner, session.Shots, firstPage);
            }


            //session data

            printSessionData(firstPage, 280, 20, 295, 250, session);


            //draw series header
            XGraphics gfx = XGraphics.FromPdfPage(firstPage);

            gfx.DrawLine(penBlack, 20, 290, 575, 290);

            gfx.DrawString("Series (" + session.AllSeries.Count + ")", f, brushBlack, 25, 285);



            //draw footer
            XBrush brushLight = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Linen));

            gfx.DrawRectangle(brushLight, 20, 770, 555, 10);
            Font f2 = new Font("Arial", 6, GraphicsUnit.World);

            gfx.DrawString("Page " + pageNo, f2, brushBlack, new XPoint(550, 777));
            XImage img = XImage.FromStream(imageStream);

            gfx.DrawImage(img, new XPoint(22, 771));

            gfx.Dispose();

            //series 1
            if (session.AllSeries.Count > 0)
            {
                int     y     = 295;
                decimal zoom2 = getZoom(session.AllSeries[0], session.targetType);
                paintTarget(150, 20, y, blackRings, rings, zoom2, solidInner, session.AllSeries[0], firstPage);
                printSeriesData(firstPage, 180, y, 395, 150, session.AllSeries[0], 1, session);
            }

            //series 2
            if (session.AllSeries.Count > 1)
            {
                int     y     = 455;
                decimal zoom2 = getZoom(session.AllSeries[1], session.targetType);
                paintTarget(150, 20, y, blackRings, rings, zoom2, solidInner, session.AllSeries[1], firstPage);
                printSeriesData(firstPage, 180, y, 395, 150, session.AllSeries[1], 2, session);
            }

            //series 3
            if (session.AllSeries.Count > 2)
            {
                int     y     = 615;
                decimal zoom2 = getZoom(session.AllSeries[2], session.targetType);
                paintTarget(150, 20, y, blackRings, rings, zoom2, solidInner, session.AllSeries[2], firstPage);
                printSeriesData(firstPage, 180, y, 395, 150, session.AllSeries[2], 3, session);
            }


            if (session.AllSeries.Count > 3)
            {
                //more pages needed
                PdfPage page = null;
                int     y    = 20;
                for (int p = 3; p < session.AllSeries.Count; p++)
                {
                    if ((p + 1) % 4 == 0)
                    {
                        page = document.AddPage();
                        pageNo++;
                        y = 20;
                    }

                    decimal zoom2 = getZoom(session.AllSeries[p], session.targetType);
                    paintTarget(150, 20, y, blackRings, rings, zoom2, solidInner, session.AllSeries[p], page);
                    printSeriesData(page, 180, y, 395, 150, session.AllSeries[p], p + 1, session);
                    y += 170;

                    //draw footer
                    gfx = XGraphics.FromPdfPage(page);
                    gfx.DrawRectangle(brushLight, 20, 770, 555, 10);
                    gfx.DrawString("Page " + pageNo, f2, brushBlack, new XPoint(550, 777));
                    gfx.DrawImage(img, new XPoint(22, 771));
                    gfx.Dispose();
                }
            }

            PdfPage notes = document.AddPage();

            pageNo++;
            gfx = XGraphics.FromPdfPage(notes);
            RichTextBox r = new RichTextBox();

            r.Rtf = session.diaryEntry;
            gfx.DrawLine(penBlack, 20, 30, 575, 30);
            gfx.DrawString("Diary", f, brushBlack, 30, 25);

            XTextFormatter tf = new XTextFormatter(gfx);

            tf.Alignment = XParagraphAlignment.Left;
            f            = new Font("Arial", 12, GraphicsUnit.World);
            tf.DrawString(r.Text, f, brushBlack, new XRect(25, 40, 575, 782));

            gfx.DrawRectangle(brushLight, 20, 770, 555, 10);
            gfx.DrawString("Page " + pageNo, f2, brushBlack, new XPoint(550, 777));
            gfx.DrawImage(img, new XPoint(22, 771));

            gfx.Dispose();

            string filename = savePath + Path.DirectorySeparatorChar + "Session " + session.id + ".pdf";

            try {
                document.Save(filename);
                Process.Start(filename);
            } catch (Exception ex) {
                MessageBox.Show("Error saving pdf!  " + Environment.NewLine + ex.Message, "PDF Export Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Console.WriteLine("Error saving pdf " + ex.Message);
            }
        }
        //pagrindine pdf piesimo funkcija
        public void Generate(MySqlConnection conn)
        {
            conn.Open();

            PdfDocument     document = new PdfDocument();
            PdfPage         page     = document.AddPage();
            XGraphics       gfx      = XGraphics.FromPdfPage(page);
            XPdfFontOptions options  = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            //spalvos
            XBrush lblue = new XSolidBrush(XColor.FromArgb(158, 217, 252));
            XBrush pblue = new XSolidBrush(XColor.FromArgb(21, 112, 247));

            //fonts
            XFont header           = new XFont("Arial", 13, XFontStyle.BoldItalic, options);
            XFont small            = new XFont("Arial", 8, XFontStyle.Regular, options);
            XFont normal           = new XFont("Arial", 10, XFontStyle.Regular, options);
            XFont normalBold       = new XFont("Arial", 10, XFontStyle.Bold, options);
            XFont normalItalic     = new XFont("Arial", 10, XFontStyle.Italic, options);
            XFont normalBoldItalic = new XFont("Arial", 10, XFontStyle.BoldItalic, options);

            //'piestukai'
            XPen black       = new XPen(XColors.Black, 1);
            XPen gray        = new XPen(XColors.Gray, 1);
            XPen neutralRect = new XPen(XColors.Gray, 1);
            XPen goodRect    = new XPen(XColors.Aqua, 1);


            string          sql  = "SELECT ob_addr FROM objektai WHERE obid=" + this.obid + ";";
            MySqlCommand    comm = new MySqlCommand(sql, conn);
            MySqlDataReader data = comm.ExecuteReader();

            string buf;


            //HEADER
            string addr = "";

            while (data.Read())
            {
                addr = data["ob_addr"].ToString();
            }
            buf = addr + " mokesčiai";
            gfx.DrawString(buf, header, XBrushes.Black, new XRect(0, 0, page.Width, 100), XStringFormats.Center);
            gfx.DrawLine(black, 40, 90, page.Width - 40, 90);

            //DATA

            buf = "Data: " + DateTime.Now.ToString("MM-yyyy");
            gfx.DrawRectangle(black, XBrushes.Beige, 40, 95, 100, 20);
            gfx.DrawString(buf, normalBold, XBrushes.Black, new XRect(45, 100, page.Width - 80, 19), XStringFormats.TopLeft);

            //BENDRIJA

            //title
            buf = "Bendrijos mokesčiai";
            gfx.DrawRectangle(neutralRect, XBrushes.Beige, 40, 130, page.Width - 80, 18);
            gfx.DrawString(buf, normalBoldItalic, XBrushes.Black, new XRect(40, 130, page.Width - 80, 18), XStringFormats.Center);

            //tableheader
            buf = "Mokestis";
            gfx.DrawString(buf, normalBold, XBrushes.Black, new XRect(40, 155, 455, 18), XStringFormats.Center);
            buf = "Kaina";
            gfx.DrawString(buf, normalBold, XBrushes.Black, new XRect(495, 155, 60, 18), XStringFormats.Center);

            //table
            int lineheight = 16;

            double ypoint = 155 + 16 * (bendrpav.Count + 1);

            for (int i = 0; i < bendrpav.Count; i++)
            {
                int ycoords = lineheight * (i + 1);
                gfx.DrawRectangle(gray, 40, 155 + ycoords, 455, lineheight);
                gfx.DrawRectangle(gray, 495, 155 + ycoords, 60, lineheight);
                gfx.DrawString(bendrpav[i], small, XBrushes.Black, new XRect(45, 155 + ycoords + 3.5, 455, lineheight), XStringFormats.TopLeft);
                gfx.DrawString(bendrkain[i].ToString(), small, XBrushes.Black, new XRect(500, 155 + ycoords + 3.5, 60, lineheight), XStringFormats.TopLeft);
            }

            //sum
            buf = "Bendrijos mokesčių suma:";

            ypoint += lineheight;

            gfx.DrawRectangle(black, lblue, 40, ypoint, 150, 18);
            gfx.DrawString(buf, normalBold, pblue, new XRect(45, ypoint + 3, 150, 18), XStringFormats.TopLeft);
            gfx.DrawRectangle(black, lblue, 190, ypoint, 60, 18);
            gfx.DrawString(bendrkain.Sum().ToString(), normalBold, XBrushes.Black, new XRect(195, ypoint + 3, 60, 18), XStringFormats.TopLeft);



            ypoint += 28;

            gfx.DrawLine(black, 40, ypoint, page.Width - 40, ypoint);

            ypoint += 10;

            //KOMUNALINIAI

            //header
            buf = "Komunaliniai patarnavimai (vanduo, šiluma, internetas bei pan.)";
            gfx.DrawRectangle(neutralRect, XBrushes.Beige, 40, ypoint, page.Width - 80, 18);
            gfx.DrawString(buf, normalBoldItalic, XBrushes.Black, new XRect(40, ypoint, page.Width - 80, 18), XStringFormats.Center);

            ypoint += 23;

            //table
            gfx.DrawRectangle(black, XBrushes.LightGray, 170, ypoint, 128, lineheight);
            gfx.DrawString("Išnaudota", small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center);
            gfx.DrawRectangle(black, XBrushes.LightGray, 298, ypoint, 128, lineheight);
            gfx.DrawString("Kaina/Vnt.", small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center);
            gfx.DrawRectangle(black, XBrushes.LightGray, 426, ypoint, 129, lineheight);
            gfx.DrawString("Suma", small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center);

            ypoint += lineheight;
            double rate   = 0;
            double komsum = 0;

            for (int i = 0; i < 4; i++)
            {
                gfx.DrawRectangle(black, XBrushes.LightGray, 40, ypoint, 130, lineheight);
                gfx.DrawRectangle(black, 170, ypoint, 128, lineheight);
                gfx.DrawRectangle(black, 298, ypoint, 128, lineheight);
                gfx.DrawRectangle(black, 426, ypoint, 129, lineheight);

                if (i == 0)
                {
                    gfx.DrawString("Elektra (kW/h)", small, XBrushes.Black, new XRect(40, ypoint, 130, lineheight), XStringFormats.Center);
                    rate = getOperatorRate("e");
                    gfx.DrawString(elek.ToString(), small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center);
                    gfx.DrawString(rate.ToString(), small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center);
                    gfx.DrawString((elek * rate).ToString(), small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center);
                    komsum += elek * rate;
                }
                if (i == 1)
                {
                    gfx.DrawString("Dujos (MW/h)", small, XBrushes.Black, new XRect(40, ypoint, 130, lineheight), XStringFormats.Center);
                    rate = getOperatorRate("d");
                    gfx.DrawString(duj.ToString(), small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center);
                    gfx.DrawString(rate.ToString(), small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center);
                    gfx.DrawString((duj * rate).ToString(), small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center);
                    komsum += duj * rate;
                }
                if (i == 2)
                {
                    gfx.DrawString("Vanduo (m^3)", small, XBrushes.Black, new XRect(40, ypoint, 130, lineheight), XStringFormats.Center);
                    rate = getOperatorRate("v");
                    gfx.DrawString(vand.ToString(), small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center);
                    gfx.DrawString(rate.ToString(), small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center);
                    gfx.DrawString((vand * rate).ToString(), small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center);
                    komsum += vand * rate;
                }
                if (i == 3)
                {
                    gfx.DrawString("Internetas (Eur/mėn)", small, XBrushes.Black, new XRect(40, ypoint, 130, lineheight), XStringFormats.Center);
                    rate = getOperatorRate("i");
                    gfx.DrawString("---", small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center);
                    gfx.DrawString(rate.ToString(), small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center);
                    gfx.DrawString("---", small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center);
                    komsum += rate;
                }

                ypoint += lineheight;
            }


            buf = "Komunalinių mokesčių suma:";

            ypoint += lineheight;

            gfx.DrawRectangle(black, lblue, 40, ypoint, 150, 18);
            gfx.DrawString(buf, normalBold, pblue, new XRect(45, ypoint + 3, 150, 18), XStringFormats.TopLeft);
            gfx.DrawRectangle(black, lblue, 190, ypoint, 60, 18);
            gfx.DrawString(komsum.ToString(), normalBold, XBrushes.Black, new XRect(195, ypoint + 3, 60, 18), XStringFormats.TopLeft);

            ypoint += 18;

            buf = "Visų mokesčių suma:";
            gfx.DrawRectangle(black, lblue, 40, ypoint, 150, 18);
            gfx.DrawString(buf, normalBold, pblue, new XRect(45, ypoint + 3, 150, 18), XStringFormats.TopLeft);
            gfx.DrawRectangle(black, lblue, 190, ypoint, 60, 18);
            gfx.DrawString((komsum + bendrkain.Sum()).ToString(), normalBold, XBrushes.Black, new XRect(195, ypoint + 3, 60, 18), XStringFormats.TopLeft);

            //GALAS

            gfx.DrawRectangle(black, XBrushes.Beige, 306, 95, 50, 20);
            gfx.DrawRectangle(black, lblue, 356, 95, 50, 20);
            gfx.DrawRectangle(black, lblue, 405, 95, 150, 20);



            double nuom = getNuom();

            gfx.DrawString("Nuoma:", normalBoldItalic, XBrushes.Black, new XRect(306, 95, 50, 20), XStringFormats.Center);
            gfx.DrawString(nuom.ToString(), normalBold, XBrushes.Black, new XRect(356, 95, 50, 20), XStringFormats.Center);
            gfx.DrawString("Nuoma + Mokesčiai:" + (nuom + komsum + bendrkain.Sum()).ToString(), normalBold, XBrushes.Black, new XRect(405, 95, 150, 20), XStringFormats.Center);
            conn.Close();



            document.Save(filename);
            Process.Start(filename);
        }
Beispiel #15
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            if (on_off == 1)
            {
                var index = new List <double>(); DA.GetDataList("index", index);
                DA.GetDataTree("element_node_relationship", out GH_Structure <GH_Number> _ij); var ij = _ij.Branches;
                DA.GetDataTree("sectional_force", out GH_Structure <GH_Number> _sec_f);
                DA.GetDataTree("fk", out GH_Structure <GH_Number> _fk); DA.GetDataTree("ft", out GH_Structure <GH_Number> _ft); DA.GetDataTree("fb", out GH_Structure <GH_Number> _fb); DA.GetDataTree("fs", out GH_Structure <GH_Number> _fs);
                List <double> Lambda = new List <double>(); DA.GetDataList("lambda", Lambda);
                List <double> A = new List <double>(); DA.GetDataList("section area", A);
                List <double> Zy = new List <double>(); DA.GetDataList("Section modulus around y-axis", Zy);
                List <double> Zz = new List <double>(); DA.GetDataList("Section modulus around z-axis", Zz);
                var           fk = _fk.Branches[0]; var ft = _ft.Branches[0]; var fb = _fb.Branches[0]; var fs = _fs.Branches[0];
                var           fk2 = _fk.Branches[0]; var ft2 = _ft.Branches[0]; var fb2 = _fb.Branches[0]; var fs2 = _fs.Branches[0];
                if (_sec_f.Branches.Count / ij.Count == 5)
                {
                    fk2 = _fk.Branches[1]; ft2 = _ft.Branches[1]; fb2 = _fb.Branches[1]; fs2 = _fs.Branches[1];
                }
                double alpha = 1.0; DA.GetData("safe factor", ref alpha);
                DA.GetDataTree("kentei_hi", out GH_Structure <GH_Number> _kentei); DA.GetDataTree("kentei_hi(kabe)", out GH_Structure <GH_Number> _kentei2);
                List <string> secname = new List <string>(); DA.GetDataList("secname", secname); var pdfname = "TimberCheck"; DA.GetData("outputname", ref pdfname);
                int Digit(int num)//数字の桁数を求める関数
                {
                    // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。
                    return((num == 0) ? 1 : ((int)Math.Log10(num) + 1));
                }

                XColor RGB(double h, double s, double l)//convert HSL to RGB
                {
                    var max = 0.0; var min = 0.0; var r = 0.0; var g = 0.0; var b = 0.0;

                    if (l < 0.5)
                    {
                        max = l + l * s;
                        min = l - l * s;
                    }
                    else
                    {
                        max = l + (1 - l) * s;
                        min = l - (1 - l) * s;
                    }
                    var HUE_MAX = 360.0; var RGB_MAX = 255;
                    var hp = HUE_MAX / 6.0;  h *= HUE_MAX; var q = h / hp;

                    if (q <= 1)
                    {
                        r = max;
                        g = (h / hp) * (max - min) + min;
                        b = min;
                    }
                    else if (q <= 2)
                    {
                        r = ((hp * 2 - h) / hp) * (max - min) + min;
                        g = max;
                        b = min;
                    }
                    else if (q <= 3)
                    {
                        r = min;
                        g = max;
                        b = ((h - hp * 2) / hp) * (max - min) + min;
                    }
                    else if (q <= 4)
                    {
                        r = min;
                        g = ((hp * 4 - h) / hp) * (max - min) + min;
                        b = max;
                    }
                    else if (q <= 5)
                    {
                        r = ((h - hp * 4) / hp) * (max - min) + min;
                        g = min;
                        b = max;
                    }
                    else
                    {
                        r = max;
                        g = min;
                        b = ((HUE_MAX - h) / hp) * (max - min) + min;
                    }
                    r *= RGB_MAX; g *= RGB_MAX; b *= RGB_MAX;
                    return(XColor.FromArgb((int)r, (int)g, (int)b));
                }

                if (index[0] == -9999)
                {
                    index = new List <double>();
                    for (int e = 0; e < ij.Count; e++)
                    {
                        index.Add(e);
                    }
                }
                // フォントリゾルバーのグローバル登録
                if (PdfCreate.JapaneseFontResolver.fontset == 0)
                {
                    PdfSharp.Fonts.GlobalFontSettings.FontResolver = fontresolver; PdfCreate.JapaneseFontResolver.fontset = 1;
                }
                // PDFドキュメントを作成。
                PdfDocument document = new PdfDocument();
                document.Info.Title  = pdfname;
                document.Info.Author = "Shinnosuke Fujita, Assoc. Prof., The Univ. of Kitakyushu";
                // フォントを作成。
                XFont font = new XFont("Gen Shin Gothic", 9, XFontStyle.Regular);
                XFont fontbold = new XFont("Gen Shin Gothic", 9, XFontStyle.Bold);
                var   pen = XPens.Black;
                var   burnB = new List <double>(); var burnD = new List <double>(); if (!DA.GetDataList("burnB", burnB))
                {
                }
                ; if (!DA.GetDataList("burnD", burnD))
                {
                }
                ;
                var labels = new List <string>
                {
                    "部材番号", "部材断面", "λ", "A[cm2]", "α(低減率)", "Zy[cm3]", "Zz[cm3]", "", "fk[N/mm2]", "ft[N/mm2]", "fb[N/mm2]", "fs[N/mm2]", "", "節点番号", "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定",
                    "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定",
                    "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定",
                    "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定",
                    "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定"
                };
                if (burnB.Count != 0 && burnD.Count != 0)
                {
                    labels = new List <string>
                    {
                        "部材番号", "部材断面", "燃えしろB[mm]", "燃えしろD[mm]", "λ", "A[cm2]", "α(低減率)", "Zy[cm3]", "Zz[cm3]", "", "fk[N/mm2]", "ft[N/mm2]", "fb[N/mm2]", "fs[N/mm2]", "", "節点番号", "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定"
                    };
                }
                var label_width = 75; var offset_x = 25; var offset_y = 25; var pitchy = 13; var text_width = 25; PdfPage page = new PdfPage(); page.Size = PageSize.A4;
                for (int e = 0; e < index.Count; e++)//
                {
                    int ni = (int)ij[e][0].Value; int nj = (int)ij[e][1].Value; int sec = (int)ij[e][3].Value;
                    var ele_text = ((int)index[e]).ToString(); var ni_text = ni.ToString(); var nj_text = nj.ToString();
                    var name_text = secname[sec]; var lambda_text = Lambda[e].ToString("F").Substring(0, Digit((int)Lambda[e]));
                    var A_text = (A[sec] * 1e+4).ToString("F").Substring(0, Digit((int)(A[sec] * 1e+4)));
                    var b = 0.0; var d = 0.0;
                    if (burnB.Count != 0 && burnD.Count != 0)
                    {
                        b = Math.Pow(6 * Math.Pow(Zz[sec], 2) / Zy[sec], 1.0 / 3.0); d = Math.Pow(6 * Math.Pow(Zy[sec], 2) / Zz[sec], 1.0 / 3.0);
                    }
                    if (burnB.Count != 0 && burnD.Count != 0)
                    {
                        A_text = (b * d * 1e+4).ToString("F").Substring(0, Digit((int)(b * d * 1e+4)));
                    }
                    var alpha_text = alpha.ToString("F"); alpha_text = alpha_text.Substring(0, Math.Min(4, alpha_text.Length));
                    var Zy_text    = (Zy[sec] * 1e+6).ToString("F"); Zy_text = Zy_text.Substring(0, Math.Min(Digit((int)(Zy[sec] * 1e+6)), Zy_text.Length));
                    var Zz_text    = (Zz[sec] * 1e+6).ToString("F"); Zz_text = Zz_text.Substring(0, Math.Min(Digit((int)(Zz[sec] * 1e+6)), Zz_text.Length));
                    if (burnB.Count != 0 && burnD.Count != 0)
                    {
                        var zy = b * Math.Pow(d, 2) / 6.0; var zz = d * Math.Pow(b, 2) / 6.0;
                        Zy_text = (zy * 1e+6).ToString("F"); Zy_text = Zy_text.Substring(0, Math.Min(Digit((int)(zy * 1e+6)), Zy_text.Length));
                        Zz_text = (zz * 1e+6).ToString("F"); Zy_text = Zy_text.Substring(0, Math.Min(Digit((int)(zz * 1e+6)), Zy_text.Length));
                    }
                    var fk_text = fk[e].Value.ToString("F"); fk_text = fk_text.Substring(0, Math.Min(5, fk_text.Length)); var fk2_text = "";
                    var ft_text = ft[e].Value.ToString("F"); ft_text = ft_text.Substring(0, Math.Min(5, ft_text.Length)); var ft2_text = "";
                    var fb_text = fb[e].Value.ToString("F"); fb_text = fb_text.Substring(0, Math.Min(5, fb_text.Length)); var fb2_text = "";
                    var fs_text = fs[e].Value.ToString("F"); fs_text = fs_text.Substring(0, Math.Min(5, fs_text.Length)); var fs2_text = "";
                    if (_fk.Branches.Count == 2)
                    {
                        fk2_text = fk2[e].Value.ToString("F"); fk2_text = fk2_text.Substring(0, Math.Min(5, fk2_text.Length));
                    }
                    if (_ft.Branches.Count == 2)
                    {
                        ft2_text = ft2[e].Value.ToString("F"); ft2_text = ft2_text.Substring(0, Math.Min(5, ft2_text.Length));
                    }
                    if (_fb.Branches.Count == 2)
                    {
                        fb2_text = fb2[e].Value.ToString("F"); fb2_text = fb2_text.Substring(0, Math.Min(5, fb2_text.Length));
                    }
                    if (_fs.Branches.Count == 2)
                    {
                        fs2_text = fs2[e].Value.ToString("F"); fs2_text = fs2_text.Substring(0, Math.Min(5, fs2_text.Length));
                    }
                    var sec_f = _sec_f.get_Branch(new GH_Path(new int[] { 0, e }));
                    var Ni_text = double.Parse(sec_f[0].ToString()).ToString("F"); Ni_text = Ni_text.Substring(0, Math.Min(4, Ni_text.Length));
                    var Qyi_text = Math.Abs(double.Parse(sec_f[1].ToString())).ToString("F"); Qyi_text = Qyi_text.Substring(0, Math.Min(4, Qyi_text.Length));
                    var Qzi_text = Math.Abs(double.Parse(sec_f[2].ToString())).ToString("F"); Qzi_text = Qzi_text.Substring(0, Math.Min(4, Qzi_text.Length));
                    var Myi_text = Math.Abs(double.Parse(sec_f[4].ToString())).ToString("F"); Myi_text = Myi_text.Substring(0, Math.Min(4, Myi_text.Length));
                    var Mzi_text = Math.Abs(double.Parse(sec_f[5].ToString())).ToString("F"); Mzi_text = Mzi_text.Substring(0, Math.Min(4, Mzi_text.Length));
                    var Nj_text = (-double.Parse(sec_f[6].ToString())).ToString("F"); Nj_text = Nj_text.Substring(0, Math.Min(4, Nj_text.Length));
                    var Qyj_text = Math.Abs(double.Parse(sec_f[7].ToString())).ToString("F"); Qyj_text = Qyj_text.Substring(0, Math.Min(4, Qyj_text.Length));
                    var Qzj_text = Math.Abs(double.Parse(sec_f[8].ToString())).ToString("F"); Qzj_text = Qzj_text.Substring(0, Math.Min(4, Qzj_text.Length));
                    var Myj_text = Math.Abs(double.Parse(sec_f[10].ToString())).ToString("F"); Myj_text = Myj_text.Substring(0, Math.Min(4, Myj_text.Length));
                    var Mzj_text = Math.Abs(double.Parse(sec_f[11].ToString())).ToString("F"); Mzj_text = Mzj_text.Substring(0, Math.Min(4, Mzj_text.Length));
                    var Nc_text = (double.Parse(sec_f[12].ToString())).ToString("F"); Nc_text = Nc_text.Substring(0, Math.Min(4, Nc_text.Length));
                    var Qyc_text = Math.Abs(double.Parse(sec_f[13].ToString())).ToString("F"); Qyc_text = Qyc_text.Substring(0, Math.Min(4, Qyc_text.Length));
                    var Qzc_text = Math.Abs(double.Parse(sec_f[14].ToString())).ToString("F"); Qzc_text = Qzc_text.Substring(0, Math.Min(4, Qzc_text.Length));
                    var Myc_text = Math.Abs(double.Parse(sec_f[16].ToString())).ToString("F"); Myc_text = Myc_text.Substring(0, Math.Min(4, Myc_text.Length));
                    var Mzc_text = Math.Abs(double.Parse(sec_f[17].ToString())).ToString("F"); Mzc_text = Mzc_text.Substring(0, Math.Min(4, Mzc_text.Length));
                    var klist = _kentei.get_Branch(new GH_Path(new int[] { 0, e }));
                    var Mki_color = new List <XSolidBrush>(); var Mkj_color = new List <XSolidBrush>(); var Mkc_color = new List <XSolidBrush>();
                    var Qki_color = new List <XSolidBrush>(); var Qkj_color = new List <XSolidBrush>(); var Qkc_color = new List <XSolidBrush>();
                    var Mki = (Math.Max(double.Parse(klist[3].ToString()), double.Parse(klist[4].ToString())) + double.Parse(klist[0].ToString()));
                    var Mki_text = Mki.ToString("F").Substring(0, 4); Mki_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mki, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                    var Mkj = (Math.Max(double.Parse(klist[8].ToString()), double.Parse(klist[9].ToString())) + double.Parse(klist[5].ToString()));
                    var Mkj_text = Mkj.ToString("F").Substring(0, 4); Mkj_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mkj, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                    var Mkc = (Math.Max(double.Parse(klist[13].ToString()), double.Parse(klist[14].ToString())) + double.Parse(klist[10].ToString()));
                    var Mkc_text = Mkc.ToString("F").Substring(0, 4); Mkc_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mkc, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                    var Qki = Math.Max(double.Parse(klist[1].ToString()), double.Parse(klist[2].ToString()));
                    var Qki_text = Qki.ToString("F").Substring(0, 4); Qki_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qki, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                    var Qkj = Math.Max(double.Parse(klist[6].ToString()), double.Parse(klist[7].ToString()));
                    var Qkj_text = Qkj.ToString("F").Substring(0, 4); Qkj_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qkj, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                    var Qkc = Math.Max(double.Parse(klist[11].ToString()), double.Parse(klist[12].ToString()));
                    var Qkc_text = Qkc.ToString("F").Substring(0, 4); Qkc_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qkc, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                    var OKi_text = "O.K."; var OKj_text = "O.K."; var OKc_text = "O.K.";
                    if (Mki > 1 || Qki > 1)
                    {
                        OKi_text = "N.G.";
                    }
                    if (Mkj > 1 || Qkj > 1)
                    {
                        OKc_text = "N.G.";
                    }
                    if (Mkc > 1 || Qkc > 1)
                    {
                        OKj_text = "N.G.";
                    }
                    var values = new List <List <string> >();
                    values.Add(new List <string> {
                        ele_text
                    }); values.Add(new List <string> {
                        name_text
                    });
                    if (burnB.Count != 0 && burnD.Count != 0)
                    {
                        values.Add(new List <string> {
                            ((int)(burnB[e] * 1000)).ToString()
                        });
                        values.Add(new List <string> {
                            ((int)(burnD[e] * 1000)).ToString()
                        });
                    }
                    values.Add(new List <string> {
                        lambda_text
                    }); values.Add(new List <string> {
                        A_text
                    }); values.Add(new List <string> {
                        alpha_text
                    });
                    values.Add(new List <string> {
                        Zy_text
                    }); values.Add(new List <string> {
                        Zz_text
                    }); values.Add(new List <string> {
                        "長期", "", "短期"
                    });
                    if (burnB.Count == 0 && burnD.Count == 0)
                    {
                        values.Add(new List <string> {
                            fk_text, "", fk2_text
                        });
                    }
                    else
                    {
                        values.Add(new List <string> {
                            "", "", fk_text
                        });
                    }
                    values.Add(new List <string> {
                        ft_text, "", ft2_text
                    }); values.Add(new List <string> {
                        fb_text, "", fb2_text
                    }); values.Add(new List <string> {
                        fs_text, "", fs2_text
                    });
                    values.Add(new List <string> {
                        "i端", "中央", "j端"
                    }); values.Add(new List <string> {
                        ni_text, "", nj_text
                    });
                    if (burnB.Count == 0 && burnD.Count == 0)
                    {
                        values.Add(new List <string> {
                            "長期検討"
                        });
                    }
                    else
                    {
                        values.Add(new List <string> {
                            "短期検討"
                        });
                    }
                    values.Add(new List <string> {
                        Ni_text, Nc_text, Nj_text
                    }); values.Add(new List <string> {
                        Myi_text, Myc_text, Myj_text
                    }); values.Add(new List <string> {
                        Mzi_text, Mzc_text, Mzj_text
                    });
                    values.Add(new List <string> {
                        Qyi_text, Qyc_text, Qyj_text
                    }); values.Add(new List <string> {
                        Qzi_text, Qzc_text, Qzj_text
                    });
                    values.Add(new List <string> {
                        Mki_text, Mkc_text, Mkj_text
                    }); values.Add(new List <string> {
                        Qki_text, Qkc_text, Qkj_text
                    });
                    values.Add(new List <string> {
                        OKi_text, OKc_text, OKj_text
                    });
                    int N = _sec_f.Branches.Count / ij.Count;
                    if (N == 5)
                    {
                        var text = new List <string> {
                            "短期(L+X)検討", "短期(L+Y)検討", "短期(L-X)検討", "短期(L-Y)検討"
                        };
                        for (int i = 0; i < 4; i++)
                        {
                            values.Add(new List <string> {
                                text[i]
                            });
                            var sec_f1 = _sec_f.get_Branch(new GH_Path(new int[] { i + 1, e }));
                            Ni_text  = (double.Parse(sec_f[0].ToString()) + double.Parse(sec_f1[0].ToString())).ToString("F"); Ni_text = Ni_text.Substring(0, Math.Min(4, Ni_text.Length));
                            Qyi_text = Math.Abs(double.Parse(sec_f[1].ToString()) + double.Parse(sec_f1[1].ToString())).ToString("F"); Qyi_text = Qyi_text.Substring(0, Math.Min(4, Qyi_text.Length));
                            Qzi_text = Math.Abs(double.Parse(sec_f[2].ToString()) + double.Parse(sec_f1[2].ToString())).ToString("F"); Qzi_text = Qzi_text.Substring(0, Math.Min(4, Qzi_text.Length));
                            Myi_text = Math.Abs(double.Parse(sec_f[4].ToString()) + double.Parse(sec_f1[4].ToString())).ToString("F"); Myi_text = Myi_text.Substring(0, Math.Min(4, Myi_text.Length));
                            Mzi_text = Math.Abs(double.Parse(sec_f[5].ToString()) + double.Parse(sec_f1[5].ToString())).ToString("F"); Mzi_text = Mzi_text.Substring(0, Math.Min(4, Mzi_text.Length));
                            Nj_text  = (-double.Parse(sec_f[6].ToString()) - double.Parse(sec_f1[6].ToString())).ToString("F"); Nj_text = Nj_text.Substring(0, Math.Min(4, Nj_text.Length));
                            Qyj_text = Math.Abs(double.Parse(sec_f[7].ToString()) + double.Parse(sec_f1[7].ToString())).ToString("F"); Qyj_text = Qyj_text.Substring(0, Math.Min(4, Qyj_text.Length));
                            Qzj_text = Math.Abs(double.Parse(sec_f[8].ToString()) + double.Parse(sec_f1[8].ToString())).ToString("F"); Qzj_text = Qzj_text.Substring(0, Math.Min(4, Qzj_text.Length));
                            Myj_text = Math.Abs(double.Parse(sec_f[10].ToString()) + double.Parse(sec_f1[10].ToString())).ToString("F"); Myj_text = Myj_text.Substring(0, Math.Min(4, Myj_text.Length));
                            Mzj_text = Math.Abs(double.Parse(sec_f[11].ToString()) + double.Parse(sec_f1[11].ToString())).ToString("F"); Mzj_text = Mzj_text.Substring(0, Math.Min(4, Mzj_text.Length));
                            Nc_text  = (double.Parse(sec_f[12].ToString()) + double.Parse(sec_f1[12].ToString())).ToString("F"); Nc_text = Nc_text.Substring(0, Math.Min(4, Nc_text.Length));
                            Qyc_text = Math.Abs(double.Parse(sec_f[13].ToString()) + double.Parse(sec_f1[13].ToString())).ToString("F"); Qyc_text = Qyc_text.Substring(0, Math.Min(4, Qyc_text.Length));
                            Qzc_text = Math.Abs(double.Parse(sec_f[14].ToString()) + double.Parse(sec_f1[14].ToString())).ToString("F"); Qzc_text = Qzc_text.Substring(0, Math.Min(4, Qzc_text.Length));
                            Myc_text = Math.Abs(double.Parse(sec_f[16].ToString()) + double.Parse(sec_f1[16].ToString())).ToString("F"); Myc_text = Myc_text.Substring(0, Math.Min(4, Myc_text.Length));
                            Mzc_text = Math.Abs(double.Parse(sec_f[17].ToString()) + double.Parse(sec_f1[17].ToString())).ToString("F"); Mzc_text = Mzc_text.Substring(0, Math.Min(4, Mzc_text.Length));
                            klist    = _kentei.get_Branch(new GH_Path(new int[] { i + 1, e }));
                            Mki      = (Math.Max(double.Parse(klist[3].ToString()), double.Parse(klist[4].ToString())) + double.Parse(klist[0].ToString()));
                            Mki_text = Mki.ToString("F").Substring(0, 4); Mki_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mki, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                            Mkj      = (Math.Max(double.Parse(klist[8].ToString()), double.Parse(klist[9].ToString())) + double.Parse(klist[5].ToString()));
                            Mkj_text = Mkj.ToString("F").Substring(0, 4); Mkj_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mkj, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                            Mkc      = (Math.Max(double.Parse(klist[13].ToString()), double.Parse(klist[14].ToString())) + double.Parse(klist[10].ToString()));
                            Mkc_text = Mkc.ToString("F").Substring(0, 4); Mkc_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mkc, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                            Qki      = Math.Max(double.Parse(klist[1].ToString()), double.Parse(klist[2].ToString()));
                            Qki_text = Qki.ToString("F").Substring(0, 4); Qki_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qki, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                            Qkj      = Math.Max(double.Parse(klist[6].ToString()), double.Parse(klist[7].ToString()));
                            Qkj_text = Qkj.ToString("F").Substring(0, 4); Qkj_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qkj, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                            Qkc      = Math.Max(double.Parse(klist[11].ToString()), double.Parse(klist[12].ToString()));
                            Qkc_text = Qkc.ToString("F").Substring(0, 4); Qkc_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qkc, 1.0)) * 1.9 / 3.0, 1, 0.5)));
                            OKi_text = "O.K."; OKj_text = "O.K."; OKc_text = "O.K.";
                            if (Mki > 1 || Qki > 1)
                            {
                                OKi_text = "N.G.";
                            }
                            if (Mkj > 1 || Qkj > 1)
                            {
                                OKc_text = "N.G.";
                            }
                            if (Mkc > 1 || Qkc > 1)
                            {
                                OKj_text = "N.G.";
                            }
                            values.Add(new List <string> {
                                Ni_text, Nc_text, Nj_text
                            }); values.Add(new List <string> {
                                Myi_text, Myc_text, Myj_text
                            }); values.Add(new List <string> {
                                Mzi_text, Mzc_text, Mzj_text
                            });
                            values.Add(new List <string> {
                                Qyi_text, Qyc_text, Qyj_text
                            }); values.Add(new List <string> {
                                Qzi_text, Qzc_text, Qzj_text
                            });
                            values.Add(new List <string> {
                                Mki_text, Mkc_text, Mkj_text
                            }); values.Add(new List <string> {
                                Qki_text, Qkc_text, Qkj_text
                            });
                            values.Add(new List <string> {
                                OKi_text, OKc_text, OKj_text
                            });
                        }
                    }


                    if (e % 6 == 0)
                    {
                        // 空白ページを作成。
                        page = document.AddPage();
                        // 描画するためにXGraphicsオブジェクトを取得。
                        gfx = XGraphics.FromPdfPage(page);
                        for (int i = 0; i < labels.Count; i++)                                                                                     //ラベル列**************************************************************************
                        {
                            gfx.DrawLine(pen, offset_x, offset_y + pitchy * i, offset_x + label_width, offset_y + pitchy * i);                     //横線
                            gfx.DrawLine(pen, offset_x + label_width, offset_y + pitchy * i, offset_x + label_width, offset_y + pitchy * (i + 1)); //縦線
                            gfx.DrawString(labels[i], font, XBrushes.Black, new XRect(offset_x, offset_y + pitchy * i, label_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter);
                            if (i == labels.Count - 1)
                            {
                                i += 1;
                                gfx.DrawLine(pen, offset_x, offset_y + pitchy * i, offset_x + label_width, offset_y + pitchy * i);//横線
                            }
                        }//***********************************************************************************************************************
                    }
                    for (int i = 0; i < values.Count; i++)
                    {
                        var j = e % 6;
                        gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, offset_x + label_width + text_width * 3 * (j + 1), offset_y + pitchy * i); //横線
                        gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * (i + 1)); //縦線
                        if (values[i].Count == 1)
                        {
                            gfx.DrawString(values[i][0], font, XBrushes.Black, new XRect(offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, text_width * 3, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter);
                        }
                        else
                        {
                            var color1 = XBrushes.Black; var color2 = XBrushes.Black; var color3 = XBrushes.Black; var f = font;
                            if (burnB.Count == 0 && burnD.Count == 0)
                            {
                                if (i == 20)
                                {
                                    color1 = Mki_color[0]; color2 = Mkc_color[0]; color3 = Mkj_color[0]; f = fontbold;
                                }
                                else if (i == 21)
                                {
                                    color1 = Qki_color[0]; color2 = Qkc_color[0]; color3 = Qkj_color[0]; f = fontbold;
                                }
                                else if (i == 29)
                                {
                                    color1 = Mki_color[1]; color2 = Mkc_color[1]; color3 = Mkj_color[1]; f = fontbold;
                                }
                                else if (i == 30)
                                {
                                    color1 = Qki_color[1]; color2 = Qkc_color[1]; color3 = Qkj_color[1]; f = fontbold;
                                }
                                else if (i == 38)
                                {
                                    color1 = Mki_color[2]; color2 = Mkc_color[2]; color3 = Mkj_color[2]; f = fontbold;
                                }
                                else if (i == 39)
                                {
                                    color1 = Qki_color[2]; color2 = Qkc_color[2]; color3 = Qkj_color[2]; f = fontbold;
                                }
                                else if (i == 47)
                                {
                                    color1 = Mki_color[3]; color2 = Mkc_color[3]; color3 = Mkj_color[3]; f = fontbold;
                                }
                                else if (i == 48)
                                {
                                    color1 = Qki_color[3]; color2 = Qkc_color[3]; color3 = Qkj_color[3]; f = fontbold;
                                }
                                else if (i == 56)
                                {
                                    color1 = Mki_color[4]; color2 = Mkc_color[4]; color3 = Mkj_color[4]; f = fontbold;
                                }
                                else if (i == 57)
                                {
                                    color1 = Qki_color[4]; color2 = Qkc_color[4]; color3 = Qkj_color[4]; f = fontbold;
                                }
                            }
                            else
                            {
                                if (i == 22)
                                {
                                    color1 = Mki_color[0]; color2 = Mkc_color[0]; color3 = Mkj_color[0]; f = fontbold;
                                }
                                else if (i == 23)
                                {
                                    color1 = Qki_color[0]; color2 = Qkc_color[0]; color3 = Qkj_color[0]; f = fontbold;
                                }
                            }
                            gfx.DrawString(values[i][0], f, color1, new XRect(offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, text_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter);
                            gfx.DrawString(values[i][1], f, color2, new XRect(offset_x + label_width + text_width * 3 * j + text_width, offset_y + pitchy * i, text_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter);
                            gfx.DrawString(values[i][2], f, color3, new XRect(offset_x + label_width + text_width * 3 * j + text_width * 2, offset_y + pitchy * i, text_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter);
                        }
                        if (i == values.Count - 1)
                        {
                            i += 1;
                            gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, offset_x + label_width + text_width * 3 * (j + 1), offset_y + pitchy * i);//横線
                        }
                    }
                }
                var kentei2 = _kentei2.Branches;
                if (kentei2[0][0].Value != -9999)//壁の検定
                {
                    var text_width1 = 10;
                    var widths2     = new int[] { text_width1 * 2, text_width1 * 2, text_width1 * 2, text_width1 * 2, text_width, text_width1 * 3, text_width + text_width1 * 3, text_width + text_width1 * 3, text_width1 * 3, text_width, text_width1 * 3, text_width + text_width1 * 3, text_width + text_width1 * 3, text_width1 * 3, text_width };
                    var widths1     = new int[] { widths2[0] + widths2[1] + widths2[2] + widths2[3], widths2[4], widths2[5] + widths2[6] + widths2[7] + widths2[8] + widths2[9], widths2[10] + widths2[11] + widths2[12] + widths2[13] + widths2[14] };
                    var label1      = new string[] { "節点番号", "壁/床", "X方向荷重時", "Y方向荷重時" };
                    var label2      = new string[] { "i", "j", "k", "l", "倍率", "幅[m]", "許容Qa[kN]", "設計Q[kN]", "Q/Qa", "判定", "幅[m]", "許容Qa[kN]", "設計Q[kN]", "Q/Qa", "判定" };
                    int nline       = 55;
                    for (int e = 0; e < kentei2.Count; e++)
                    {
                        var width1 = 0.0;
                        if (e % nline == 0)
                        {
                            // 空白ページを作成。
                            page = document.AddPage();
                            // 描画するためにXGraphicsオブジェクトを取得。
                            gfx = XGraphics.FromPdfPage(page);
                            //ラベル行**************************************************************************
                            gfx.DrawLine(pen, offset_x, offset_y + pitchy * 0, offset_x + widths1.Sum(), offset_y + pitchy * 0); //横線1
                            gfx.DrawLine(pen, offset_x, offset_y + pitchy * 1, offset_x + widths1.Sum(), offset_y + pitchy * 1); //横線2
                            gfx.DrawLine(pen, offset_x, offset_y + pitchy * 2, offset_x + widths1.Sum(), offset_y + pitchy * 2); //横線2
                            width1 = 0.0;
                            for (int i = 0; i < label1.Length; i++)                                                              //ラベル1行目
                            {
                                gfx.DrawString(label1[i], font, XBrushes.Black, new XRect(offset_x + width1, offset_y + pitchy * 0, widths1[i], offset_y + pitchy * (0 + 1)), XStringFormats.TopCenter);
                                gfx.DrawLine(pen, offset_x + width1, offset_y + pitchy * 0, offset_x + width1, offset_y + pitchy * (0 + 1));//縦線
                                width1 += widths1[i];
                            }
                            gfx.DrawLine(pen, offset_x + width1, offset_y + pitchy * 0, offset_x + width1, offset_y + pitchy * (0 + 1)); //縦線最後尾
                            width1 = 0.0;
                            for (int i = 0; i < label2.Length; i++)                                                                      //ラベル1行目
                            {
                                gfx.DrawString(label2[i], font, XBrushes.Black, new XRect(offset_x + width1, offset_y + pitchy * 1, widths2[i], offset_y + pitchy * (1 + 1)), XStringFormats.TopCenter);
                                gfx.DrawLine(pen, offset_x + width1, offset_y + pitchy * 1, offset_x + width1, offset_y + pitchy * (1 + 1));//縦線
                                width1 += widths2[i];
                            }
                            gfx.DrawLine(pen, offset_x + width1, offset_y + pitchy * 1, offset_x + width1, offset_y + pitchy * (1 + 1));//縦線最後尾
                        }
                        int ii = 8;
                        var ni = kentei2[e][0].Value; var nj = kentei2[e][1].Value; var nk = kentei2[e][2].Value; var nl = kentei2[e][3].Value;
                        var Lx = kentei2[e][ii + 4].Value; var Ly = kentei2[e][ii * 2 + 4].Value; var Qx = kentei2[e][ii + 5].Value; var Qy = kentei2[e][ii * 2 + 5].Value; var Qax = kentei2[e][ii + 6].Value; var Qay = kentei2[e][ii * 2 + 6].Value; var Qx_Qax = kentei2[e][ii + 7].Value; var Qy_Qay = kentei2[e][ii * 2 + 7].Value; var K = Qax / Lx / 1.96; var hanteix = "O.K."; var hanteiy = "O.K.";
                        if (Qx_Qax > 1.0)
                        {
                            hanteix = "N.G.";
                        }
                        if (Qy_Qay > 1.0)
                        {
                            hanteiy = "N.G.";
                        }
                        var color  = new XSolidBrush[] { new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(RGB((1 - Math.Min(Qx_Qax, 1.0)) * 1.9 / 3.0, 1, 0.5)), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(XBrushes.Black), new XSolidBrush(RGB((1 - Math.Min(Qy_Qay, 1.0)) * 1.9 / 3.0, 1, 0.5)), new XSolidBrush(XBrushes.Black) };
                        var values = new string[] { ni.ToString(), nj.ToString(), nk.ToString(), nl.ToString(), Math.Round(K, 4).ToString().Substring(0, Math.Min(Math.Round(K, 4).ToString().Length, 4)), Math.Round(Lx, 5).ToString().Substring(0, Math.Min(Math.Round(Lx, 5).ToString().Length, 5)), Math.Round(Qax, 5).ToString().Substring(0, Math.Min(Math.Round(Qax, 5).ToString().Length, 5)), Math.Round(Qx, 5).ToString().Substring(0, Math.Min(Math.Round(Qx, 5).ToString().Length, 5)), Math.Round(Qx_Qax, 4).ToString().Substring(0, Math.Min(Math.Round(Qx_Qax, 4).ToString().Length, 4)), hanteix, Math.Round(Ly, 5).ToString().Substring(0, Math.Min(Math.Round(Ly, 5).ToString().Length, 5)), Math.Round(Qay, 5).ToString().Substring(0, Math.Min(Math.Round(Qay, 5).ToString().Length, 5)), Math.Round(Qy, 5).ToString().Substring(0, Math.Min(Math.Round(Qy, 5).ToString().Length, 5)), Math.Round(Qy_Qay, 4).ToString().Substring(0, Math.Min(Math.Round(Qy_Qay, 4).ToString().Length, 4)), hanteiy };
                        width1 = 0.0;
                        for (int i = 0; i < values.Length; i++)//3行目以降
                        {
                            gfx.DrawString(values[i], font, color[i], new XRect(offset_x + width1, offset_y + pitchy * (e % nline + 2), widths2[i], offset_y + pitchy * (e % nline + 3)), XStringFormats.TopCenter);
                            gfx.DrawLine(pen, offset_x + width1, offset_y + pitchy * (e % nline + 2), offset_x + width1, offset_y + pitchy * (e % nline + 3));//縦線
                            width1 += widths2[i];
                        }
                        gfx.DrawLine(pen, offset_x + width1, offset_y + pitchy * (e % nline + 2), offset_x + width1, offset_y + pitchy * (e % nline + 3)); //縦線最後尾
                        gfx.DrawLine(pen, offset_x, offset_y + pitchy * (e % nline + 3), offset_x + widths1.Sum(), offset_y + pitchy * (e % nline + 3));   //横線
                    }
                }
                var dir = Path.GetDirectoryName(Rhino.RhinoDoc.ActiveDoc.Path);
                // ドキュメントを保存。
                var filename = dir + "/" + pdfname + ".pdf";
                document.Save(filename);
                // ビューアを起動。
                Process.Start(filename);
            }
        }
Beispiel #16
0
        public void GeneratePdf(List <ChatDay> dates)
        {
            var sampleDateText = dates
                                 .SelectMany(date => date.Lines)
                                 .Select(line => line.Time)
                                 .OrderByDescending(time => time.ToString().Length)
                                 .First()
                                 .ToString();
            var samplePersonText = dates
                                   .SelectMany(date => date.Lines)
                                   .Select(line => line.Person)
                                   .OrderByDescending(person => person.Length)
                                   .First();

            //TODO: Page numbers
            //TODO: Foreword/Dedication/both
            //TODO: Emoji options:

            /*
             * 1. Replace them with ""
             * 2. Replace them with " "
             * 3. Replace them with ?
             * 4. Replace them with any non-printing emoji
             * 5.
             * */
            //TODO: Lines that don't wrap (no linebreaks)
            //TODO: Add book title to header on non-chapter pages?
            //TODO: Cover
            //TODO: Jacket

            var brushesByTextType = new Dictionary <TextType, XSolidBrush>
            {
                { TextType.EzraChat, new XSolidBrush(XColor.FromArgb(Color.FromArgb(40, 150, 40).ToArgb())) },
                { TextType.EzraPersonal, new XSolidBrush(XColor.FromArgb(Color.FromArgb(40, 150, 40).ToArgb())) },
                { TextType.FunnyChat, new XSolidBrush(XColor.FromArgb(Color.FromArgb(138, 43, 226).ToArgb())) },
                { TextType.MusicAndLinkChat, new XSolidBrush(XColor.FromArgb(Color.FromArgb(0, 0, 255).ToArgb())) },
                { TextType.RomanticChat, new XSolidBrush(XColor.FromArgb(Color.FromArgb(205, 51, 51).ToArgb())) },
                { TextType.SarahChat, new XSolidBrush(XColor.FromArgb(Color.FromArgb(0, 150, 150).ToArgb())) },
                { TextType.SarahPersonal, new XSolidBrush(XColor.FromArgb(Color.FromArgb(0, 150, 150).ToArgb())) },
            };
            var boldChatTypes = new[]
            {
                TextType.EzraPersonal,
                TextType.SarahPersonal,
                TextType.FunnyChat,
                TextType.RomanticChat
            };

            var options         = new XPdfFontOptions(PdfFontEncoding.Unicode);
            var pdfDocument     = new PdfDocument();
            var headerFont      = new XFont("Garamond", 30, XFontStyle.Bold);
            var blackBrush      = new XSolidBrush(XColor.FromArgb(Color.Black.ToArgb()));
            var textFont        = new XFont("Segoe UI Symbol", 12, XFontStyle.Regular, options);
            var borderDemoBrush = new XSolidBrush(XColor.FromArgb(Color.FromArgb(240, 240, 240).ToArgb()));
            var boldTextFont    = new XFont("Segoe UI Symbol", 12, XFontStyle.Bold, options);

            foreach (var chatDay in dates)
            {
                var page      = CreatePage(pdfDocument);
                var xGraphics = XGraphics.FromPdfPage(page);
                xGraphics.DrawRectangle(borderDemoBrush, new XRect(0, 0, page.Width, page.Height));
                var textFormatter = new XTextFormatterEx2(xGraphics);

                var chatDayDate     = chatDay.Date.ToLongDateString();
                var headerSize      = xGraphics.MeasureString(chatDayDate, headerFont);
                var headerX         = (page.Width / 2) - (headerSize.Width / 2);
                var headerRectangle = new XRect(headerX, VerticalHeaderPadding, headerSize.Width, headerSize.Height);
                textFormatter.DrawString(chatDayDate, headerFont, blackBrush, headerRectangle);

                var mainSectionTop    = headerRectangle.Bottom + VerticalHeaderPadding;
                var mainSectionHeight = page.Height - (headerRectangle.Height + VerticalHeaderPadding + VerticalHeaderPadding + PageVerticalPadding);
                var pageLayout        = new PdfSharpPageLayout(xGraphics);
                pageLayout.InitializeBasePageLayout(mainSectionTop, mainSectionHeight, textFont, sampleDateText, samplePersonText, page.Width);

                var nextTop = pageLayout.TextColumn.Top;
                foreach (var nextChatLine in chatDay.Lines)
                {
                    var    remainingHeight         = pageLayout.TextColumn.Bottom - (nextTop + LinePadding);
                    var    newPage                 = false;
                    double neededHeightForChatText = 0;
                    if (remainingHeight <= 0)
                    {
                        newPage = true;
                    }
                    else
                    {
                        neededHeightForChatText = GetNeededHeightForChatText(pageLayout, nextTop, textFormatter, nextChatLine, textFont);
                        if (neededHeightForChatText <= 0 || neededHeightForChatText > remainingHeight)
                        {
                            newPage = true;
                        }
                    }
                    if (newPage)
                    {
                        page      = CreatePage(pdfDocument);
                        xGraphics = XGraphics.FromPdfPage(page);
                        xGraphics.DrawRectangle(borderDemoBrush, new XRect(0, 0, page.Width, page.Height));
                        textFormatter     = new XTextFormatterEx2(xGraphics);
                        mainSectionTop    = PageVerticalPadding;
                        mainSectionHeight = page.Height - 2 * PageVerticalPadding;

                        pageLayout = new PdfSharpPageLayout(xGraphics);
                        pageLayout.InitializeBasePageLayout(mainSectionTop, mainSectionHeight, textFont, sampleDateText, samplePersonText, page.Width);
                        nextTop = pageLayout.DateColumn.Top;
                        neededHeightForChatText = GetNeededHeightForChatText(pageLayout, nextTop, textFormatter, nextChatLine, textFont);
                    }
                    var textRect   = new XRect(pageLayout.TextColumn.Left, nextTop, pageLayout.TextColumn.Width, neededHeightForChatText);
                    var dateRect   = new XRect(pageLayout.DateColumn.Left, nextTop, pageLayout.DateColumn.Width, neededHeightForChatText);
                    var personRect = new XRect(pageLayout.PersonColumn.Left, nextTop, pageLayout.PersonColumn.Width, neededHeightForChatText);

                    var font = boldChatTypes.Contains(nextChatLine.TextType) ? boldTextFont : textFont;
                    textFormatter.DrawString(nextChatLine.Time.ToString(), textFont, brushesByTextType[nextChatLine.TextType], dateRect);
                    textFormatter.DrawString(nextChatLine.Person, textFont, brushesByTextType[nextChatLine.TextType], personRect);
                    textFormatter.DrawString(nextChatLine.Text, font, brushesByTextType[nextChatLine.TextType], textRect, XStringFormats.TopLeft);
                    nextTop += neededHeightForChatText + LinePadding;
                }
            }

            pdfDocument.Save($@"C:\Users\Ezramc\Desktop\Starfire\pdf\output{DateTime.Now.ToFileTime()}.pdf");
        }
Beispiel #17
0
        /// <summary>
        /// Draws the marker given through rendererInfo at the specified position. Position specifies
        /// the center of the marker.
        /// </summary>
        internal static void Draw(XGraphics graphics, XPoint pos, MarkerRendererInfo rendererInfo)
        {
#if SILVERLIGHT
            return; // BUG: Code crashs Silverlight Path class.

#pragma warning disable 0162
#endif

            if (rendererInfo.MarkerStyle == MarkerStyle.None)
            {
                return;
            }

            double size = rendererInfo.MarkerSize;
            double size2 = size / 2;
            double x0, y0, x1, y1;
            double g;

            XPen   foreground = new XPen(rendererInfo.MarkerForegroundColor, 0.5);
            XBrush background = new XSolidBrush(rendererInfo.MarkerBackgroundColor);

            XGraphicsPath gp = new XGraphicsPath();
            switch (rendererInfo.MarkerStyle)
            {
            case MarkerStyle.Square:
                x0 = pos.X - size2;
                y0 = pos.Y - size2;
                x1 = pos.X + size2;
                y1 = pos.Y + size2;
                gp.AddLine(x0, y0, x1, y0);
                gp.AddLine(x1, y0, x1, y1);
                gp.AddLine(x1, y1, x0, y1);
                gp.AddLine(x0, y1, x0, y0);
                break;

            case MarkerStyle.Diamond:
                gp.AddLine(x1                   = pos.X + size2, pos.Y, pos.X, y0 = pos.Y - size2);
                gp.AddLine(pos.X, y0, x0        = pos.X - size2, pos.Y);
                gp.AddLine(x0, pos.Y, pos.X, y1 = pos.Y + size2);
                gp.AddLine(pos.X, y1, x1, pos.Y);
                break;

            case MarkerStyle.Triangle:
                y0 = pos.Y + size / 2;
                y1 = pos.Y - size / 2;
                g  = Math.Sqrt(size * size * 4 / 3) / 2;
                gp.AddLine(pos.X, y1, pos.X + g, y0);
                gp.AddLine(pos.X + g, y0, pos.X - g, y0);
                gp.AddLine(pos.X - g, y0, pos.X, y1);
                break;

            case MarkerStyle.Plus:
                g = size2 / 4;
                gp.AddLine(pos.X - size2, pos.Y + g, pos.X - g, pos.Y + g);
                gp.AddLine(pos.X - g, pos.Y + g, pos.X - g, pos.Y + size2);
                gp.AddLine(pos.X - g, pos.Y + size2, pos.X + g, pos.Y + size2);
                gp.AddLine(pos.X + g, pos.Y + size2, pos.X + g, pos.Y + g);
                gp.AddLine(pos.X + g, pos.Y + g, pos.X + size2, pos.Y + g);
                gp.AddLine(pos.X + size2, pos.Y + g, pos.X + size2, pos.Y - g);
                gp.AddLine(pos.X + size2, pos.Y - g, pos.X + g, pos.Y - g);
                gp.AddLine(pos.X + g, pos.Y - g, pos.X + g, pos.Y - size2);
                gp.AddLine(pos.X + g, pos.Y - size2, pos.X - g, pos.Y - size2);
                gp.AddLine(pos.X - g, pos.Y - size2, pos.X - g, pos.Y - g);
                gp.AddLine(pos.X - g, pos.Y - g, pos.X - size2, pos.Y - g);
                gp.AddLine(pos.X - size2, pos.Y - g, pos.X - size2, pos.Y + g);
                break;

            case MarkerStyle.Circle:
            case MarkerStyle.Dot:
                x0 = pos.X - size2;
                y0 = pos.Y - size2;
                gp.AddEllipse(x0, y0, size, size);
                break;

            case MarkerStyle.Dash:
                x0 = pos.X - size2;
                y0 = pos.Y - size2 / 3;
                x1 = pos.X + size2;
                y1 = pos.Y + size2 / 3;
                gp.AddLine(x0, y0, x1, y0);
                gp.AddLine(x1, y0, x1, y1);
                gp.AddLine(x1, y1, x0, y1);
                gp.AddLine(x0, y1, x0, y0);
                break;

            case MarkerStyle.X:
                g = size / 4;
                gp.AddLine(pos.X - size2 + g, pos.Y - size2, pos.X, pos.Y - g);
                gp.AddLine(pos.X, pos.Y - g, pos.X + size2 - g, pos.Y - size2);
                gp.AddLine(pos.X + size2 - g, pos.Y - size2, pos.X + size2, pos.Y - size2 + g);
                gp.AddLine(pos.X + size2, pos.Y - size2 + g, pos.X + g, pos.Y);
                gp.AddLine(pos.X + g, pos.Y, pos.X + size2, pos.Y + size2 - g);
                gp.AddLine(pos.X + size2, pos.Y + size2 - g, pos.X + size2 - g, pos.Y + size2);
                gp.AddLine(pos.X + size2 - g, pos.Y + size2, pos.X, pos.Y + g);
                gp.AddLine(pos.X, pos.Y + g, pos.X - size2 + g, pos.Y + size2);
                gp.AddLine(pos.X - size2 + g, pos.Y + size2, pos.X - size2, pos.Y + size2 - g);
                gp.AddLine(pos.X - size2, pos.Y + size2 - g, pos.X - g, pos.Y);
                gp.AddLine(pos.X - g, pos.Y, pos.X - size2, pos.Y - size2 + g);
                break;

            case MarkerStyle.Star:
            {
                XPoint[] points = new XPoint[10];

                double radStep     = 2 * Math.PI / 5;
                double outerCircle = size / 2;
                double innerCircle = size / 5;
                // outer circle
                double rad = -(Math.PI / 2);         // 90�
                for (int idx = 0; idx < 10; idx += 2)
                {
                    points[idx].X = pos.X + outerCircle * Math.Cos(rad);
                    points[idx].Y = pos.Y + outerCircle * Math.Sin(rad);
                    rad          += radStep;
                }

                // inner circle
                rad = -(Math.PI / 4);         // 45�
                double x = innerCircle * Math.Cos(rad);
                double y = innerCircle * Math.Sin(rad);
                points[1].X = pos.X + x;
                points[1].Y = pos.Y + y;
                points[9].X = pos.X - x;
                points[9].Y = pos.Y + y;
                rad        += radStep;
                x           = innerCircle * Math.Cos(rad);
                y           = innerCircle * Math.Sin(rad);
                points[3].X = pos.X + x;
                points[3].Y = pos.Y + y;
                points[7].X = pos.X - x;
                points[7].Y = pos.Y + y;
                rad        += radStep;
                y           = innerCircle * Math.Sin(rad);
                points[5].X = pos.X;
                points[5].Y = pos.Y + y;
                gp.AddLines(points);
            }
            break;
            }

            gp.CloseFigure();
            if (rendererInfo.MarkerStyle != MarkerStyle.Dot)
            {
                graphics.DrawPath(background, gp);
                graphics.DrawPath(foreground, gp);
            }
        }
Beispiel #18
0
        private static void drawBreakdownGraph(XGraphics gfx, double x, double y, double width, double height, Session session)
        {
            XPen   penBlack   = new XPen(XColor.FromKnownColor(XKnownColor.Black), 0.5);
            XBrush brushBlack = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black));

            gfx.DrawRectangle(penBlack, x, y, width, height);
            Font f1 = new Font("Arial", 8, GraphicsUnit.World);
            Font f2 = new Font("Arial", 5, GraphicsUnit.World);

            List <int> breakdown = new List <int> {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };

            foreach (Shot s in session.Shots)
            {
                if (s.score == 10)
                {
                    if (s.innerTen)
                    {
                        breakdown[11]++;
                    }
                    else
                    {
                        breakdown[s.score]++;
                    }
                }
                else
                {
                    breakdown[s.score]++;
                }
            }

            int bigest = -100;

            double offset = x + 7;

            for (int i = breakdown.Count - 1; i >= 0; i--)
            {
                int c = breakdown[i];
                if (c > bigest)
                {
                    bigest = c;
                }
                XPoint point = new XPoint(offset, y + height - 10);
                string cs    = c.ToString();
                if (c == 0)
                {
                    cs = "-";
                }

                gfx.DrawString(cs, f1, brushBlack, point);


                XPoint point2 = new XPoint(offset + 1, y + height - 3);
                cs = i.ToString();
                if (i == 11)
                {
                    cs = "X";
                }
                gfx.DrawString(cs, f2, brushBlack, point2);

                offset += width / 12;
            }

            double tallest = height - 30;

            offset = x + 7;
            for (int i = breakdown.Count - 1; i >= 0; i--)
            {
                int    c = breakdown[i];
                double h = (c * tallest) / bigest;
                gfx.DrawRectangle(brushBlack, new XRect(new XPoint(offset - 2, y + height - 25), new XPoint(offset + 8, y + height - 25 - h)));
                offset += width / 12;
            }
        }
    // --------------------------------------------------------------------------------------------

    #region  Drawing

    //void SetPageLayout(down, point(0, 0), unit

    // ----- Clear --------------------------------------------------------------------------------

    public void Clear(XColor color)
    {
      if (!this.gfx.transform.IsIdentity)
        throw new NotImplementedException("Transform must be identity to clear the canvas.");

      // TODO: this is implementation is bogus. Reset transformation to identity an then fill
      XBrush brush = new XSolidBrush(color);
      DrawRectangle(null, brush, 0, 0, Size.Width, Size.Height);
    }
Beispiel #20
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";
            var          file     = Path.Combine(Directory.GetCurrentDirectory(), filename);

            File.Copy(Path.Combine("../../../../assets/PDFs/", filename), file, true);

            // Remove ReadOnly attribute from the copy.
            File.SetAttributes(file, File.GetAttributes(file) & ~FileAttributes.ReadOnly);

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

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

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

            for (var idx = 0; idx < document.Pages.Count; idx++)
            {
                var page = document.Pages[idx];

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

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

                    // Get the size (in points) of the text.
                    var 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.
                    var 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 a watermark as an outlined graphical path.
                    // NYI: Does not work in Core build.

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

                    // Get the size (in points) of the text.
                    var 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.
                    var path = new XGraphicsPath();

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

                    // Add the text to the path.
                    // AddString is not implemented in PDFsharp Core.
                    path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   format);

                    // Create a dimmed red pen.
                    var 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 a watermark as a transparent graphical path above text.
                    // NYI: Does not work in Core build.

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

                    // Get the size (in points) of the text.
                    var 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.
                    var path = new XGraphicsPath();

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

                    // Add the text to the path.
                    // AddString is not implemented in PDFsharp Core.
                    path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   format);

                    // Create a dimmed red pen and brush.
                    var    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);
        }
Beispiel #21
0
        private void btn_pdf_Click(object sender, EventArgs e)
        {
            PdfDocument doc = new PdfDocument();

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


            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();
            XGraphics   gfx      = XGraphics.FromPdfPage(page);
            XFont       font     = new XFont("Times New Roman", 8, XFontStyle.Bold);
            XPen        pen      = new XPen(XColors.Black, 0.8);

            gfx.DrawRectangle(pen, 75, 70, 150, 65);
            gfx.DrawRectangle(pen, 400, 70, 125, 65);

            gfx.DrawString("Lycée Pasteur Mont Roland", font, XBrushes.Black, 100, 80);
            gfx.DrawString("Enseignement Supérieur", font, XBrushes.Black, 107, 90);
            font = new XFont("Times New Roman", 8, XFontStyle.Regular);
            gfx.DrawString("9 avenue Rockefeller", font, XBrushes.Black, 117, 100);
            gfx.DrawString("BP 24", font, XBrushes.Black, 139, 110);
            gfx.DrawString("39107 Dole Cedex", font, XBrushes.Black, 120, 120);
            gfx.DrawString("03 84 79 75 00", font, XBrushes.Black, 127, 130);
            gfx.DrawString("En partenariat avec :", font, XBrushes.Black, 429, 80);
            font = new XFont("Times New Roman", 8, XFontStyle.Bold);
            gfx.DrawString("CFA ASPECT", font, XBrushes.Black, 438, 100);
            font = new XFont("Times New Roman", 8, XFontStyle.Regular);
            gfx.DrawString("20 rue Megevand", font, XBrushes.Black, 435, 110);
            gfx.DrawString("25041 Besançon", font, XBrushes.Black, 436, 120);
            gfx.DrawString("03 81 25 03 75", font, XBrushes.Black, 439, 130);
            gfx.DrawImage(XImage.FromFile("lpmr.png"), 230, 75, 80, 50);
            gfx.DrawImage(XImage.FromFile("aspect.jpg"), 318, 75, 80, 50);
            font = new XFont("Times New Roman", 10, XFontStyle.Bold);
            gfx.DrawString("RELEVE DE NOTES - Promotion 2019 2021 - Première année", font, XBrushes.Black, 184, 160);
            gfx.DrawString("Administrateur de Systèmes d'Information", font, XBrushes.Black, 222, 180);
            font = new XFont("Times New Roman", 8, XFontStyle.Bold);
            gfx.DrawString("TITRE RNCP de Niveau 6 - N° de certification 26E32601 - Code NSF 326 n", font, XBrushes.Black, 186, 195);

            font = new XFont("Times New Roman", 8, XFontStyle.Regular);
            gfx.DrawString("Nom de l'apprenti : DIZIERE Emma", font, XBrushes.Black, 90, 220);
            pen = new XPen(XColors.Black, 1);
            XBrush brush = new XSolidBrush(XColor.FromArgb(240, 240, 240));

            gfx.DrawRectangle(pen, brush, 50, 225, 450, 15);
            font = new XFont("Times New Roman", 8, XFontStyle.Bold);
            gfx.DrawString("Envaluation au sein du centre de formation ", font, XBrushes.Black, 228, 235);
            pen  = new XPen(XColors.Black, 0.8);
            font = new XFont("Times New Roman", 8, XFontStyle.Regular);
            gfx.DrawRectangle(pen, 50, 240, 105, 20);

            gfx.DrawString("Matières ", font, XBrushes.Black, 60, 252);
            gfx.DrawRectangle(pen, 155, 240, 180, 10);

            gfx.DrawString("Moyennes sur 20", font, XBrushes.Black, 222, 248);

            gfx.DrawString("Coef", font, XBrushes.Black, 164, 258);
            gfx.DrawRectangle(pen, 191, 250, 36, 10);
            gfx.DrawString("Ctrl Cont", font, XBrushes.Black, 194, 258);
            gfx.DrawRectangle(pen, 227, 250, 36, 10);
            gfx.DrawString("Examen", font, XBrushes.Black, 232, 258);
            gfx.DrawRectangle(pen, 263, 250, 36, 10);
            gfx.DrawString("Total", font, XBrushes.Black, 272, 258);
            gfx.DrawRectangle(pen, 299, 250, 36, 10);
            gfx.DrawString("Classe", font, XBrushes.Black, 307, 258);
            gfx.DrawRectangle(pen, 335, 240, 165, 20);
            gfx.DrawString("Notes sur 20", font, XBrushes.Black, 395, 255);

            gfx.DrawString("1", font, XBrushes.Black, 164, 268);
            gfx.DrawRectangle(pen, 155, 260, 180, 10);
            gfx.DrawRectangle(pen, 155, 260, 36, 10);
            gfx.DrawRectangle(pen, 227, 260, 36, 10);
            gfx.DrawRectangle(pen, 263, 260, 36, 10);
            gfx.DrawString("Anglais Professionel ", font, XBrushes.Black, 55, 268);
            gfx.DrawRectangle(pen, 50, 260, 450, 10);

            gfx.DrawString("1", font, XBrushes.Black, 164, 278);
            gfx.DrawRectangle(pen, 155, 270, 180, 10);
            gfx.DrawRectangle(pen, 155, 270, 36, 10);
            gfx.DrawRectangle(pen, 227, 270, 36, 10);
            gfx.DrawRectangle(pen, 263, 270, 36, 10);
            gfx.DrawString("Outil mathématique", font, XBrushes.Black, 55, 278);
            gfx.DrawRectangle(pen, 50, 270, 450, 10);

            gfx.DrawString("1", font, XBrushes.Black, 164, 288);
            gfx.DrawRectangle(pen, 155, 280, 180, 10);
            gfx.DrawRectangle(pen, 155, 280, 36, 10);
            gfx.DrawRectangle(pen, 227, 280, 36, 10);
            gfx.DrawRectangle(pen, 263, 280, 36, 10);
            gfx.DrawString("Droit informatique ", font, XBrushes.Black, 55, 288);
            gfx.DrawRectangle(pen, 50, 280, 450, 10);

            gfx.DrawString("2", font, XBrushes.Black, 164, 298);
            gfx.DrawRectangle(pen, 155, 290, 180, 10);
            gfx.DrawRectangle(pen, 155, 290, 36, 10);
            gfx.DrawRectangle(pen, 227, 290, 36, 10);
            gfx.DrawRectangle(pen, 263, 290, 36, 10);
            gfx.DrawString("Management Budgetisation", font, XBrushes.Black, 55, 298);
            gfx.DrawRectangle(pen, 50, 290, 450, 10);
            gfx.DrawString("Evalué en première année ", font, XBrushes.Black, 370, 298);

            gfx.DrawString("3", font, XBrushes.Black, 164, 308);
            gfx.DrawRectangle(pen, 155, 300, 180, 10);
            gfx.DrawRectangle(pen, 155, 300, 36, 10);
            gfx.DrawRectangle(pen, 227, 300, 36, 10);
            gfx.DrawRectangle(pen, 263, 300, 36, 10);
            gfx.DrawString("Génie Logiciel ", font, XBrushes.Black, 55, 308);
            gfx.DrawRectangle(pen, 50, 300, 450, 10);

            gfx.DrawString("3", font, XBrushes.Black, 164, 318);
            gfx.DrawRectangle(pen, 155, 310, 180, 10);
            gfx.DrawRectangle(pen, 155, 310, 36, 10);
            gfx.DrawRectangle(pen, 227, 310, 36, 10);
            gfx.DrawRectangle(pen, 263, 310, 36, 10);
            gfx.DrawString("Réseaux, Systèmes et Sécurité ", font, XBrushes.Black, 55, 318);
            gfx.DrawRectangle(pen, 50, 310, 450, 10);

            gfx.DrawString("1", font, XBrushes.Black, 164, 328);
            gfx.DrawRectangle(pen, 155, 320, 180, 10);
            gfx.DrawRectangle(pen, 155, 320, 36, 10);
            gfx.DrawRectangle(pen, 227, 320, 36, 10);
            gfx.DrawRectangle(pen, 263, 320, 36, 10);
            gfx.DrawString("BD ", font, XBrushes.Black, 55, 328);
            gfx.DrawRectangle(pen, 50, 320, 450, 10);
            gfx.DrawString("Evalué en projet tutoré", font, XBrushes.Black, 370, 328);

            gfx.DrawString("3", font, XBrushes.Black, 164, 338);
            gfx.DrawRectangle(pen, 155, 330, 180, 10);
            gfx.DrawRectangle(pen, 155, 330, 36, 10);
            gfx.DrawRectangle(pen, 227, 330, 36, 10);
            gfx.DrawRectangle(pen, 263, 330, 36, 10);
            gfx.DrawString("Conduite de Projet ", font, XBrushes.Black, 55, 338);
            gfx.DrawRectangle(pen, 50, 330, 450, 10);
            gfx.DrawString("Evalué en première année ", font, XBrushes.Black, 370, 338);

            gfx.DrawString("3", font, XBrushes.Black, 164, 348);
            gfx.DrawRectangle(pen, 155, 340, 180, 10);
            gfx.DrawRectangle(pen, 155, 340, 36, 10);
            gfx.DrawRectangle(pen, 227, 340, 36, 10);
            gfx.DrawRectangle(pen, 263, 340, 36, 10);
            gfx.DrawString("Projet Tutoré ", font, XBrushes.Black, 55, 348);
            gfx.DrawRectangle(pen, 50, 340, 450, 10);
            gfx.DrawString("Evalué en projet tutoré ", font, XBrushes.Black, 370, 348);


            gfx.DrawString("Moyenne", font, XBrushes.Black, 164, 358);
            gfx.DrawRectangle(pen, 50, 350, 450, 10);
            gfx.DrawRectangle(pen, 263, 350, 36, 10);
            gfx.DrawRectangle(pen, 299, 350, 36, 10);
            gfx.DrawString("Moyenne informatique ", font, XBrushes.Black, 360, 358);
            gfx.DrawRectangle(pen, 450, 350, 50, 10);

            font = new XFont("Times New Roman", 8, XFontStyle.Bold);
            gfx.DrawString("Evaluation en entreprise", font, XBrushes.Black, 228, 378);
            pen  = new XPen(XColors.Black, 0.8);
            font = new XFont("Times New Roman", 8, XFontStyle.Regular);
            gfx.DrawRectangle(pen, 50, 370, 450, 10);
            gfx.DrawString("Livret de Suivi", font, XBrushes.Black, 80, 388);
            gfx.DrawString("12", font, XBrushes.Black, 164, 388);
            gfx.DrawRectangle(pen, 50, 380, 450, 10);
            gfx.DrawRectangle(pen, 155, 380, 180, 10);
            gfx.DrawRectangle(pen, 155, 380, 36, 10);
            gfx.DrawRectangle(pen, 263, 380, 36, 10);

            gfx.DrawString("Projet Entreprise", font, XBrushes.Black, 80, 398);
            gfx.DrawRectangle(pen, 50, 390, 450, 10);
            gfx.DrawRectangle(pen, 155, 390, 180, 10);
            gfx.DrawRectangle(pen, 155, 390, 36, 10);
            gfx.DrawRectangle(pen, 263, 390, 36, 10);

            gfx.DrawString("Moyenne", font, XBrushes.Black, 164, 408);
            gfx.DrawRectangle(pen, 50, 400, 450, 10);
            gfx.DrawRectangle(pen, 263, 400, 36, 10);
            gfx.DrawRectangle(pen, 299, 400, 36, 10);

            font = new XFont("Times New Roman", 8, XFontStyle.Bold);
            gfx.DrawString("Appréciation du conseil de promotion et du responsable de dispositif", font, XBrushes.Black, 198, 428);
            pen  = new XPen(XColors.Black, 0.8);
            font = new XFont("Times New Roman", 8, XFontStyle.Regular);
            gfx.DrawRectangle(pen, 50, 420, 450, 10);
            gfx.DrawRectangle(pen, 50, 430, 450, 100);


            gfx.DrawString("Rappel Moyenne année 1", font, XBrushes.Black, 134, 448);
            gfx.DrawRectangle(pen, 284, 440, 30, 10);

            gfx.DrawString("Moyenne année 2 1er semestre", font, XBrushes.Black, 134, 458);
            gfx.DrawRectangle(pen, 284, 450, 30, 10);

            gfx.DrawString("A Dole le 10 mars 2021 ", font, XBrushes.Black, 290, 470);
            gfx.DrawString("Le responsable de dispositif : Julian COURBEZ", font, XBrushes.Black, 290, 480);


            const string filename = "Bulletin-notes-2annee.pdf";

            document.Save(filename);

            Process.Start(filename);
        }
Beispiel #22
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);
        }
Beispiel #23
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);
        }
        public override void RenderPage(XGraphics gfx)
        {
#if true_
            // Create a new PDF document
            //PdfDocument document = new PdfDocument();

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

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

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

            // Create an empty XForm object with the specified width and height
            // A form is bound to its target document when it is created. The reason is that the form can
            // share fonts and other objects with its target document.
            XForm form = new XForm(gfx, XUnit.FromMillimeter(70), XUnit.FromMillimeter(55));

            // Create an XGraphics object for drawing the contents of the form.
            XGraphics formGfx = XGraphics.FromForm(form);

            // Draw a large transparent rectangle to visualize the area the form occupies
            XColor back = XColors.Orange;
            back.A = 0.2;
            XSolidBrush brush = new XSolidBrush(back);
            formGfx.DrawRectangle(brush, -10000, -10000, 20000, 20000);


            // On a form you can draw...

            //// ... text
            //formGfx.DrawString("Text, Graphics, Images, and Forms", new XFont("Verdana", 10, XFontStyle.Regular), XBrushes.Navy, 3, 0, XStringFormat.TopLeft);
            //XPen pen = XPens.LightBlue.Clone();
            //pen.Width = 2.5;

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

            //// ... raster images like GIF files
            //XGraphicsState state = formGfx.Save();
            //formGfx.RotateAtTransform(17, new XPoint(30, 30));
            //formGfx.DrawImage(XImage.FromFile("../../../../XGraphicsLab/images/Test.gif"), 20, 20);
            //formGfx.Restore(state);

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

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


            // Step 2: Draw the XPdfForm on your PDF page like an image

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

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

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

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

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

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

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

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

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

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

            gfx.DrawImage(form, (dx - form.Width) / 2, (dy - form.Height) / 2, form.Width, form.Height);
#endif
#endif
        }
Beispiel #25
0
        private void createDocument()
        {
            PdfDocument   document    = new PdfDocument();
            PdfPage       page        = document.AddPage();
            double        pointsPermm = page.Height / page.Height.Millimeter;
            XGraphics     gfx         = XGraphics.FromPdfPage(page);
            XFont         Times11     = new XFont("Times New Roman", 11);
            XFont         Times11Bold = new XFont("Times New Roman", 11, XFontStyle.Bold);
            XFont         Times9      = new XFont("Times New Roman", 9);
            XStringFormat left        = new XStringFormat();

            left.Alignment = XStringAlignment.Near;
            XStringFormat right = new XStringFormat();

            right.Alignment = XStringAlignment.Far;
            XStringFormat center = new XStringFormat();

            center.Alignment = XStringAlignment.Center;

            byte[] data;
            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("FolkBok.Images.FolkLogo.png"))
            {
                int count = (int)stream.Length;
                data = new byte[count];
                stream.Read(data, 0, count);
            }
            MemoryStream mstream = new MemoryStream(data);
            BitmapImage  image   = new BitmapImage();

            image.BeginInit();
            image.StreamSource = mstream;
            image.EndInit();
            double topLeftX = 14.5 * pointsPermm;
            double topLeftY = 20.5 * pointsPermm;
            double height   = 29.55 * pointsPermm;
            double width    = 71.67 * pointsPermm;

            gfx.DrawImage(XImage.FromBitmapSource(image), topLeftX, topLeftY, width, height);

            width = 181.74 * pointsPermm;
            gfx.DrawString("Faktura", new XFont("Times New Roman", 24), XBrushes.Black, topLeftX + width, 27.63 * pointsPermm, right);

            topLeftY = 54.84 * pointsPermm - 1;
            height   = 5.67 * pointsPermm + 1;
            width    = 88.16 * pointsPermm;
            gfx.DrawRectangle(XBrushes.Black, topLeftX, topLeftY, width, height);
            System.Windows.Point lp = new System.Windows.Point(16.5 * pointsPermm, topLeftY);
            System.Windows.Point rp = new System.Windows.Point(16.5 * pointsPermm + width / 2, topLeftY);
            gfx.DrawString("Belopp", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.White, lp, left);
            gfx.DrawString(getAmountString(invoice.Sum), new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.White, rp, left);

            topLeftY += height;
            height    = 31.25 * pointsPermm;
            gfx.DrawRectangle(XBrushes.Gainsboro, topLeftX, topLeftY, width, height);
            lp.Y = topLeftY;
            rp.Y = topLeftY;
            gfx.DrawString("Fakturanummer", Times11, XBrushes.Black, lp, left);
            gfx.DrawString(invoice.Number.ToString(), Times11, XBrushes.Black, rp, left);
            lp.Y = topLeftY + height / 7;
            rp.Y = topLeftY + height / 7;
            gfx.DrawString("Fakturadatum", Times11, XBrushes.Black, lp, left);
            gfx.DrawString(invoice.Date.ToShortDateString(), Times11, XBrushes.Black, rp, left);
            lp.Y = topLeftY + 2 * height / 7;
            rp.Y = topLeftY + 2 * height / 7;
            gfx.DrawString("Betalningsvillkor", Times11, XBrushes.Black, lp, left);
            gfx.DrawString("30 dagar", Times11, XBrushes.Black, rp, left);
            lp.Y = topLeftY + 3 * height / 7;
            rp.Y = topLeftY + 3 * height / 7;
            gfx.DrawString("Förfallodag", Times11, XBrushes.Black, lp, left);
            gfx.DrawString(invoice.Date.AddDays(30).ToShortDateString(), Times11, XBrushes.Black, rp, left);
            lp.Y = topLeftY + 4 * height / 7;
            rp.Y = topLeftY + 4 * height / 7;
            gfx.DrawString("Dröjsmålsränta", Times11, XBrushes.Black, lp, left);
            gfx.DrawString("8%", Times11, XBrushes.Black, rp, left);
            lp.Y = topLeftY + 5 * height / 7;
            rp.Y = topLeftY + 5 * height / 7;
            gfx.DrawString("Er referens", Times11, XBrushes.Black, lp, left);
            gfx.DrawString(invoice.YourReference, Times11, XBrushes.Black, rp, left);
            lp.Y = topLeftY + 6 * height / 7;
            rp.Y = topLeftY + 6 * height / 7;
            gfx.DrawString("Vår referens", Times11, XBrushes.Black, lp, left);
            gfx.DrawString(invoice.OurReference, Times11, XBrushes.Black, rp, left);

            topLeftY = 114.34 * pointsPermm;
            width    = 181.74 * pointsPermm;
            height   = 4.49 * pointsPermm + 1;
            gfx.DrawRectangle(XBrushes.Black, topLeftX, topLeftY, width, height);
            gfx.DrawString("Beskrivning", Times11, XBrushes.White, new System.Windows.Point(topLeftX + pointsPermm, topLeftY), left);
            gfx.DrawString("Datum", Times11, XBrushes.White, new System.Windows.Point(topLeftX + 5 * width / 8, topLeftY), left);
            gfx.DrawString("Belopp", Times11, XBrushes.White, new System.Windows.Point(topLeftX + 13 * width / 16, topLeftY), left);

            topLeftY += height;
            foreach (InvoiceLine line in invoice.Lines)
            {
                gfx.DrawString(line.Description, Times11, XBrushes.Black, new System.Windows.Point(topLeftX + pointsPermm, topLeftY), left);
                gfx.DrawString(line.Date.ToShortDateString(), Times11, XBrushes.Black, new System.Windows.Point(topLeftX + 5 * width / 8, topLeftY), left);
                gfx.DrawString(line.Amount.ToString() + " kr", Times11, XBrushes.Black, new System.Windows.Point(topLeftX + width, topLeftY), right);
                topLeftY = topLeftY + 5 * pointsPermm;
            }

            gfx.DrawLine(XPens.Black, topLeftX + 5 * width / 8, topLeftY + pointsPermm, topLeftX + width, topLeftY + pointsPermm);
            topLeftY = topLeftY + 1 * pointsPermm;
            gfx.DrawString("Summa att betala", Times11Bold, XBrushes.Black, new System.Windows.Point(topLeftX + 13 * width / 16, topLeftY), right);
            gfx.DrawString(getAmountString(invoice.Sum), Times11Bold, XBrushes.Black, new System.Windows.Point(topLeftX + width, topLeftY), right);

            height = 5;
            System.Windows.Point p1 = new System.Windows.Point(lp.X, 153.56 * pointsPermm);
            System.Windows.Point p2 = new System.Windows.Point(p1.X + 23.55 * pointsPermm, 153.56 * pointsPermm);
            System.Windows.Point p3 = new System.Windows.Point(p2.X + 75.58 * pointsPermm, 153.56 * pointsPermm);
            System.Windows.Point p4 = new System.Windows.Point(p3.X + 20.78 * pointsPermm, 153.56 * pointsPermm);
            gfx.DrawString("Organisation", Times9, XBrushes.Black, p1, left);
            gfx.DrawString("Folktetten", Times9, XBrushes.Black, p2, left);
            gfx.DrawString("Tel.", Times9, XBrushes.Black, p3, left);
            gfx.DrawString("0706-141866", Times9, XBrushes.Black, p4, left);
            p1.Y += height * pointsPermm;
            p2.Y += height * pointsPermm;
            p3.Y += height * pointsPermm;
            p4.Y += height * pointsPermm;
            gfx.DrawString("Adress", Times9, XBrushes.Black, p1, left);
            gfx.DrawString("Skarpskyttevägen 22G Lgh 1201 226 42 Lund", Times9, XBrushes.Black, p2, left);
            gfx.DrawString("E-post", Times9, XBrushes.Black, p3, left);
            gfx.DrawString("*****@*****.**", Times9, XBrushes.Black, p4, left);
            p1.Y += height * pointsPermm;
            p2.Y += height * pointsPermm;
            p3.Y += height * pointsPermm;
            p4.Y += height * pointsPermm;
            gfx.DrawString("Org. Nr.", Times9, XBrushes.Black, p1, left);
            gfx.DrawString("802495-4656", Times9, XBrushes.Black, p2, left);
            gfx.DrawString("Hemsida", Times9, XBrushes.Black, p3, left);
            gfx.DrawString("www.folktetten.se", Times9, XBrushes.Black, p4, left);
            p2.Y += height * pointsPermm;
            gfx.DrawString("Godkänd för F-skatt", Times9, XBrushes.Black, p2, left);

            p2.X += 43.57 * pointsPermm;
            p2.Y  = 172 * pointsPermm;
            gfx.DrawString("INBETALNING/GIRERING AVI Nr 1", Times11, XBrushes.Black, p2, left);
            topLeftY = 176.55 * pointsPermm;
            topLeftX = 13 * pointsPermm;
            width    = 186.27 * pointsPermm;
            height   = 72.7 * pointsPermm;
            gfx.DrawLine(XPens.Black, topLeftX, topLeftY, topLeftX + width, topLeftY);
            gfx.DrawLine(XPens.Black, topLeftX, topLeftY + height, topLeftX + width, topLeftY + height);
            gfx.DrawLine(XPens.Black, topLeftX, topLeftY, topLeftX, topLeftY + height);
            gfx.DrawLine(XPens.Black, topLeftX + width, topLeftY, topLeftX + width, topLeftY + height);
            gfx.DrawLine(XPens.Black, topLeftX, topLeftY + height / 2, topLeftX + width, topLeftY + height / 2);
            gfx.DrawLine(XPens.Black, topLeftX + width / 2, topLeftY + height / 2, topLeftX + width / 2, topLeftY + height);

            p1.Y = 221.47 * pointsPermm;
            p1.X = 111.81 * pointsPermm;
            gfx.DrawString("Folktetten", Times11Bold, XBrushes.Black, p1, left);
            p1.Y += 4 * pointsPermm;
            gfx.DrawString("Philip Jönsson", Times11, XBrushes.Black, p1, left);
            p1.Y += 4 * pointsPermm;
            gfx.DrawString("Skarpskyttevägen 22G Lgh 1201", Times11, XBrushes.Black, p1, left);
            p1.Y += 4 * pointsPermm;
            gfx.DrawString("226 42 Lund", Times11, XBrushes.Black, p1, left);

            System.Windows.Point top    = new System.Windows.Point(120.76 * pointsPermm, 60.51 * pointsPermm);
            System.Windows.Point bottom = new System.Windows.Point(20.44 * pointsPermm, 221.47 * pointsPermm);
            string[]             lines  = invoice.Address.Split('\n');
            XFont font = Times11Bold;

            foreach (string line in lines)
            {
                gfx.DrawString(line, font, XBrushes.Black, top, left);
                gfx.DrawString(line, font, XBrushes.Black, bottom, left);
                bottom.Y += 4 * pointsPermm;
                top.Y    += 4 * pointsPermm;
                if (font.Bold)
                {
                    font = Times11;
                }
            }

            XBrush brush = new XSolidBrush(XColor.FromArgb(208, 206, 206));

            topLeftX = 14.5 * pointsPermm;
            topLeftY = 257.92 * pointsPermm;
            width    = 181.74 * pointsPermm;
            height   = 14.44 * pointsPermm;
            gfx.DrawRectangle(brush, topLeftX, topLeftY, width, height);
            topLeftX += 35.15 * pointsPermm;
            topLeftY += height / 3;
            width     = 52 * pointsPermm;
            height   /= 3;
            gfx.DrawRectangle(XBrushes.White, topLeftX, topLeftY, width, height);
            p1.X = topLeftX + width / 2;
            p1.Y = topLeftY;
            gfx.DrawString(getAmountString(invoice.Sum), Times11Bold, XBrushes.Black, p1, center);
            topLeftX += width + 4.78 * pointsPermm;
            gfx.DrawRectangle(XBrushes.White, topLeftX, topLeftY, width, height);
            p1.X = topLeftX + width / 2;
            gfx.DrawString("666-4791", Times11Bold, XBrushes.Black, p1, center);

            string filename = name + ".pdf";

            document.Save(filename);
            Process.Start(filename);
        }
Beispiel #26
0
        private static void paintTarget(int dimension, int xLoc, int yLoc, int blackRingCutoff, decimal[] rings, decimal zoomFactor, bool solidInner, List <Shot> shotsList, PdfPage page)
        {
            XPen   penBlack   = new XPen(XColor.FromKnownColor(XKnownColor.Black), 0.5);
            XPen   penWhite   = new XPen(XColor.FromKnownColor(XKnownColor.Linen), 0.5);
            XBrush brushBlack = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black));
            XBrush brushWhite = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Linen));

            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.IntersectClip(new XRect(xLoc, yLoc, dimension, dimension));

            gfx.SmoothingMode = XSmoothingMode.AntiAlias;

            gfx.DrawRectangle(brushWhite, xLoc, yLoc, dimension, dimension);

            int r = 1;

            for (int i = 0; i < rings.Length; i++)
            {
                XPen   p;
                XBrush b;
                XBrush bText;
                if (r < blackRingCutoff)
                {
                    p     = penBlack;
                    b     = brushWhite;
                    bText = brushBlack;
                }
                else
                {
                    p     = penWhite;
                    b     = brushBlack;
                    bText = brushWhite;
                }

                float circle  = getDimension(dimension, rings[i], zoomFactor);
                float centerX = (dimension / 2) + xLoc;
                float centerY = (dimension / 2) + yLoc;
                float x       = centerX - (circle / 2);
                float y       = centerY - (circle / 2);
                float xInvers = centerX + (circle / 2);
                float yInvers = centerY + (circle / 2);


                if (solidInner && i == rings.Length - 1) //rifle target - last ring (10) is a solid dot
                {
                    gfx.DrawEllipse(brushWhite, x, y, circle, circle);
                }
                else
                {
                    gfx.DrawEllipse(b, x, y, circle, circle);
                    gfx.DrawEllipse(p, x, y, circle, circle);
                }

                if (r < 9) //for ring 9 and after no text is displayed
                {
                    float nextCircle = getDimension(dimension, rings[i + 1], zoomFactor);
                    float diff       = circle - nextCircle;
                    float fontSize   = diff / 6f;
                    Font  f          = new Font("Arial", fontSize, GraphicsUnit.World);

                    XStringFormat format = new XStringFormat();
                    format.LineAlignment = (XLineAlignment)XStringAlignment.Center;
                    format.Alignment     = XStringAlignment.Center;

                    gfx.DrawString(r.ToString(), f, bText, centerX, y + (diff / 4), format);
                    gfx.DrawString(r.ToString(), f, bText, centerX, yInvers - (diff / 4), format);
                    gfx.DrawString(r.ToString(), f, bText, x + (diff / 4), centerY, format);
                    gfx.DrawString(r.ToString(), f, bText, xInvers - (diff / 4), centerY, format);
                }
                r++;
            }

            gfx.DrawRectangle(penBlack, xLoc, yLoc, dimension, dimension);

            foreach (Shot shot in shotsList)
            {
                drawShot(shot, gfx, xLoc, yLoc, dimension, zoomFactor);
            }

            decimal localRbar;
            decimal localXbar;
            decimal localYbar;

            computeMeans(out localRbar, out localXbar, out localYbar, shotsList);

            drawMeanGroup(gfx, dimension, zoomFactor, shotsList, localRbar, localXbar, localYbar, xLoc, yLoc);

            gfx.Dispose();
        }
    // ----- DrawRectangles -----------------------------------------------------------------------

    //public void DrawRectangles(XPen pen, XSolidBrush brush, Rectangle[] rects)
    //{
    //  if (this.gfx != null)
    //  {
    //    this.gfx.FillRectangles(brush.RealizeGdiBrush(), rects);
    //    this.gfx.DrawRectangles(pen.RealizeGdiPen(), rects);
    //  }
    //  if (this.pdfPage != null)
    //  {
    //    int count = rects.Length;
    //    for (int idx = 0; idx < count; idx++)
    //    {
    //      Rectangle rect = rects[idx];
    //      this.pdfPage.PageContent.DrawRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height);
    //    }
    //  }
    //}

    public void DrawRectangles(XPen pen, XSolidBrush brush, RectangleF[] rects)
    {
      if (this.gfx != null)
      {
        this.gfx.FillRectangles(brush.RealizeGdiBrush(), rects);
        this.gfx.DrawRectangles(pen.RealizeGdiPen(), rects);
      }
      if (this.pdfPage != null)
      {
        int count = rects.Length;
        for (int idx = 0; idx < count; idx++)
        {
          RectangleF rect = rects[idx];
          this.pdfPage.PageContent.DrawRectangle(pen, brush, rect.X, rect.Y, rect.Width, rect.Height);
        }
      }
    }
Beispiel #28
0
        private static void printSessionData(PdfPage page, int x, int y, int width, int height, Session session)
        {
            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.IntersectClip(new XRect(x, y, width, height));
            XPen   penBlack   = new XPen(XColor.FromKnownColor(XKnownColor.Black), 0.5);
            XBrush brushBlack = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black));


            XTextFormatter tf = new XTextFormatter(gfx);

            tf.Alignment = XParagraphAlignment.Left;
            Font fLarge      = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.World);
            Font fMedium     = new Font("Arial", 10, GraphicsUnit.World);
            Font fMediumBold = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.World);
            Font fSmall      = new Font("Arial", 8, GraphicsUnit.World);

            String s = "Match summary";

            XPoint point = new XPoint(x, y);

            point.Offset(5, 5);
            s = "Session ID:";
            XSize rect = gfx.MeasureString(s, fMediumBold);

            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = session.id.ToString();
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));



            //new line
            point = new XPoint(x, y);
            point.Offset(5, 5);
            point.Offset(0, rect.Height + 5);
            s    = "Event:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s = session.eventType.Name;
            if (session.numberOfShots > 0)
            {
                s += " " + session.numberOfShots;
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Shooter:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = session.user;
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Start Time: ";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width, 0);
            s    = session.startTime.ToString("yyyy-MM-dd hh:mm:ss");
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "End Time: ";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width, 0);
            s    = session.endTime.ToString("yyyy-MM-dd hh:mm:ss");
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 15, 0);
            s    = "Duration:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = (session.endTime - session.startTime).TotalMinutes.ToString("F2", CultureInfo.InvariantCulture) + " mins";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Avg Shot time:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.averageTimePerShot.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Shortest:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.shortestShot.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Longest:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.longestShot.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "MPI: ";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            string W, E;

            if (session.xbar < 0)
            {
                W = "\u2190";
            }
            else
            {
                W = "\u2192";
            }

            if (session.ybar < 0)
            {
                E = "\u2193";
            }
            else
            {
                E = "\u2191";
            }
            s    = W + Math.Abs(session.xbar).ToString("F2", CultureInfo.InvariantCulture) + "mm" + "  " + E + Math.Abs(session.ybar).ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "MR:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.rbar.ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Group size:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.groupSize.ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Total Score:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            if (session.decimalScoring)
            {
                s = session.decimalScore.ToString("F1", CultureInfo.InvariantCulture) + " - " + session.innerX + "x";
            }
            else
            {
                s = session.score.ToString() + " - " + session.innerX + "x";
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 10, 0);
            s    = "Average score:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = session.averageScore.ToString("F2", CultureInfo.InvariantCulture);
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Number of shots in session:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 2, 0);
            s    = session.actualNumberOfShots.ToString();
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Series:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 2, 0);
            s = "";
            int X;

            foreach (List <Shot> shots in session.AllSeries)
            {
                if (session.decimalScoring)
                {
                    s += sumScores(session, shots, out X).ToString("F1", CultureInfo.InvariantCulture) + " ";
                }
                else
                {
                    s += sumScores(session, shots, out X).ToString("F0", CultureInfo.InvariantCulture) + " ";
                }
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            drawBreakdownGraph(gfx, point.X, point.Y, width - 10, height - point.Y + 15, session);

            gfx.DrawRectangle(penBlack, x, y, width, height);
            gfx.Dispose();
        }
Beispiel #29
0
        private void print_button_Click(object sender, EventArgs e)
        {
            string dir;

            int          tamFonte = 10;
            List <Label> labels   = new List <Label>();

            for (int i = 0; i < groupResultados.Controls.Count; i++)
            {
                if (groupResultados.Controls[i].AccessibilityObject.Role == AccessibleRole.StaticText)
                {
                    labels.Add(new Label()
                    {
                        Text = groupResultados.Controls[i].Text, BackColor = groupResultados.Controls[i].BackColor
                    });
                }
            }

            if (!labels.Any())
            {
                return;
            }
            folderBrowserDialog1.Description = "Selecione a pasta para salvar o Relatório.";
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                dir = folderBrowserDialog1.SelectedPath;
            }
            else
            {
                return;
            }

            var colunas = labels.Count(x => x.BackColor == Color.Gray);

            PdfDocument document = new PdfDocument();                            //cria um documento pdf

            document.Info.Title = tabela.SelectedItem.ToString();                //título do pdf(meio obvio)
            PdfPage   page = document.AddPage();                                 //cria uma página no pdf
            XGraphics gfx  = XGraphics.FromPdfPage(page);                        //permite desenhar coisas no pdf
            XFont     font = new XFont("Consolas", tamFonte, XFontStyle.Italic); //permite definir fonte, tamanho de fonte e estilo de fonte

            XTextFormatter tf = new XTextFormatter(gfx);

            var tamanho   = page.Width.Point - 40;
            var tamColuna = Math.Ceiling(tamanho / colunas);

            var altura  = page.Height.Point - 40;
            var paginas = Math.Ceiling(((labels.Count / colunas) * tamFonte) / (altura));

            int pageAtual = 0;

            for (int i = 0; i < labels.Count / colunas; i++)
            {
                for (int j = 0; j < colunas; j++)
                {
                    if (paginas > 1 && (20 + (i * tamFonte) + tamFonte - (pageAtual * altura)) > altura)
                    {
                        page = document.AddPage();
                        gfx  = XGraphics.FromPdfPage(page);
                        tf   = new XTextFormatter(gfx);
                        pageAtual++;
                        paginas--;
                    }
                    XRect rect  = new XRect(20 + (tamColuna * j), (20 + (i * tamFonte) - (pageAtual * altura)) > 0? (20 + (i * tamFonte) - (pageAtual * altura)) : 0, tamColuna, tamFonte);
                    var   brush = new XSolidBrush(new XColor()
                    {
                        A = 1, R = labels[(i * colunas) + j].BackColor.R, G = labels[(i * colunas) + j].BackColor.G, B = labels[(i * colunas) + j].BackColor.B
                    });
                    gfx.DrawRectangle(brush, rect);
                    tf.Alignment = XParagraphAlignment.Left;
                    tf.DrawString(labels[(i * colunas) + j].Text, font, XBrushes.Black, rect, XStringFormats.TopLeft);
                }
            }

            string filename = dir + "\\" + tabela.SelectedItem.ToString() + "-" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + ".pdf";

            document.Save(filename);
        }
Beispiel #30
0
        private static void printSeriesData(PdfPage page, int x, int y, int width, int height, List <Shot> shotList, int index, Session session)
        {
            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.IntersectClip(new XRect(x, y, width, height));
            XPen   penBlack   = new XPen(XColor.FromKnownColor(XKnownColor.Black), 0.5);
            XBrush brushBlack = new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black));

            XTextFormatter tf = new XTextFormatter(gfx);

            tf.Alignment = XParagraphAlignment.Left;
            Font fMedium     = new Font("Arial", 10, GraphicsUnit.World);
            Font fMediumBold = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.World);

            XPoint point = new XPoint(x, y);

            point.Offset(5, 5);
            String s    = "Series " + index;
            XSize  rect = gfx.MeasureString(s, fMediumBold);

            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Score:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            int X;

            point.Offset(rect.Width + 2, 0);
            decimal score = sumScores(session, shotList, out X);

            if (session.decimalScoring)
            {
                s = score.ToString("F1", CultureInfo.InvariantCulture) + " - " + X + "x";
            }
            else
            {
                s = score.ToString("F0", CultureInfo.InvariantCulture) + " - " + X + "x";
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Shots:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 2, 0);
            s = "";
            foreach (Shot shot in shotList)
            {
                string t = shot.innerTen ? "*" : "";
                if (session.decimalScoring)
                {
                    s += shot.decimalScore.ToString("F1", CultureInfo.InvariantCulture) + t + "   ";
                }
                else
                {
                    s += shot.score + t + "   ";
                }
            }
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Average score:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            decimal avg = score / shotList.Count;

            s    = avg.ToString("F2", CultureInfo.InvariantCulture);
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));



            decimal localRbar;
            decimal localXbar;
            decimal localYbar;

            computeMeans(out localRbar, out localXbar, out localYbar, shotList);

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "MPI: ";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            string W, E;

            if (localXbar < 0)
            {
                W = "\u2190";
            }
            else
            {
                W = "\u2192";
            }

            if (localYbar < 0)
            {
                E = "\u2193";
            }
            else
            {
                E = "\u2191";
            }
            s    = W + Math.Abs(localXbar).ToString("F2", CultureInfo.InvariantCulture) + "mm" + "  " + E + Math.Abs(localYbar).ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "MR:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = localRbar.ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Group size:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = calculateMaxSpread(shotList).ToString("F2", CultureInfo.InvariantCulture) + "mm";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "First shot:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = shotList[0].timestamp.ToString("hh:mm:ss");
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Last shot:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = shotList[shotList.Count - 1].timestamp.ToString("hh:mm:ss");
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            TimeSpan shortest;
            TimeSpan longest;
            TimeSpan avgTime;

            calculateTimeStats(out shortest, out longest, out avgTime, shotList);
            //new line
            point = new XPoint(x + 5, point.Y + rect.Height + 5);
            s     = "Avg Shot time:";
            rect  = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = avgTime.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Shortest:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = shortest.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 5, 0);
            s    = "Longest:";
            rect = gfx.MeasureString(s, fMediumBold);
            tf.DrawString(s, fMediumBold, brushBlack, new XRect(point, rect));

            point.Offset(rect.Width + 1, 0);
            s    = longest.TotalSeconds.ToString("F2", CultureInfo.InvariantCulture) + "s";
            rect = gfx.MeasureString(s, fMedium);
            tf.DrawString(s, fMedium, brushBlack, new XRect(point, rect));


            gfx.DrawRectangle(penBlack, x, y, width, height);
            gfx.Dispose();
        }
Beispiel #31
0
        public Stream GeneratePdfLabels(List <string> Addresses, LabelFormat lf, int QtyEachLabel)
        {
            Stream generatePdfLabels = new MemoryStream();
            // The label sheet is basically a table and each cell is a single label
            // Format related
            int CellsPerPage  = lf.RowCount * lf.ColumnCount;
            int CellsThisPage = 0;
            //XRect ContentRectangle = new XRect();       // A single cell content rectangle. This is the rectangle that can be used for contents and accounts for margins and padding.
            XSize  ContentSize = new XSize(); // Size of content area inside a cell.
            double ContentLeftPos;            // left edge of current content area.
            double ContentTopPos;             // Top edge of current content area

            // Layout related
            XColor        StrokeColor = XColors.DarkBlue;
            XColor        FillColor   = XColors.DarkBlue;
            XPen          Pen         = new XPen(StrokeColor, 0.1);
            XBrush        Brush       = new XSolidBrush(FillColor);
            XGraphics     Gfx;
            XGraphicsPath Path = new XGraphicsPath();

            //int LoopTemp = 0;         // Counts each itteration. Used with QtyEachLabel
            int         CurrentColumn = 1;
            int         CurrentRow    = 1;
            PdfDocument Doc           = new PdfDocument();
            PdfPage     page          = new PdfPage();

            //AddPage(Doc, page, lf);
            Doc.AddPage(page);
            Gfx = XGraphics.FromPdfPage(page);

            // Ensure that at least 1 of each label is printed.
            if (QtyEachLabel < 1)
            {
                QtyEachLabel = 1;
            }

            // Define the content area size
            ContentSize = new XSize(XUnit.FromMillimeter(lf.LabelWidth - lf.LabelPaddingLeft - lf.LabelPaddingRight).Point,
                                    XUnit.FromMillimeter(lf.LabelHeight - lf.LabelPaddingTop - lf.LabelPaddingBottom).Point);

            if (Addresses != null)
            {
                if (Addresses.Count > 0)
                // We actually have addresses to output.
                {
                    WriteLine();
                    foreach (string Address in Addresses)
                    {
                        // Once for each address
                        for (int LoopTemp = 0; LoopTemp < QtyEachLabel; LoopTemp++)
                        // Once for each copy of this address.
                        {
                            WriteLine($"Obradjuje se : {Address} ");
                            //WriteLine($"Nalepnica: {CellsThisPage} od :{CellsPerPage} ");
                            if (CellsThisPage == CellsPerPage)
                            {
                                //AddPage(Doc, page, lf);
                                //Gfx = XGraphics.FromPdfPage(page);
                                page          = Doc.AddPage();
                                Gfx           = XGraphics.FromPdfPage(page);
                                CellsThisPage = 0;
                            }
                            // This pages worth of cells are filled up. Create a new page


                            // Calculate which row and column we are working on.
                            CurrentColumn = (CellsThisPage + 1) % lf.ColumnCount;
                            double a = (CellsThisPage + 1) / lf.ColumnCount;
                            CurrentRow = (int)Math.Truncate(a);
                            //WriteLine($"Tekuci red: {CurrentRow} tekuca kolona :{CurrentColumn} ");


                            if (CurrentColumn == 0)
                            {
                                // This occurs when you are working on the last column of the row.
                                // This affects the count for column and row
                                CurrentColumn = lf.ColumnCount;
                            }
                            else
                            {
                                // We are not viewing the last column so this number will be decremented by one.
                                CurrentRow = CurrentRow + 1;
                            }



                            // Calculate the left position of the current cell.
                            ContentLeftPos = ((CurrentColumn - 1) * lf.HorizontalPitch) + lf.LeftMargin + lf.LabelPaddingLeft;


                            // Calculate the top position of the current cell.
                            ContentTopPos = ((CurrentRow - 1) * lf.VerticalPitch) + lf.TopMargin + lf.LabelPaddingTop;
                            //WriteLine($"Leva pozicija: {ContentLeftPos} Pozicija od vrha :{ContentTopPos} Velicina sadrzaja : {ContentSize} ");


                            // Define the content rectangle.
                            XPoint xpoint1 = new XPoint(XUnit.FromMillimeter(ContentLeftPos).Point, XUnit.FromMillimeter(ContentTopPos).Point);

                            XRect ContentRectangle = new XRect(xpoint1, ContentSize);


                            Path = new XGraphicsPath();


                            // Add the address string to the page.
                            Path.AddString(Address, new XFontFamily("Arial"),
                                           XFontStyle.Regular,
                                           9,
                                           ContentRectangle,
                                           XStringFormats.TopLeft);


                            Gfx.DrawPath(Pen, Brush, Path);


                            // Increment the cell count
                            CellsThisPage = CellsThisPage + 1;
                        }
                    }
                    Doc.Save(generatePdfLabels, false);
                }
            }
            return(generatePdfLabels);
        }
Beispiel #32
0
        private void btn_createcalendar_Click(object sender, EventArgs e)
        {
            string        strConnString = "Data Source=toh-app;Initial Catalog=UBC;Integrated Security=False;user id=OnlineServices;password=Whanganui497";
            SqlConnection con           = new SqlConnection(strConnString);

            con.Open();
            SqlCommand cmd;

            cmd             = new SqlCommand("Calender_Planner_Format", con);
            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();


            // EXECUTE SP: Calender_Planner_Format (NEED TO PARAMETRISE WITH DATES)
            string columns    = "Days";
            int    pageWidth  = 1500;
            int    pageHeight = 594;

            int margin       = 10;
            int toprowHeight = 10;
            int leftcolWidth = 17;
            int tidesheight  = 4;

            double textmargin = 8;
            double schoolholidaysrowheight = 3;

            //int textheight = 13; made 1/3 of row height

            bool     isSunrise = false;
            bool     isSunset  = false;
            DateTime sunrise   = DateTime.Now;
            DateTime sunset    = DateTime.Now;


            DateTime startDate = new DateTime(2019, 7, 1);

            if (startDate.Day != 1)
            {
                MessageBox.Show("Must be 1st of the month");
            }

            DateTime endDate = new DateTime(2020, 6, 30);

            if (endDate.AddDays(1).Day != 1)
            {
                MessageBox.Show("Must be last of thenmonth");
            }

            /*
             * int days = (endDate - startDate).Days+1;
             *
             * for (int f1 = 0; f1 <= days-1; f1++)
             * {
             *
             * }
             */

            int startyear  = startDate.Year;
            int startmonth = startDate.Month;
            int months     = 12; //Should be calculated

            //DateTime dlsStart = new DateTime(2019, 9, 29);
            //DateTime dlsEnd = new DateTime(2020, 4, 5);

            cmd.CommandType = CommandType.Text;


            XUnit XtoprowHeight = XUnit.FromMillimeter(toprowHeight);
            XUnit XleftcolWidth = XUnit.FromMillimeter(leftcolWidth);

            #region get maximum days
            DateTime firstofmonth = new DateTime(startyear, startmonth, 1);

            int maxDays = 0;
            for (int f1 = 1; f1 <= months; f1++)
            {
                int dayofweek = (int)firstofmonth.DayOfWeek; //Sunday is 0     MOD(xxx-1,7)
                dayofweek = mod(dayofweek - 1, 7);
                int daysinmonth = DateTime.DaysInMonth(firstofmonth.Year, firstofmonth.Month);
                if (dayofweek + daysinmonth > maxDays)
                {
                    maxDays = dayofweek + daysinmonth;
                }
                firstofmonth = firstofmonth.AddMonths(1);
            }
            #endregion

            double columnWidth;
            double rowHeight;
            if (columns == "Months")
            {
                columnWidth = (pageWidth - (2 * margin) - leftcolWidth) / months;
                rowHeight   = (pageHeight - (2 * margin) - toprowHeight) / maxDays;
            }
            else
            {
                columnWidth = (pageWidth - (2 * margin) - leftcolWidth) / maxDays;
                rowHeight   = (pageHeight - (2 * margin) - toprowHeight) / months;
            }
            double textheight = (rowHeight - textmargin - schoolholidaysrowheight - tidesheight) / 3;
            //double xx = XUnit.FromMillimeter(textheight);
            XFont textfont = new XFont("Verdana", textheight / 1.5);

            XUnit XcolumnWidth = XUnit.FromMillimeter(columnWidth);
            XUnit XrowHeight   = XUnit.FromMillimeter(rowHeight);

            // Create a new PDF document
            PdfDocument document = new PdfDocument();
            document.Info.Title = "Calendar";

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

            page.Width  = XUnit.FromMillimeter(pageWidth);
            page.Height = XUnit.FromMillimeter(pageHeight);

            #region fonts, brushes, pens
            XBrush blueshade        = new XSolidBrush(XBrushes.LightBlue);
            XBrush grayshade        = new XSolidBrush(XBrushes.LightGray);
            XBrush whiteshade       = new XSolidBrush(XBrushes.White);
            XBrush greenshade       = new XSolidBrush(XBrushes.LightGreen);
            XBrush redshade         = new XSolidBrush(XBrushes.Red);
            XBrush orangeshade      = new XSolidBrush(XBrushes.Orange);
            XBrush yellowshade      = new XSolidBrush(XBrushes.Yellow);
            XBrush aquashade        = new XSolidBrush(XBrushes.Aqua);
            XBrush pinkshade        = new XSolidBrush(XBrushes.Pink);
            XBrush purpleshade      = new XSolidBrush(XBrushes.Purple);
            XBrush transparentshade = new XSolidBrush(XBrushes.Transparent);

            XFont daynumberfont = new XFont("Verdana", 14);
            XFont headfont      = new XFont("Verdana", 20);
            XFont sunfont       = new XFont("Verdana", 8);
            XFont tidefont      = new XFont("Verdana", 6.5);

            XBrush shade  = new XSolidBrush();
            XPen   border = new XPen(XColors.Black, 1);


            #endregion

            using (XGraphics gfx = XGraphics.FromPdfPage(page))
            {
                #region headings
                XTextFormatter tf = new XTextFormatter(gfx);
                //gfx.DrawString("Hello, World!", textfont, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);

                if (columns == "Months")
                {
                    //Top Row - Months
                    //tf.Alignment = XParagraphAlignment.Center;
                    firstofmonth = new DateTime(startyear, startmonth, 1);
                    for (int f1 = 0; f1 < months; f1++)
                    {
                        double x = f1 * columnWidth + margin + leftcolWidth;
                        gfx.DrawRectangle(border, blueshade, XUnit.FromMillimeter(x), XUnit.FromMillimeter(toprowHeight), XcolumnWidth, XtoprowHeight);
                        XRect  rect  = new XRect(XUnit.FromMillimeter(x), XUnit.FromMillimeter(toprowHeight), XcolumnWidth, XtoprowHeight);
                        string month = firstofmonth.ToString("MMM");
                        //tf.DrawString(month, daynumberfont, XBrushes.Black, rect, XStringFormats.TopLeft);
                        gfx.DrawString(month, headfont, XBrushes.Black, rect, XStringFormats.Center);
                        //gfx.DrawString(month, headfont, XBrushes.Black, XUnit.FromMillimeter(x), XUnit.FromMillimeter(toprowHeight), XStringFormats.Center);
                        firstofmonth = firstofmonth.AddMonths(1);
                    }

                    //Left Column - Days
                    DateTime anymonday = new DateTime(2019, 7, 1);
                    for (int f1 = 0; f1 < maxDays; f1++)
                    {
                        double y = f1 * rowHeight + margin + toprowHeight;
                        gfx.DrawRectangle(border, blueshade, XUnit.FromMillimeter(margin), XUnit.FromMillimeter(y), XleftcolWidth, XrowHeight);
                        XRect  rect = new XRect(XUnit.FromMillimeter(margin), XUnit.FromMillimeter(y), XleftcolWidth, XrowHeight);
                        string day  = anymonday.ToString("ddd");
                        //tf.DrawString(day, daynumberfont, XBrushes.Black, rect, XStringFormats.TopLeft);
                        gfx.DrawString(day, headfont, XBrushes.Black, rect, XStringFormats.Center);
                        //gfx.DrawString(day, headfont, XBrushes.Black, XUnit.FromMillimeter(margin), XUnit.FromMillimeter(y), XStringFormats.Center);
                        anymonday = anymonday.AddDays(1);
                    }
                }
                else
                {
                    //Top Row - Days
                    DateTime anymonday = new DateTime(2019, 7, 1);
                    for (int f1 = 0; f1 < maxDays; f1++)
                    {
                        double x = f1 * columnWidth + margin + leftcolWidth;
                        gfx.DrawRectangle(border, blueshade, XUnit.FromMillimeter(x), XUnit.FromMillimeter(margin), XcolumnWidth, XtoprowHeight);
                        XRect  rect = new XRect(XUnit.FromMillimeter(x), XUnit.FromMillimeter(margin), XcolumnWidth, XtoprowHeight);
                        string day  = anymonday.ToString("ddd");
                        //tf.DrawString(day, daynumberfont, XBrushes.Black, rect, XStringFormats.TopLeft);
                        gfx.DrawString(day, headfont, XBrushes.Black, rect, XStringFormats.Center);
                        //gfx.DrawString(day, headfont, XBrushes.Black, XUnit.FromMillimeter(x), XUnit.FromMillimeter(margin), XStringFormats.Center);
                        anymonday = anymonday.AddDays(1);
                    }

                    //Left Column - Months
                    //tf.Alignment = XParagraphAlignment.Center;
                    firstofmonth = new DateTime(startyear, startmonth, 1);
                    for (int f1 = 0; f1 < months; f1++)
                    {
                        double y = f1 * rowHeight + margin + toprowHeight;
                        gfx.DrawRectangle(border, blueshade, XUnit.FromMillimeter(margin), XUnit.FromMillimeter(y), XleftcolWidth, XrowHeight);
                        XRect  rect  = new XRect(XUnit.FromMillimeter(margin), XUnit.FromMillimeter(y), XleftcolWidth, XrowHeight);
                        string month = firstofmonth.ToString("MMM");
                        //tf.DrawString(month, daynumberfont, XBrushes.Black, rect, XStringFormats.TopLeft);
                        gfx.DrawString(month, headfont, XBrushes.Black, rect, XStringFormats.Center);
                        //gfx.DrawString(month, headfont, XBrushes.Black, XUnit.FromMillimeter(margin), XUnit.FromMillimeter(y), XStringFormats.Center);
                        firstofmonth = firstofmonth.AddMonths(1);
                    }
                }
                #endregion

                if (1 == 1)
                {
                    double   x         = 0;
                    double   y         = 0;
                    int      thisyear  = startyear;
                    int      thismonth = startmonth;
                    DateTime thisday   = new DateTime();
                    firstofmonth = new DateTime(startyear, startmonth, 1);
                    for (int f1 = 0; f1 < months; f1++)
                    {
                        if (columns == "Months")
                        {
                            x = f1 * columnWidth + margin + leftcolWidth;
                        }
                        else
                        {
                            y = f1 * rowHeight + margin + toprowHeight;
                        }
                        int d1        = 0;
                        int dayofweek = (int)firstofmonth.DayOfWeek; //Sunday is 0     MOD(xxx-1,7)
                        dayofweek = mod(dayofweek - 1, 7);
                        int daysinmonth = DateTime.DaysInMonth(firstofmonth.Year, firstofmonth.Month);
                        for (int f2 = 0; f2 < maxDays; f2++)
                        {
                            if (columns == "Months")
                            {
                                y = f2 * rowHeight + margin + toprowHeight;
                            }
                            else
                            {
                                x = f2 * columnWidth + margin + leftcolWidth;
                            }
                            //gfx.DrawLine(lineRed, 0, j, page.Width, j);
                            string day = "";
                            if (f2 >= dayofweek && f2 < dayofweek + daysinmonth)
                            {
                                d1++;
                                day     = d1.ToString();
                                shade   = transparentshade;
                                thisday = new DateTime(thisyear, thismonth, d1);
                            }
                            else
                            {
                                shade = grayshade;
                            }
                            gfx.DrawRectangle(border, shade, XUnit.FromMillimeter(x), XUnit.FromMillimeter(y), XcolumnWidth, XrowHeight);
                            //XRect rect = new XRect(XUnit.FromMillimeter(x + 2), XUnit.FromMillimeter(y + 2), XcolumnWidth, XrowHeight);
                            //gfx.DrawString(day, daynumberfont, XBrushes.Black, rect, XStringFormats.TopLeft);
                            gfx.DrawString(day, daynumberfont, XBrushes.Black, XUnit.FromMillimeter(x + 2), XUnit.FromMillimeter(y + 2), XStringFormats.TopLeft);

                            if (day != "")
                            {
                                //if (thisday >= dlsStart && thisday <= dlsEnd)
                                if (TimeZoneInfo.Local.IsDaylightSavingTime(thisday))
                                {
                                    XImage image = XImage.FromFile(@"\\toh-dc\RedirectedFolders$\gtichbon\My Documents\Visual Studio 2017\Projects\Calendar\Calendar\DLS.png");
                                    gfx.DrawImage(image, XUnit.FromMillimeter(x - 1), XUnit.FromMillimeter(y - 1));
                                }
                                //-39.932493, 175.058131

                                SunTimes.Instance.CalculateSunRiseSetTimes(new SunTimes.LatitudeCoords
                                                                               (-39, 55, 57, SunTimes.LatitudeCoords.Direction.North),
                                                                           new SunTimes.LongitudeCoords
                                                                               (175, 3, 29, SunTimes.LongitudeCoords.Direction.East),
                                                                           thisday, ref sunrise, ref sunset,
                                                                           ref isSunrise, ref isSunset);

                                //day += sunrise.ToString("HH:mm") + Environment.NewLine + sunset.ToString("HH:mm");
                                gfx.DrawString(sunrise.ToString("HH:mm"), sunfont, XBrushes.Black, XUnit.FromMillimeter(x + 30), XUnit.FromMillimeter(y + .5), XStringFormats.TopLeft);
                                gfx.DrawString(sunset.ToString("HH:mm"), sunfont, XBrushes.Black, XUnit.FromMillimeter(x + 30), XUnit.FromMillimeter(y + 4), XStringFormats.TopLeft);

                                string tides = "";
                                string sql1  = "Select * from tides where [date] = '" + thisday.ToString("dd-MMM-yyyy") + "'";
                                cmd = new SqlCommand(sql1, con);
                                //cmd.Connection = con;
                                SqlDataReader dr1 = cmd.ExecuteReader();
                                if (dr1.HasRows)
                                {
                                    dr1.Read();
                                    for (int f4 = 1; f4 <= 4; f4++)
                                    {
                                        if (dr1["Type" + f4.ToString()].ToString() != "")
                                        {
                                            tides += dr1["Type" + f4.ToString()].ToString().Substring(0, 1) + (dr1["Time" + f4.ToString()]).ToString().Substring(0, 5) + " ";
                                            ////if(dr1["Type" + f4.ToString()].ToString() == "High")
                                            ////{
                                            ////} else
                                            ////{

                                            ////}

                                            //tides += (dr1["Time" + f4.ToString()]).ToString().Substring(0, 5) + " ";
                                        }
                                    }
                                }
                                dr1.Close();
                                gfx.DrawString(tides, tidefont, XBrushes.DarkRed, XUnit.FromMillimeter(x + 1), XUnit.FromMillimeter(y + rowHeight - 3), XStringFormats.TopLeft);


                                if (thismonth == 12 && d1 == 31)
                                {
                                    thisyear += 1;
                                }
                            }
                        }
                        firstofmonth = firstofmonth.AddMonths(1);
                        thismonth   += 1;
                        if (thismonth > 12)
                        {
                            thismonth = 1;
                        }
                    }
                } //1=1

                /*
                 * string sql1 = "Select * from tides [date] >= '" + startDate.ToString("dd-MMM-yyyy") + "' and [date] <= '" + endDate.ToString("dd-MMM-yyyy") + "'"; // and calendar_id in (67,69)";
                 * cmd = new SqlCommand(sql1, con);
                 * //cmd.Connection = con;
                 * SqlDataReader dr1 = cmd.ExecuteReader();
                 * while (dr1.Read())
                 * {
                 * }
                 * dr1.Close();
                 */


                string sql2 = "Select * from Calendar where line <> 0"; // and calendar_id in (67,69)";
                cmd = new SqlCommand(sql2, con);
                //cmd.Connection = con;
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    DateTime Eventstartdate   = (DateTime)dr["startdate"];
                    string   eventtitle       = dr["event"].ToString();
                    string   Eventenddatetext = dr["enddate"].ToString();
                    DateTime Eventenddate     = new DateTime();
                    string   colour           = dr["colour"].ToString();
                    if (Eventenddatetext == "")
                    {
                        Eventenddate = Eventstartdate;
                    }
                    else
                    {
                        Eventenddate = Convert.ToDateTime(Eventenddatetext);
                    }
                    int line = (int)dr["line"] - 1;

                    DateTime useStartDate = Eventstartdate;
                    DateTime useEndDate   = Eventenddate;
                    String   CalendarType = dr["type"].ToString();
                    if (CalendarType != "Daylight savings")
                    {
                        //Eventenddate may extend into the next month or a month after that even.
                        int monthspan = ((Eventenddate.Year - Eventstartdate.Year) * 12) + Eventenddate.Month - Eventstartdate.Month + 1;
                        for (int f3 = 1; f3 <= monthspan; f3++)
                        {
                            int row = (mod(Eventstartdate.Month - startmonth, 12) + f3);

                            firstofmonth = new DateTime(useStartDate.Year, useStartDate.Month, 1);
                            int firstdaycolum = (int)firstofmonth.DayOfWeek; //Sunday is 0     MOD(xxx-1,7)
                            firstdaycolum = mod(firstdaycolum - 1, 7);
                            int column = useStartDate.Day + firstdaycolum;

                            //if (Eventenddate.Month > Eventstartdate.Month || Eventenddate.Year > Eventstartdate.Year)
                            if (f3 < monthspan)
                            {
                                useEndDate = new DateTime(Eventstartdate.Year, Eventstartdate.Month, 1).AddMonths(f3).AddDays(-1);
                            }
                            else
                            {
                                useEndDate = Eventenddate;
                            }

                            int cols = (useEndDate - useStartDate).Days + 1;

                            useStartDate = useEndDate.AddDays(1);

                            double x = margin + leftcolWidth + (column - 1) * columnWidth;
                            double y = margin + toprowHeight + (row - 1) * rowHeight;
                            if (CalendarType == "School Holidays")
                            {
                                shade = redshade;
                                gfx.DrawRectangle(redshade, XUnit.FromMillimeter(x), XUnit.FromMillimeter(y + textmargin), XcolumnWidth * cols, XUnit.FromMillimeter(schoolholidaysrowheight));
                            }
                            else
                            {
                                switch (colour.ToLower())
                                {
                                case "green":
                                    shade = greenshade;
                                    break;

                                case "red":
                                    shade = redshade;
                                    break;

                                case "orange":
                                    shade = orangeshade;
                                    break;

                                case "blue":
                                    shade = blueshade;
                                    break;

                                case "yellow":
                                    shade = yellowshade;
                                    break;

                                case "aqua":
                                    shade = aquashade;
                                    break;

                                case "pink":
                                    shade = pinkshade;
                                    break;

                                case "purple":
                                    shade = purpleshade;
                                    break;

                                case "gray":
                                    shade = grayshade;
                                    break;

                                default:
                                    shade = greenshade;
                                    break;
                                }

                                gfx.DrawRectangle(border, shade, XUnit.FromMillimeter(x), XUnit.FromMillimeter(y + (line * textheight) + textmargin + schoolholidaysrowheight), XcolumnWidth * cols, XUnit.FromMillimeter(textheight));
                                XRect rectevent = new XRect(XUnit.FromMillimeter(x + 2), XUnit.FromMillimeter(y + (line * textheight) + textmargin + schoolholidaysrowheight + 2), XUnit.FromMillimeter(columnWidth * cols - 4), XUnit.FromMillimeter(textheight - 4));
                                tf.DrawString(eventtitle, textfont, XBrushes.Black, rectevent, XStringFormats.TopLeft);
                            }
                        }
                    }
                }
                dr.Close();
                con.Close();
                con.Dispose();

                // Save the document...
                const string filename = "UBC.pdf";
                document.Save(filename);
                // ...and start a viewer.
                Process.Start(filename);
            }
        } //btn_click
Beispiel #33
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="line"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, Core2D.XLine line, double dx, double dy, ImmutableArray <Core2D.ShapeProperty> db, Core2D.Record r)
        {
            if (!line.IsStroked)
            {
                return;
            }

            var _gfx = gfx as XGraphics;

            XSolidBrush fillLine   = ToXSolidBrush(line.Style.Fill);
            XPen        strokeLine = ToXPen(line.Style, _scaleToPage);

            XSolidBrush fillStartArrow   = ToXSolidBrush(line.Style.StartArrowStyle.Fill);
            XPen        strokeStartArrow = ToXPen(line.Style.StartArrowStyle, _scaleToPage);

            XSolidBrush fillEndArrow   = ToXSolidBrush(line.Style.EndArrowStyle.Fill);
            XPen        strokeEndArrow = ToXPen(line.Style.EndArrowStyle, _scaleToPage);

            double _x1 = line.Start.X + dx;
            double _y1 = line.Start.Y + dy;
            double _x2 = line.End.X + dx;
            double _y2 = line.End.Y + dy;

            Core2D.XLine.SetMaxLength(line, ref _x1, ref _y1, ref _x2, ref _y2);

            double x1 = _scaleToPage(_x1);
            double y1 = _scaleToPage(_y1);
            double x2 = _scaleToPage(_x2);
            double y2 = _scaleToPage(_y2);

            var    sas = line.Style.StartArrowStyle;
            var    eas = line.Style.EndArrowStyle;
            double a1  = Math.Atan2(y1 - y2, x1 - x2) * 180.0 / Math.PI;
            double a2  = Math.Atan2(y2 - y1, x2 - x1) * 180.0 / Math.PI;

            var t1 = new XMatrix();
            var c1 = new XPoint(x1, y1);

            t1.RotateAtPrepend(a1, c1);

            var t2 = new XMatrix();
            var c2 = new XPoint(x2, y2);

            t2.RotateAtPrepend(a2, c2);

            XPoint pt1;
            XPoint pt2;

            double radiusX1 = sas.RadiusX;
            double radiusY1 = sas.RadiusY;
            double sizeX1   = 2.0 * radiusX1;
            double sizeY1   = 2.0 * radiusY1;

            switch (sas.ArrowType)
            {
            default:
            case Core2D.ArrowType.None:
            {
                pt1 = new XPoint(x1, y1);
            }
            break;

            case Core2D.ArrowType.Rectangle:
            {
                pt1 = t1.Transform(new XPoint(x1 - sizeX1, y1));
                var rect = new XRect(x1 - sizeX1, y1 - radiusY1, sizeX1, sizeY1);
                _gfx.Save();
                _gfx.RotateAtTransform(a1, c1);
                DrawRectangleInternal(_gfx, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref rect);
                _gfx.Restore();
            }
            break;

            case Core2D.ArrowType.Ellipse:
            {
                pt1 = t1.Transform(new XPoint(x1 - sizeX1, y1));
                _gfx.Save();
                _gfx.RotateAtTransform(a1, c1);
                var rect = new XRect(x1 - sizeX1, y1 - radiusY1, sizeX1, sizeY1);
                DrawEllipseInternal(_gfx, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref rect);
                _gfx.Restore();
            }
            break;

            case Core2D.ArrowType.Arrow:
            {
                pt1 = t1.Transform(new XPoint(x1, y1));
                var p11 = t1.Transform(new XPoint(x1 - sizeX1, y1 + sizeY1));
                var p21 = t1.Transform(new XPoint(x1, y1));
                var p12 = t1.Transform(new XPoint(x1 - sizeX1, y1 - sizeY1));
                var p22 = t1.Transform(new XPoint(x1, y1));
                DrawLineInternal(_gfx, strokeStartArrow, sas.IsStroked, ref p11, ref p21);
                DrawLineInternal(_gfx, strokeStartArrow, sas.IsStroked, ref p12, ref p22);
            }
            break;
            }

            double radiusX2 = eas.RadiusX;
            double radiusY2 = eas.RadiusY;
            double sizeX2   = 2.0 * radiusX2;
            double sizeY2   = 2.0 * radiusY2;

            switch (eas.ArrowType)
            {
            default:
            case Core2D.ArrowType.None:
            {
                pt2 = new XPoint(x2, y2);
            }
            break;

            case Core2D.ArrowType.Rectangle:
            {
                pt2 = t2.Transform(new XPoint(x2 - sizeX2, y2));
                var rect = new XRect(x2 - sizeX2, y2 - radiusY2, sizeX2, sizeY2);
                _gfx.Save();
                _gfx.RotateAtTransform(a2, c2);
                DrawRectangleInternal(_gfx, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref rect);
                _gfx.Restore();
            }
            break;

            case Core2D.ArrowType.Ellipse:
            {
                pt2 = t2.Transform(new XPoint(x2 - sizeX2, y2));
                _gfx.Save();
                _gfx.RotateAtTransform(a2, c2);
                var rect = new XRect(x2 - sizeX2, y2 - radiusY2, sizeX2, sizeY2);
                DrawEllipseInternal(_gfx, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref rect);
                _gfx.Restore();
            }
            break;

            case Core2D.ArrowType.Arrow:
            {
                pt2 = t2.Transform(new XPoint(x2, y2));
                var p11 = t2.Transform(new XPoint(x2 - sizeX2, y2 + sizeY2));
                var p21 = t2.Transform(new XPoint(x2, y2));
                var p12 = t2.Transform(new XPoint(x2 - sizeX2, y2 - sizeY2));
                var p22 = t2.Transform(new XPoint(x2, y2));
                DrawLineInternal(_gfx, strokeEndArrow, eas.IsStroked, ref p11, ref p21);
                DrawLineInternal(_gfx, strokeEndArrow, eas.IsStroked, ref p12, ref p22);
            }
            break;
            }

            _gfx.DrawLine(strokeLine, pt1, pt2);
        }
Beispiel #34
0
 private static void DrawText(string text, XGraphics formGfx, XFont font, XSolidBrush color, double x, double y)
 {
     formGfx.DrawString(text, font, color, x, y, XStringFormats.TopLeft);
 }
Beispiel #35
0
        public FileStreamResult CreatePDF(int invoiceNumber, HttpContext context)
        {
            Invoice            selected    = null;
            List <InvoiceItem> itemList    = null;
            List <Product>     productList = new List <Product>();
            Debtor             Debtor      = null;

            try
            {
                selected = _context.Invoices.Single(p => p.InvoiceNumber == invoiceNumber);
                itemList = _context.InvoiceItems.Where(i => i.InvoiceNumber == selected.InvoiceNumber).ToList();
                Debtor   = _context.Debtors.Single(d => d.DebtorID == selected.DebtorID);

                foreach (var inv_item in itemList)
                {
                    Product product = _context.Products.Single(p => p.ProductID == inv_item.ProductID);
                    productList.Add(product);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

            /*--------------------------------------------------------------------------*/
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

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

            page.Orientation = PdfSharp.PageOrientation.Portrait;
            page.Size        = PdfSharp.PageSize.A4;

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

            /*--------------------------------------------------------------------------*/
            // Create a font
            XFont bigFont       = new XFont("Arial", 25, XFontStyle.Bold);
            XFont textFont      = new XFont("Arial", 12, XFontStyle.Regular);
            XFont textFontBold  = new XFont("Arial", 11, XFontStyle.Bold);
            XFont infoFont      = new XFont("Arial", 11, XFontStyle.Regular);
            XFont infoFontSmall = new XFont("Arial", 9, XFontStyle.Regular);
            XFont infoFontLarge = new XFont("Arial", 13, XFontStyle.Bold);

            //Margins
            int leftMargin   = 40;
            int rightMargin  = Convert.ToInt32(page.Width.Point) - 175;
            int topMargin    = 40;
            int bottomMargin = Convert.ToInt32(page.Height.Point) - 40;

            /*--------------------------------------------------------------------------*/
            //Strings and image
            string fname    = Debtor.FirstName;
            string lname    = Debtor.LastName;
            string dAddress = Debtor.Address;
            string dCity    = Debtor.PostalCode + " " + Debtor.City;
            string dCountry = Debtor.Country;

            string logo    = settings.Logo;
            bool   useLogo = settings.UseLogo;
            string email   = settings.Email;
            string company = settings.CompanyName;
            string web     = settings.Website;
            string name    = "";
            string address = settings.Address;
            string city    = settings.PostalCode + " | " + settings.City;
            string country = settings.Country;
            string phone   = settings.Phone;
            string btw     = settings.CommerceNumber;
            string kvk     = settings.CompanyNumber;
            string prefix  = settings.Prefix;

            string[] words = fname.Split(' ');

            for (int i = 0; i < words.Length; i++)
            {
                name += words[i].ElementAt(0);
            }

            name += ". " + lname;

            //Company name or logo
            if (useLogo)
            {
                XImage img       = XImage.FromGdiPlusImage(Image.FromFile(_env.WebRootPath + @"\images\" + logo));
                int    imgMargin = Convert.ToInt32(page.Width.Point) - img.PixelWidth;
                gfx.DrawImage(img, new XRect(imgMargin - 40, 22, 240, 75));
            }
            else
            {
                tf.DrawString(company, bigFont, XBrushes.Black, new XRect(rightMargin, topMargin, 280, 20), XStringFormats.TopLeft);
            }

            /*--------------------------------------------------------------------------*/
            //Company info rows
            tf.DrawString("Addr:", infoFont, XBrushes.Black, new XRect(leftMargin + 0, topMargin, 24, 20), XStringFormats.TopLeft);
            tf.DrawString("Tel:", infoFont, XBrushes.Black, new XRect(leftMargin + 7, topMargin + 43, 24, 20), XStringFormats.TopLeft);
            tf.DrawString("Email:", infoFont, XBrushes.Black, new XRect(leftMargin - 4, topMargin + 58, 24, 20), XStringFormats.TopLeft);
            tf.DrawString("Tax Nr:", infoFont, XBrushes.Black, new XRect(leftMargin - 9, topMargin + 73, 40, 20), XStringFormats.TopLeft);
            tf.DrawString("Company:", infoFont, XBrushes.Black, new XRect(leftMargin - 24, topMargin + 88, 24, 20), XStringFormats.TopLeft);
            tf.DrawString("Web:", infoFont, XBrushes.Black, new XRect(leftMargin + 1, topMargin + 103, 24, 20), XStringFormats.TopLeft);

            //Company info
            tf.DrawString(address, infoFont, XBrushes.Black, new XRect(leftMargin + 44, topMargin, 280, 20), XStringFormats.TopLeft);
            tf.DrawString(city, infoFont, XBrushes.Black, new XRect(leftMargin + 44, topMargin + 13, 280, 20), XStringFormats.TopLeft);
            tf.DrawString(country, infoFont, XBrushes.Black, new XRect(leftMargin + 44, topMargin + 27, 280, 20), XStringFormats.TopLeft);
            tf.DrawString(phone, infoFont, XBrushes.Black, new XRect(leftMargin + 44, topMargin + 43, 280, 20), XStringFormats.TopLeft);
            tf.DrawString(email, infoFont, XBrushes.Black, new XRect(leftMargin + 44, topMargin + 58, 280, 20), XStringFormats.TopLeft);
            tf.DrawString(kvk, infoFont, XBrushes.Black, new XRect(leftMargin + 44, topMargin + 73, 280, 20), XStringFormats.TopLeft);
            tf.DrawString(btw, infoFont, XBrushes.Black, new XRect(leftMargin + 44, topMargin + 88, 280, 20), XStringFormats.TopLeft);
            tf.DrawString(web, infoFont, XBrushes.Black, new XRect(leftMargin + 44, topMargin + 103, 280, 20), XStringFormats.TopLeft);

            /*------------------------------------------*/
            //invoice info rows
            tf.DrawString("Invoice Nr:", textFont, XBrushes.Black, new XRect(leftMargin, topMargin + 255, 100, 20), XStringFormats.TopLeft);
            tf.DrawString("Invoice Date:", textFont, XBrushes.Black, new XRect(leftMargin, topMargin + 268, 100, 20), XStringFormats.TopLeft);

            //invoice info
            tf.DrawString(prefix + selected.InvoiceNumber.ToString(), textFont, XBrushes.Black, new XRect(leftMargin + 95, topMargin + 255, 100, 20), XStringFormats.TopLeft);
            tf.DrawString(selected.CreatedOn.ToString("dd-MM-yyyy"), textFont, XBrushes.Black, new XRect(leftMargin + 95, topMargin + 268, 100, 20), XStringFormats.TopLeft);

            /*------------------------------------------*/
            //debtor info rows
            tf.DrawString("Invoice", bigFont, XBrushes.Black, new XRect(leftMargin - 2, topMargin + 150, 80, 35), XStringFormats.TopLeft);

            tf.DrawString(name, textFont, XBrushes.Black, new XRect(rightMargin - 40, topMargin + 150, 160, 20), XStringFormats.TopLeft);
            tf.DrawString(dAddress, textFont, XBrushes.Black, new XRect(rightMargin - 40, topMargin + 165, 200, 20), XStringFormats.TopLeft);
            tf.DrawString(dCity, textFont, XBrushes.Black, new XRect(rightMargin - 40, topMargin + 180, 200, 20), XStringFormats.TopLeft);
            tf.DrawString(dCountry, textFont, XBrushes.Black, new XRect(rightMargin - 40, topMargin + 195, 200, 20), XStringFormats.TopLeft);

            /*------------------------------------------*/
            //Add divider between invoice info and message
            XColor color = new XColor();

            color.R = 0;
            color.G = 0;
            color.B = 0;

            int rightMargin2 = Convert.ToInt32(page.Width.Point) - 40;

            XPen  pen = new XPen(color);
            Point a   = new Point(leftMargin, topMargin + 290);
            Point b   = new Point(rightMargin2, topMargin + 290);

            gfx.DrawLine(pen, a, b);

            /*--------------------------------------------------------------------------*/
            //invoice message
            string message = "Hereby we bring you in charge:";

            tf.DrawString(message, textFont, XBrushes.Black, new XRect(leftMargin, topMargin + 305, rightMargin2, 20), XStringFormats.TopLeft);

            /*--------------------------------------------------------------------------*/
            int yLoc = topMargin + 345;

            //table header
            XPoint th1 = new XPoint(leftMargin, yLoc);
            XPoint th2 = new XPoint(rightMargin2, yLoc + 14);

            XBrush brush = new XSolidBrush(XColor.FromArgb(255, 255, 255));
            XRect  thead = new XRect(th1, th2);

            gfx.DrawRectangle(pen, brush, thead);

            //Table dividers
            Point d1 = new Point(leftMargin + 220, yLoc);
            Point d2 = new Point(leftMargin + 220, yLoc + 14);

            gfx.DrawLine(pen, d1, d2);

            Point d3 = new Point(leftMargin + 270, yLoc);
            Point d4 = new Point(leftMargin + 270, yLoc + 14);

            gfx.DrawLine(pen, d3, d4);

            Point d5 = new Point(leftMargin + 360, yLoc);
            Point d6 = new Point(leftMargin + 360, yLoc + 14);

            gfx.DrawLine(pen, d5, d6);

            Point d7 = new Point(rightMargin2 - 96, yLoc);
            Point d8 = new Point(rightMargin2 - 96, yLoc + 14);

            gfx.DrawLine(pen, d7, d8);

            /*--------------------------------------------------------------------------*/
            //Columns
            tf.DrawString("Product", textFontBold, XBrushes.Black, new XRect(leftMargin + 2, yLoc + 1, 188, 15), XStringFormats.TopLeft);
            tf.DrawString("Qnt.", textFontBold, XBrushes.Black, new XRect(leftMargin + 224, yLoc + 1, 25, 15), XStringFormats.TopLeft);
            tf.DrawString("Price", textFontBold, XBrushes.Black, new XRect(leftMargin + 274, yLoc + 1, 60, 15), XStringFormats.TopLeft);
            tf.DrawString("Tax", textFontBold, XBrushes.Black, new XRect(leftMargin + 364, yLoc + 1, 25, 15), XStringFormats.TopLeft);
            tf.DrawString("Total", textFontBold, XBrushes.Black, new XRect(rightMargin2 - 92, yLoc + 1, 60, 15), XStringFormats.TopLeft);

            /*--------------------------------------------------------------------------*/
            int y = topMargin + 359;

            decimal subTotal   = 0;
            decimal total      = 0;
            decimal btwDecimal = 0;

            for (int i = 0; i < productList.Count; i++)
            {
                Product     product = productList[i];
                InvoiceItem pItem   = itemList.Where(l => l.ProductID == product.ProductID &&
                                                     l.InvoiceNumber == selected.InvoiceNumber).FirstOrDefault();

                int tax = 100 + product.TaxPercentage;

                total      += (decimal)(product.Price * pItem.Amount);
                subTotal   += (total * 100) / tax;
                btwDecimal += (total - subTotal);

                /*--------------------------------------------*/
                //Product column
                XPoint t1 = new XPoint(leftMargin, y);
                XPoint t2 = new XPoint(leftMargin + 220, y + 15);

                XRect tProduct = new XRect(t1, t2);
                gfx.DrawRectangle(pen, brush, tProduct);
                /*--------------------------------------------*/
                //Quantity column
                XPoint t3 = new XPoint(leftMargin + 220, y);
                XPoint t4 = new XPoint(leftMargin + 270, y + 15);

                XRect tQnt = new XRect(t3, t4);
                gfx.DrawRectangle(pen, brush, tQnt);
                /*--------------------------------------------*/
                //Price column
                XPoint t5 = new XPoint(leftMargin + 270, y);
                XPoint t6 = new XPoint(leftMargin + 360, y + 15);

                XRect tPrice = new XRect(t5, t6);
                gfx.DrawRectangle(pen, brush, tPrice);
                /*--------------------------------------------*/
                //BTW column
                XPoint t7 = new XPoint(leftMargin + 360, y);
                XPoint t8 = new XPoint(leftMargin + 419, y + 15);

                XRect tBTW = new XRect(t7, t8);
                gfx.DrawRectangle(pen, brush, tBTW);
                /*--------------------------------------------*/
                //Total column
                XPoint t9  = new XPoint(rightMargin2 - 96, y);
                XPoint t10 = new XPoint(rightMargin2, y + 15);

                XRect tTotal = new XRect(t9, t10);
                gfx.DrawRectangle(pen, brush, tTotal);
                /*--------------------------------------------*/
                //Text
                tf.DrawString(product.Name, infoFont, XBrushes.Black, new XRect(leftMargin + 2, y + 2, 188, 15), XStringFormats.TopLeft);
                tf.DrawString(pItem.Amount.ToString(), infoFont, XBrushes.Black, new XRect(leftMargin + 224, y + 2, 188, 15), XStringFormats.TopLeft);
                tf.DrawString("€ " + string.Format("{0:N2}", product.Price), infoFont, XBrushes.Black, new XRect(leftMargin + 274, y + 2, 188, 15), XStringFormats.TopLeft);
                tf.DrawString(product.TaxPercentage + "%", infoFont, XBrushes.Black, new XRect(leftMargin + 364, y + 2, 188, 15), XStringFormats.TopLeft);
                tf.DrawString("€ " + string.Format("{0:N2}", (product.Price * pItem.Amount)), infoFont, XBrushes.Black, new XRect(rightMargin2 - 92, y + 2, 188, 15), XStringFormats.TopLeft);
                /*--------------------------------------------*/

                y = y + 15;
            }
            /*--------------------------------------------------------------------------*/
            //Text
            tf.DrawString("Subtotal", infoFont, XBrushes.Black, new XRect(rightMargin - 25, bottomMargin - 150, 45, 15), XStringFormats.TopLeft);
            tf.DrawString("Tax", infoFont, XBrushes.Black, new XRect(rightMargin - 25, bottomMargin - 135, 45, 15), XStringFormats.TopLeft);
            tf.DrawString("Total", infoFont, XBrushes.Black, new XRect(rightMargin - 25, bottomMargin - 114, 65, 15), XStringFormats.TopLeft);

            //Divider with plus sign
            Point subA = new Point(rightMargin - 25, bottomMargin - 118);
            Point subB = new Point(rightMargin + 115, bottomMargin - 118);

            gfx.DrawLine(pen, subA, subB);
            tf.DrawString("+", infoFont, XBrushes.Black, new XRect(rightMargin + 117, bottomMargin - 123.5, 5, 5), XStringFormats.TopLeft);

            //Numbers
            tf.DrawString("€" + " " + string.Format("{0:N2}", subTotal), infoFont, XBrushes.Black, new XRect(rightMargin + 25, bottomMargin - 150, 65, 15), XStringFormats.TopLeft);
            tf.DrawString("€" + " " + string.Format("{0:N2}", btwDecimal), infoFont, XBrushes.Black, new XRect(rightMargin + 25, bottomMargin - 135, 65, 15), XStringFormats.TopLeft);
            tf.DrawString("€" + " " + string.Format("{0:N2}", total), infoFont, XBrushes.Black, new XRect(rightMargin + 25, bottomMargin - 114, 65, 15), XStringFormats.TopLeft);
            /*--------------------------------------------------------------------------*/
            //Disclaimer
            int width  = (Convert.ToInt32(page.Width.Point) - 40);
            int height = 50;

            tf.DrawString("We kindly request you to transfer the amount due within 30 days, stating the invoice number"
                          + "\n" + "Our terms and conditions apply to all services",
                          infoFontSmall, XBrushes.Black, new XRect(leftMargin, bottomMargin - 10, width, height),
                          XStringFormats.TopLeft);
            /*--------------------------------------------------------------------------*/
            // Save the document...
            string fileName = "invoice_" + invoiceNumber + ".pdf";

            MemoryStream stream = new MemoryStream();

            document.Save(stream, false);

            //stream.Position = 0;
            FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf");

            fileStreamResult.FileDownloadName = fileName;

            return(fileStreamResult);

            //End of method
        }