public static void CreateParcourPDF(ParcourPictureBox 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.A4; XGraphics gfx = XGraphics.FromPdfPage(page); AddLogo(gfx, page); gfx.DrawString("Competition: " + c.SelectedCompetition.Name, new XFont("Verdana", 16, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2))); gfx.DrawString("Parcour: " + parcourName, new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(3))); XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage); double distX = picBox.GetXDistanceKM() / 2;//1:200 000 in cm double distY = picBox.GetYDistanceKM() / 2;//1:200 000 in cm gfx.DrawImage(image, XUnit.FromCentimeter(1), XUnit.FromCentimeter(4), page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter)); 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()); for (int i = 0; i < 5; i++) { if (i == 1) continue; points = new List<XPoint>(); points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * i), Unit.FromMillimeter(40))); points.Add(new XPoint(Unit.FromMillimeter(startX + 18 * i), Unit.FromMillimeter(40 + 9))); gfx.DrawLines(XPens.Black, points.ToArray()); } gfx.DrawString("Comp. Nr:", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(40 + 7))); gfx.DrawString("Track:", new XFont("Verdana", 14, XFontStyle.Bold), 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.", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + colWidth * 1 + 1), Unit.FromMillimeter(startY + 7))); gfx.DrawString("TT", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + colWidth * 2 + 1), Unit.FromMillimeter(startY + 7))); gfx.DrawString("EET", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + colWidth * 3 + 1), Unit.FromMillimeter(startY + 7))); gfx.DrawString("ETO", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + colWidth * 4 + 1), Unit.FromMillimeter(startY + 7))); gfx.DrawString("T/O", new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * 1 + 7))); gfx.DrawString("SP", new XFont("Verdana", 14, XFontStyle.Bold), 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), new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(Unit.FromMillimeter(startX + 1), Unit.FromMillimeter(startY + rowHeight * i + 7))); } gfx.DrawString("FP", new XFont("Verdana", 14, XFontStyle.Bold), 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))); if (overlayText != null && overlayText != "") { XRect rect = new XRect(new XPoint(Unit.FromMillimeter(startX - 80 - 2), Unit.FromMillimeter(startY + rowHeight * 14 + 2 - 16)), new XSize(Unit.FromCentimeter(8), Unit.FromCentimeter(3.6))); gfx.DrawRectangle(XBrushes.White, rect); XTextFormatter tf = new XTextFormatter(gfx); tf.DrawString(overlayText, new XFont("Verdana", 13, XFontStyle.Bold), XBrushes.Black, rect, XStringFormats.TopLeft); } doc.Save(pathToPDF); doc.Close(); Process.Start(pathToPDF); }
public static void CreateParcourPDF100k(ParcourPictureBox picBox, Client.DataAccess c, String parcourName, String pathToPDF, String overlayText) { 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.A3; XGraphics gfx = XGraphics.FromPdfPage(page); AddLogo(gfx, page); gfx.DrawString("Competition: " + c.SelectedCompetition.Name, new XFont("Verdana", 16, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(2))); gfx.DrawString("Parcour: " + parcourName, new XFont("Verdana", 14, XFontStyle.Bold), XBrushes.Black, new XPoint(XUnit.FromCentimeter(2), XUnit.FromCentimeter(3))); XImage image = XImage.FromGdiPlusImage(picBox.PrintOutImage); double distX = picBox.GetXDistanceKM();//1:100 000 in cm double distY = picBox.GetYDistanceKM();//1:100 000 in cm gfx.DrawImage(image, XUnit.FromCentimeter(1), XUnit.FromCentimeter(4), page.Width.Point * (distX / page.Width.Centimeter), page.Height.Point * (distY / page.Height.Centimeter)); if (overlayText != null && overlayText != "") { XRect rect = new XRect(new XPoint(Unit.FromCentimeter(page.Width.Centimeter - 8), Unit.FromCentimeter(page.Height.Centimeter-4)), new XSize(Unit.FromCentimeter(8), Unit.FromCentimeter(3.6))); gfx.DrawRectangle(XBrushes.White, rect); XTextFormatter tf = new XTextFormatter(gfx); tf.DrawString(overlayText, new XFont("Verdana", 13, XFontStyle.Bold), XBrushes.Black, rect, XStringFormats.TopLeft); } doc.Save(pathToPDF); doc.Close(); Process.Start(pathToPDF); }