コード例 #1
0
        public static void CreateResultPDF(PictureBoxExt picBox, Client.DataAccess c, QualificationRoundSet qRnd, List <ComboBoxFlights> qRndFlights, String pathToPDF)
        {
            int counter = 0;
            List <FlightSet> tempList = new List <FlightSet>();

            foreach (ComboBoxFlights cbct in qRndFlights)
            {
                GC.Collect();
                PdfDocument doc = new PdfDocument();
                doc.Info.Author       = "*****@*****.**";
                doc.Info.Keywords     = "ANRL Results Printout";
                doc.Info.Subject      = "Results Printout generated from ANRL Client on " + DateTime.Now.ToString();
                doc.Info.Title        = "Results Printout";
                doc.Options.ColorMode = PdfColorMode.Cmyk;
                doc.Language          = "EN";
                doc.PageLayout        = PdfPageLayout.SinglePage;

                tempList.Clear();
                tempList.Add(cbct.flight);
                picBox.SetData(tempList);

                PdfPage page = doc.AddPage();
                page.Orientation = PdfSharp.PageOrientation.Landscape;
                page.Size        = PdfSharp.PageSize.A4;
                double scaleFactor = 2.0;

                XGraphics      gfx  = XGraphics.FromPdfPage(page);
                XTextFormatter tf   = new XTextFormatter(gfx);
                XRect          rect = new XRect();

                AddLogo(gfx, page);

                XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage.VaryQualityLevel());

                double distX = picBox.GetXDistanceKM() / scaleFactor; //1:200 000 in cm
                double distY = picBox.GetYDistanceKM() / scaleFactor; //1:200 000 in cm

                gfx.DrawImage(image, XUnit.FromCentimeter(2).Point, XUnit.FromCentimeter(3).Point, page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter));

                #region Header data (Competition, Qualification round, Crew)

                gfx.DrawString("Competition: " + c.SelectedCompetition.Name,
                               verdana13Bold, XBrushes.Black,
                               new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(1.5)));

                gfx.DrawString("Q-Round: " + qRnd.Name,
                               verdana11Bold, XBrushes.Black,
                               new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2.1)));

                gfx.DrawString("Crew: " + getTeamDsc(c, cbct.flight),
                               verdana11Bold, XBrushes.Black,
                               new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2.7)));

                #endregion

                #region Write table with Penalty points

                int sum        = 0;
                int line       = 0;
                int offsetLine = 20;
                gfx.DrawString("Points ", verdana11Bold, XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3)));
                gfx.DrawString("Reason ", verdana11Bold, XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3)));

                line++;
                foreach (PenaltySet penalty in cbct.flight.PenaltySet)
                {
                    sum += penalty.Points;

                    // Penalty points, aligned right
                    rect = new XRect(
                        new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3 + line * 0.4)),
                        new XPoint(XUnit.FromCentimeter(offsetLine + 1.3), XUnit.FromCentimeter(3.0 + line * 0.4 + 0.4)));
                    //gfx.DrawRectangle(XBrushes.Yellow, rect);
                    tf.Alignment = XParagraphAlignment.Right;
                    tf.DrawString(penalty.Points.ToString(), verdana9Reg, XBrushes.Black, rect, XStringFormats.TopLeft);
                    //gfx.DrawString(penalty.Points.ToString(), verdana9Reg, XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3 + line * 0.4)));

                    // Penalty explanation, aligned left
                    //List<String> reason = getWrapped(penalty.Reason);
                    List <string> reason = penalty.Reason.SplitOn(40);
                    foreach (String s in reason)
                    {
                        rect = new XRect(
                            new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3.0 + line * 0.4)),
                            new XPoint(XUnit.FromCentimeter(offsetLine + 9), XUnit.FromCentimeter(3.0 + line * 0.4 + 0.4)));
                        tf.Alignment = XParagraphAlignment.Left;
                        //gfx.DrawRectangle(XBrushes.Yellow, rect);
                        tf.DrawString(s, verdana9Reg, XBrushes.Black, rect, XStringFormats.TopLeft);
                        //gfx.DrawString(s, verdana9Reg, XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3 + line * 0.4)));
                        line++;
                    }
                }
                line++;

                // Penalty total points, aligned right
                rect = new XRect(
                    new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3 + line * 0.4)),
                    new XPoint(XUnit.FromCentimeter(offsetLine + 1.3), XUnit.FromCentimeter(3.0 + line * 0.4 + 0.4)));
                tf.Alignment = XParagraphAlignment.Right;
                tf.DrawString(sum.ToString(), verdana9Bold, XBrushes.Black, rect, XStringFormats.TopLeft);
                // gfx.DrawString(sum.ToString(), verdana10Bold, XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine), XUnit.FromCentimeter(3 + line * 0.4)));

                // Penalty text, aligned left
                rect = new XRect(
                    new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3.0 + line * 0.4)),
                    new XPoint(XUnit.FromCentimeter(offsetLine + 9), XUnit.FromCentimeter(3.0 + line * 0.4 + 0.4)));
                tf.Alignment = XParagraphAlignment.Left;
                tf.DrawString("Total Points", verdana9Bold, XBrushes.Black, rect, XStringFormats.TopLeft);
                //gfx.DrawString("Total Points", verdana10Bold, XBrushes.Black, new XPoint(XUnit.FromCentimeter(offsetLine + 2), XUnit.FromCentimeter(3 + line * 0.4)));

                #endregion

                String path = pathToPDF.Replace(".pdf", (counter++ + "_" + getTeamDsc(c, cbct.flight) + ".pdf"));
                doc.Save(path);
                doc.Close();
                Process.Start(path);
            }
        }
