示例#1
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();
        }
示例#2
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();
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="img"></param>
        /// <param name="path"></param>
        /// <param name="exportItem"></param>
        /// <returns>byte[]</returns>
        private byte[] createPdf(Image img, MapExportItem exportItem, string fontName)
        {
            PdfDocument document = new PdfDocument();
            PdfPage     page     = document.AddPage();

            page.Size        = GetPageSize(exportItem);
            page.Orientation = exportItem.orientation == "L" ? PdfSharp.PageOrientation.Landscape : PdfSharp.PageOrientation.Portrait;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            int    scale      = int.Parse(exportItem.scale);
            double length     = (1.0 / scale);
            double unitLength = (length * 2.82e3);

            Dictionary <int, string> scaleBarTexts = new Dictionary <int, string>()
            {
                { 250, "25 m" },
                { 500, "50 m" },
                { 1000, "50 m" },
                { 2500, "100 m" },
                { 5000, "200 m" },
                { 10000, "500 m" },
                { 25000, "1 km" },
                { 50000, "2 km" },
                { 100000, "5 km" },
                { 250000, "10 km" }
            };

            Dictionary <int, int> scaleBarLengths = new Dictionary <int, int>()
            {
                { 250, 25 },
                { 500, 50 },
                { 1000, 50 },
                { 2500, 100 },
                { 5000, 200 },
                { 10000, 500 },
                { 25000, 1000 },
                { 50000, 2000 },
                { 100000, 5000 },
                { 250000, 10000 }
            };

            int    displayLength = GetDisplayLength(unitLength, scaleBarLengths, scale);
            string displayText   = GetDisplayText(unitLength, scaleBarTexts, scale);

            // adding support for different layouts
            int layout = ConfigurationManager.AppSettings["exportLayout"] != null?int.Parse(ConfigurationManager.AppSettings["exportLayout"]) : 1;

            if (layout == 1)//original layout
            {
                //origina code from github

                this.drawImage(gfx, img, 0, 0, page);

                List <string> copyrights = new List <string>();
                if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
                {
                    copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
                }

                string infoText = String.Empty;
                if (ConfigurationManager.AppSettings["exportInfoText"] != null)
                {
                    infoText = ConfigurationManager.AppSettings["exportInfoText"];
                }

                int height = 45 + copyrights.Count * 10;

                XPoint[] points = new XPoint[]
                {
                    new XPoint(12, 12),
                    new XPoint(12, height),
                    new XPoint(55 + displayLength, height),
                    new XPoint(55 + displayLength, 12),
                    new XPoint(12, 12)
                };

                gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);

                this.drawText(gfx, fontName, String.Format("Skala 1:{0}", exportItem.scale), 15, 25);
                gfx.DrawLine(XPens.Black, new XPoint(15, 32), new XPoint(15 + displayLength, 32));
                gfx.DrawLine(XPens.Black, new XPoint(15, 28), new XPoint(15, 36));
                gfx.DrawLine(XPens.Black, new XPoint(15 + displayLength, 28), new XPoint(15 + displayLength, 36));
                this.drawText(gfx, fontName, displayText, 20 + displayLength, 35);

                var y = (int)page.Height.Point - 15;

                this.drawText(gfx, fontName, infoText, 15, y);

                int i = 0;
                copyrights.ForEach(copyright =>
                {
                    int start = 50;
                    this.drawText(gfx, fontName, String.Format("© {0}", copyright), 15, start + i * 10);
                    i++;
                });

                XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));
                gfx.DrawImage(logo, (gfx.PageSize.Width - logo.PixelWidth / 2) - 12, 12, logo.PixelWidth / 2, logo.PixelHeight / 2);

                byte[] bytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    document.Save(ms);
                    bytes = ReadFully(ms);
                }

                return(bytes);
            }
            else if (layout == 2)//new layout
            {
                // x and y 0 0(top left corner?)-> change
                this.drawImage(gfx, img, 33, 33, page);

                List <string> copyrights = new List <string>();
                if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
                {
                    copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
                }

                string infoText = String.Empty;
                if (ConfigurationManager.AppSettings["exportInfoText"] != null)
                {
                    infoText = ConfigurationManager.AppSettings["exportInfoText"];
                }

                int height = 1;

                XPoint[] points = new XPoint[]
                {
                    new XPoint(12, 12),
                    new XPoint(12, height),
                    new XPoint(55 + displayLength, height),
                    new XPoint(55 + displayLength, 12),
                    new XPoint(12, 12)
                };

                gfx.DrawPolygon(XBrushes.White, points, XFillMode.Winding);
                // x y
                this.drawText(gfx, fontName, String.Format("Skala 1:{0}", exportItem.scale), 33, (int)page.Height.Point - 23, 8);
                gfx.DrawLine(XPens.Black, new XPoint(33, (int)page.Height.Point - 18), new XPoint(33 + displayLength, (int)page.Height.Point - 18));
                gfx.DrawLine(XPens.Black, new XPoint(33, (int)page.Height.Point - 15), new XPoint(33, (int)page.Height.Point - 21));
                gfx.DrawLine(XPens.Black, new XPoint(33 + displayLength / 2, (int)page.Height.Point - 17), new XPoint(33 + displayLength / 2, (int)page.Height.Point - 19));
                gfx.DrawLine(XPens.Black, new XPoint(33 + displayLength, (int)page.Height.Point - 15), new XPoint(33 + displayLength, (int)page.Height.Point - 21));
                this.drawText(gfx, fontName, displayText, 38 + displayLength, (int)page.Height.Point - 16, 8);

                var y = (int)page.Height.Point - 2;

                this.drawText(gfx, fontName, infoText, 33, y, 8);

                int i = 0;
                copyrights.ForEach(copyright =>
                {
                    int start = (int)page.Height.Point - 15;
                    this.drawText(gfx, fontName, String.Format("© {0}", copyright), (int)page.Width.Point - 100, start + i * 10, 8);
                    i++;
                });

                XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));
                gfx.DrawImage(logo, (gfx.PageSize.Width - logo.PixelWidth / 5) - 33, 3.5, logo.PixelWidth / 5, logo.PixelHeight / 5);

                byte[] bytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    document.Save(ms);
                    bytes = ReadFully(ms);
                }

                return(bytes);
            }
            else if (layout == 3)
            {
                List <string> copyrights = new List <string>();
                if (ConfigurationManager.AppSettings["exportCopyrightText"] != null)
                {
                    copyrights = ConfigurationManager.AppSettings["exportCopyrightText"].Split(',').ToList();
                }

                string infoText = String.Empty;
                if (ConfigurationManager.AppSettings["exportInfoText"] != null)
                {
                    infoText = ConfigurationManager.AppSettings["exportInfoText"];
                }

                // Get logoimage
                XImage logo = XImage.FromFile(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "assets", "logo.png"));

                // Set positions, areas, brushes and pens
                XRect margins   = new XRect(33, 33, 33, 33);
                XSize stampSize = new XSize(200, 120);

                // Calculate positions and areas
                XRect  drawingArea        = new XRect(margins.Left, margins.Top, page.Width - (margins.Left + margins.Width), page.Height - (margins.Top + margins.Height));
                XRect  stampArea          = new XRect(new XPoint(drawingArea.Left + 15, drawingArea.Bottom - stampSize.Height - 15), stampSize);
                XRect  logoArea           = new XRect(new XPoint(stampArea.Left + 10, stampArea.Top + 10), new XPoint(stampArea.Right - 10, stampArea.Top + 50));
                XPoint signingLine        = new XPoint(stampArea.Left + 10, logoArea.Bottom + 30);
                XPoint copyrightPosition  = new XPoint(drawingArea.Right - 3, drawingArea.Bottom - 3);
                XPoint scalLegendPosition = new XPoint(stampArea.Left + 10, signingLine.Y + 20);

                double scaling;
                var    scalingY = logo.PointHeight / logoArea.Height;
                var    scalingX = logo.PointWidth / logoArea.Width;
                if (scalingX < scalingY)
                {
                    scaling = scalingX;
                }
                else
                {
                    scaling = scalingY;
                }

                // Pens, Brushes and colors
                XColor mainColor = XColor.FromArgb(0, 119, 188);
                XPen   thickPen  = new XPen(mainColor, 1);
                XPen   thinPen   = new XPen(mainColor, 0.5);

                // Draw map
                this.drawImage(gfx, img, drawingArea.Left, drawingArea.Top, page);

                // Put a border around map
                gfx.DrawRectangle(thickPen, drawingArea);

                // Draw a white "stamparea"
                gfx.DrawRectangle(thickPen, XBrushes.White, stampArea);
                // Draw logo
                gfx.DrawImage(logo, logoArea.Left, logoArea.Top, logo.PointWidth / scaling, logo.PointHeight / scaling);
                // Draw "signing line"

                gfx.DrawLine(thinPen, signingLine, new XPoint(stampArea.Right - 10, signingLine.Y));

                // Draw scale legend
                gfx.DrawLine(XPens.Black, new XPoint(scalLegendPosition.X, scalLegendPosition.Y), new XPoint(scalLegendPosition.X + displayLength, scalLegendPosition.Y));
                gfx.DrawLine(XPens.Black, new XPoint(scalLegendPosition.X, scalLegendPosition.Y - 3), new XPoint(scalLegendPosition.X, scalLegendPosition.Y + 3));
                gfx.DrawLine(XPens.Black, new XPoint(scalLegendPosition.X + displayLength / 2, scalLegendPosition.Y - 2), new XPoint(scalLegendPosition.X + displayLength / 2, scalLegendPosition.Y + 2));
                gfx.DrawLine(XPens.Black, new XPoint(scalLegendPosition.X + displayLength, scalLegendPosition.Y - 3), new XPoint(scalLegendPosition.X + displayLength, scalLegendPosition.Y + 3));
                XFont font = new XFont(fontName, 6);
                gfx.DrawString(String.Format("Skala 1:{0}", exportItem.scale), font, XBrushes.Black, new XRect(new XPoint(scalLegendPosition.X, scalLegendPosition.Y - 12), new XPoint(scalLegendPosition.X + displayLength, scalLegendPosition.Y - 2)), XStringFormats.TopLeft);
                gfx.DrawString(displayText, font, XBrushes.Black, (int)scalLegendPosition.X + displayLength + 10, (int)scalLegendPosition.Y + 2);

                // Draw infotext
                this.drawText(gfx, fontName, infoText, (int)stampArea.Left + 10, (int)stampArea.Bottom - 5, 5);

                // Draw copyright notes
                int i = 0;
                copyrights.ForEach(copyright =>
                {
                    if (i > 0)
                    {
                        copyrightPosition.Offset(0, -10);
                    }
                    gfx.DrawString(String.Format("© {0}", copyright), font, XBrushes.Black, copyrightPosition, XStringFormats.BottomRight);

                    i++;
                });


                byte[] bytes;

                using (MemoryStream ms = new MemoryStream())
                {
                    document.Save(ms);
                    bytes = ReadFully(ms);
                }

                return(bytes);
            }

            return(null);
        }