コード例 #2
0
        public static void CreateParcourPDF(PDFSize pdfSize, bool showCalcTable, double scaleFactor, PictureBoxExt picBox, Client.DataAccess c, String parcourName, String pathToPDF, String overlayText)
        {
            //PdfDocument doc = new PdfDocument(@"Resources\PDFTemplates\Competition_Map.pdf");
            PdfDocument doc = new PdfDocument();

            doc.Info.Author       = "*****@*****.**";
            doc.Info.Keywords     = "ANRL Parcour Printout";
            doc.Info.Subject      = "Parcour Printout generated from ANRL Client on " + DateTime.Now.ToString();
            doc.Info.Title        = "Parcour Printout";
            doc.Options.ColorMode = PdfColorMode.Cmyk;
            doc.Language          = "EN";
            doc.PageLayout        = PdfPageLayout.SinglePage;

            PdfPage page = doc.AddPage();

            page.Orientation = PdfSharp.PageOrientation.Landscape;
            page.Size        = (PdfSharp.PageSize)pdfSize;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            AddLogo(gfx, page);

            #region Competition and Parcour text

            gfx.DrawString("Competition: " + c.SelectedCompetition.Name,
                           verdana16Bold, XBrushes.Black,
                           new XPoint(XUnit.FromCentimeter(1), XUnit.FromCentimeter(2)));

            gfx.DrawString("Parcour: " + parcourName,
                           verdana14Bold, XBrushes.Black,
                           new XPoint(XUnit.FromCentimeter(1), XUnit.FromCentimeter(3)));

            #endregion

            XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage);

            double distX = picBox.GetXDistanceKM() / scaleFactor;  // ScaleFactor 1.0 = 1:100 000 in cm
            double distY = picBox.GetYDistanceKM() / scaleFactor;

            gfx.DrawImage(image, XUnit.FromCentimeter(1), XUnit.FromCentimeter(4), page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter));

            if (showCalcTable && (int)pdfSize == (int)PdfSharp.PageSize.A4)
            {
                #region  Show calculation table for A4, if wanted

                double startX = 190;

                List <XPoint> points = new List <XPoint>();
                points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40)));
                points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * 5), Unit.FromMillimeter(40)));
                points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * 5), Unit.FromMillimeter(40 + 9)));
                points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40 + 9)));
                points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(40)));
                gfx.DrawLines(XPens.Black, points.ToArray());

                gfx.DrawString("Comp. Nr:",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(40 + 7)));

                gfx.DrawString("Route:",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + 18 * 3 + 1), Unit.FromMillimeter(40 + 7)));

                double startY = 40 + 9 + 5;

                double colWidth  = 18;
                double rowHeight = 9;


                for (int i = 0; i < 16; i++)
                {
                    points = new List <XPoint>();
                    points.Add(new XPoint(Unit.FromMillimeter(startX), Unit.FromMillimeter(startY + i * rowHeight)));
                    points.Add(new XPoint(Unit.FromMillimeter(startX + colWidth * 5), Unit.FromMillimeter(startY + i * rowHeight)));
                    gfx.DrawLines(XPens.Black, points.ToArray());
                }

                for (int i = 0; i < 6; i++)
                {
                    points = new List <XPoint>();
                    points.Add(new XPoint(Unit.FromMillimeter(startX + i * colWidth), Unit.FromMillimeter(startY)));
                    points.Add(new XPoint(Unit.FromMillimeter(startX + i * colWidth), Unit.FromMillimeter(startY + 15 * rowHeight)));
                    gfx.DrawLines(XPens.Black, points.ToArray());
                }

                gfx.DrawString("Dist.",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + colWidth * 1 + 1), Unit.FromMillimeter(startY + 7)));

                gfx.DrawString("TT",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + colWidth * 2 + 1), Unit.FromMillimeter(startY + 7)));

                gfx.DrawString("EET",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + colWidth * 3 + 1), Unit.FromMillimeter(startY + 7)));

                gfx.DrawString("ETO",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + colWidth * 4 + 1), Unit.FromMillimeter(startY + 7)));

                gfx.DrawString("T/O",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 1 + 7)));

                gfx.DrawString("SP",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 2 + 7)));

                for (int i = 3; i < 13; i++)
                {
                    gfx.DrawString("TP" + (i - 3 + 1),
                                   verdana14Bold, XBrushes.Black,
                                   new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * i + 7)));
                }
                gfx.DrawString("FP",
                               verdana14Bold, XBrushes.Black,
                               new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 13 + 7)));

                gfx.DrawImage(XImage.FromFile(@"Resources\Summe.png"),
                              new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 14 + 2)));

                #endregion
            }

            #region Show overlay text (map scale, time, distance etc.)
            if (!string.IsNullOrEmpty(overlayText.Trim()))
            {
                XRect rect = new XRect(XUnit.FromCentimeter(19.0), XUnit.FromCentimeter(1.5), Unit.FromCentimeter(5.0), Unit.FromCentimeter(2.0));
                gfx.DrawRectangle(XBrushes.White, rect);
                XTextFormatter tf = new XTextFormatter(gfx);
                tf.DrawString(overlayText, verdana10Reg, XBrushes.Black, rect, XStringFormats.TopLeft);
            }
            #endregion

            doc.Save(pathToPDF);
            doc.Close();
            Process.Start(pathToPDF);
        }