/// <summary>
        /// Tutorial Link http://www.pdfsharp.net/wiki/HelloWorld-sample.ashx
        /// </summary>
        public static void HelloWorld()
        {
            // Create a new PDF document
            PdfDocument document = new PdfDocument();

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

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

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

            // Create a font
            XFont font = new XFont("Verdana", 48, XFontStyle.BoldItalic);

            // Draw the text
            gfx.DrawString("Hello, World!", font, XBrushes.Plum, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);

            //Draw Square
            gfx.DrawLines(XPens.DarkRed, new XPoint[] { new XPoint(200, 500), new XPoint(300, 500), new XPoint(300, 600), new XPoint(200, 600), new XPoint(200, 500) });
            gfx.DrawLines(XPens.DarkRed, new XPoint[] { new XPoint(250, 479.5), new XPoint(320.5, 550), new XPoint(250, 620.5), new XPoint(179.5, 550), new XPoint(250, 479.5) });
            gfx.DrawArc(XPens.DarkRed, new XRect(180, 480, 140, 140), 90, 0);
            //gfx.DrawArc(XPens.DarkCyan, new XRect(180, 485, 145, 145), 90, 0);

            // Save the document...
            const string filename = @"..\..\..\HelloWorld.pdf";

            document.Save(filename);

            // ...and start a viewer.
            Process.Start(filename);
        }
        public override void CreatePDFLayout(XGraphics page, CheckBox checkBox, XRect bounds, double scaleFactor)
        {
            if (checkBox.BackgroundColor != default)
            {
                page.DrawRectangle(checkBox.BackgroundColor.ToXBrush(), bounds);
            }

            var adjustedBounds = new XRect(bounds.Location, new XSize(bounds.Height, bounds.Height));
            var checkPath      = new[]
            {
                new XPoint(adjustedBounds.Width * 0.15, adjustedBounds.Height * 0.3),
                new XPoint(adjustedBounds.Width * 0.3, adjustedBounds.Height * 0.7),
                new XPoint(adjustedBounds.Width * 0.85, adjustedBounds.Height * 0.8)
            };

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
            case Device.macOS:
                if (checkBox.IsChecked)
                {
                    page.DrawEllipse(checkBox.Color.ToXBrush(), adjustedBounds);
                    page.DrawLines(new XPen(XColors.White, scaleFactor * 3), checkPath);
                }
                else
                {
                    page.DrawEllipse(new XPen(checkBox.Color.ToXColor(), scaleFactor), adjustedBounds);
                }

                break;

            case Device.Android:
                if (checkBox.IsChecked)
                {
                    page.DrawRectangle(checkBox.Color.ToXBrush(), adjustedBounds);
                    page.DrawLines(new XPen(XColors.White, scaleFactor * 3), checkPath);
                }
                else
                {
                    page.DrawRectangle(new XPen(checkBox.Color.ToXColor(), scaleFactor), adjustedBounds);
                }

                break;

            case Device.UWP:
            case Device.WPF:
                if (checkBox.IsChecked)
                {
                    page.DrawRectangle(checkBox.Color.ToXBrush(), adjustedBounds);
                    page.DrawLines(new XPen(XColors.LightBlue, scaleFactor * 3), checkPath);
                }
                else
                {
                    page.DrawRectangle(new XPen(checkBox.Color.ToXColor(), scaleFactor), adjustedBounds);
                }

                break;
            }
        }
Exemplo n.º 3
0
        private void DrawCutLine()
        {
            XPen pen = new XPen(XColors.Black, 0.2);

            pen.DashStyle = XDashStyle.Dot;
            //pen.LineCap = XLineCap.Round;
            //pen.LineJoin = XLineJoin.Bevel;
            XUnit midx = _page.Width / 2;

            XPoint[] points =
                new XPoint[] { new XPoint(midx, 0),
                               new XPoint(midx, _page.Height) };
            gfx.DrawLines(pen, points);
        }
Exemplo n.º 4
0
        private void DrawLine(float begxmm, float endxmm, float fromtopmm)
        {
            XPen pen = new XPen(XColors.Black, 1);

            pen.LineCap  = XLineCap.Round;
            pen.LineJoin = XLineJoin.Bevel;
            XPoint[] points =
                new XPoint[] { new XPoint(XUnit.FromMillimeter(begxmm).Point, XUnit.FromMillimeter(fromtopmm).Point), new XPoint(XUnit.FromMillimeter(endxmm).Point, XUnit.FromMillimeter(fromtopmm).Point) };
            gfx.DrawLines(pen, points);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws simple lines.
        /// </summary>
        void RenderPolyLines(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XPen pen = new XPen(XColors.DarkSeaGreen, 6);

            pen.LineCap  = XLineCap.Round;
            pen.LineJoin = XLineJoin.Bevel;
            XPoint[] points =
                new XPoint[] { new XPoint(20, 30), new XPoint(60, 120), new XPoint(90, 20), new XPoint(170, 90), new XPoint(230, 40) };
            gfx.DrawLines(pen, points);
        }
Exemplo n.º 6
0
        static void DrawLines(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "DrawLines");

            XPen pen = new XPen(XColors.DarkSeaGreen, 6);

            pen.LineCap  = XLineCap.Round;
            pen.LineJoin = XLineJoin.Bevel;
            XPoint[] points =
                new XPoint[] { new XPoint(20, 30), new XPoint(60, 120), new XPoint(90, 20), new XPoint(170, 90), new XPoint(230, 40) };
            gfx.DrawLines(pen, points);

            EndBox(gfx);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Demonstrates the use of XGraphics.DrawLines.
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            //base.RenderPage(gfx);

            XPoint[] points = new XPoint[]
            {
                new XPoint(50, 100),
                new XPoint(450, 120),
                new XPoint(550, 300),
                new XPoint(150, 380),
                new XPoint(120, 190),
            };

            gfx.DrawLines(properties.Pen2.Pen, points);
        }
        /// <summary>
        /// Draws the content of the line plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;

            XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            XGraphics      gfx   = this.rendererParms.Graphics;
            XGraphicsState state = gfx.Save();

            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            //TODO null-Values müssen berücksichtigt werden.
            //     Verbindungspunkte können fehlen, je nachdem wie null-Values behandelt werden sollen.
            //     (NotPlotted, Interpolate etc.)

            // Draw lines and markers for each data series.
            XMatrix matrix = cri.plotAreaRendererInfo.matrix;

            double xMajorTick = cri.xAxisRendererInfo.MajorTick;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int      count  = sri.series.Elements.Count;
                XPoint[] points = new XPoint[count];
                for (int idx = 0; idx < count; idx++)
                {
                    double v = sri.series.Elements[idx].Value;
                    if (double.IsNaN(v))
                    {
                        v = 0;
                    }
                    points[idx] = new XPoint(idx + xMajorTick / 2, v);
                }
                matrix.TransformPoints(points);
                gfx.DrawLines(sri.LineFormat, points);
                DrawMarker(gfx, points, sri);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Draws the content of the line plot area.
        /// </summary>
        internal override void Draw()
        {
            ChartRendererInfo cri = (ChartRendererInfo)_rendererParms.RendererInfo;

            XRect plotAreaRect = cri.plotAreaRendererInfo.Rect;

            if (plotAreaRect.IsEmpty)
            {
                return;
            }

            XGraphics      gfx   = _rendererParms.Graphics;
            XGraphicsState state = gfx.Save();

            //gfx.SetClip(plotAreaRect, XCombineMode.Intersect);
            gfx.IntersectClip(plotAreaRect);

            //TODO Treat null values correctly.
            //     Points can be missing. Treat null values accordingly (NotPlotted, Interpolate etc.)

            // Draw lines and markers for each data series.
            XMatrix matrix = cri.plotAreaRendererInfo._matrix;

            double xMajorTick = cri.xAxisRendererInfo.MajorTick;

            foreach (SeriesRendererInfo sri in cri.seriesRendererInfos)
            {
                int      count  = sri._series.Elements.Count;
                XPoint[] points = new XPoint[count];
                for (int idx = 0; idx < count; idx++)
                {
                    double v = sri._series.Elements[idx].Value;
                    if (double.IsNaN(v))
                    {
                        v = 0;
                    }
                    points[idx] = new XPoint(idx + xMajorTick / 2, v);
                }
                matrix.TransformPoints(points);
                gfx.DrawLines(sri.LineFormat, points);
                DrawMarker(gfx, points, sri);
            }

            //gfx.ResetClip();
            gfx.Restore(state);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Source and more infos: http://www.math.dartmouth.edu/~dlittle/java/SpiroGraph/
        /// </summary>
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            //int R =  60, r =  60, p =   60, N = 270; // Cardioid
            //int R =  60, r = -45, p = -101, N = 270; // Rounded Square
            //int R =  75, r = -25, p =   85, N = 270; // Gold fish
            //int R =  75, r = -30, p =   60, N = 270; // Star fish
            //int R = 100, r =  49, p =   66, N =   7; // String of Pearls
            //int R =  90, r =   1, p =  105, N = 105; // Rotating Triangle

            //int R =  90, r =   1, p =  105, N = 105;
            int R = 60, r = 2, p = 122, N = 490;

            int revs = Math.Abs(r) / Gcd(R, Math.Abs(r));

            XPoint[] points = new XPoint[revs * N + 1];
            for (int i = 0; i <= revs * N; i++)
            {
                double t = 4 * i * Math.PI / N;
                points[i].X = ((R + r) * Math.Cos(t) - p * Math.Cos((R + r) * t / r));
                points[i].Y = ((R + r) * Math.Sin(t) - p * Math.Sin((R + r) * t / r));
            }

#if true
            // Draw as lines
            gfx.TranslateTransform(300, 250);
            gfx.DrawLines(properties.Pen2.Pen, points);

            //gfx.DrawPolygon(properties.Pen2.Pen, properties.Brush2.Brush, points, properties.General.FillMode);

            // Draw as closed curve
            gfx.TranslateTransform(0, 400);
            gfx.DrawClosedCurve(properties.Pen2.Pen, properties.Brush2.Brush, points, properties.General.FillMode,
                                properties.General.Tension);
#else
            gfx.TranslateTransform(300, 400);
            XSolidBrush dotBrush = new XSolidBrush(properties.Pen2.Pen.Color);
            float       width    = properties.Pen2.Width;
            for (int i = 0; i < revs * N; i++)
            {
                gfx.DrawEllipse(dotBrush, points[i].X, points[i].Y, width, width);
            }
#endif
        }
Exemplo n.º 11
0
        private void DrawLines(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "DrawLines");
            XPen xPen = new XPen(XColors.DarkSeaGreen, 6.0);

            xPen.LineCap  = XLineCap.Round;
            xPen.LineJoin = XLineJoin.Bevel;
            XPoint[] points = new XPoint[]
            {
                new XPoint(20.0, 30.0),
                new XPoint(60.0, 120.0),
                new XPoint(90.0, 20.0),
                new XPoint(170.0, 90.0),
                new XPoint(230.0, 40.0)
            };
            gfx.DrawLines(xPen, points);
            base.EndBox(gfx);
        }
Exemplo n.º 12
0
        private void DrawRectangle(XGraphics graphicsPage, double left, double top, double width, double height, string content, XFont font, bool alignmentCenter, double marginLeft, double marginRight)
        {
            graphicsPage.DrawLines(XPens.Black, new XPoint[] {
                new XPoint(left, top),
                new XPoint(left + width, top),
                new XPoint(left + width, top + height),
                new XPoint(left, top + height),
                new XPoint(left, top)
            });


            if (alignmentCenter)
            {
                width = (width - 12 - content.Length * 7) / 2;
                left  = left + width;
            }

            graphicsPage.DrawString(content, font, XBrushes.Black, new XPoint(left + 4 + marginLeft, top + 12 + marginRight));
        }
Exemplo n.º 13
0
 public void DrawLines(IPen pen, Point[] points, LineAnchor startAnchor, LineAnchor endAnchor)
 {
     Graphics.DrawLines((XPen)pen.Raw, points);
 }
Exemplo n.º 14
0
 public void DrawLines(Pen pen, Point[] points)
 {
     _graphics.DrawLines(PenToXPen(pen), points);
 }
        public void generatePDF(string elementList)
        {
            string filename = string.Empty;

            // PDF-Dokument initialisieren und Eigenschaften hinzufügen
            PdfDocument document = new PdfDocument();

            document.Info.Title   = "Stenographie Training-Tool";
            document.Info.Author  = "Frank Nelles";
            document.Info.Creator = "Frank Nelles";
            document.Info.Subject = "Stenographie Übungen";

            // Seite und Grafikfläche hinzufügen
            PdfPage   page = document.AddPage();
            XGraphics gfx  = XGraphics.FromPdfPage(page);

            // Umschließende Linie hinzufügen (Rechteck)
            XPen pen = new XPen(XColors.Gray, 3);

            XPoint[] points = new XPoint[] { new XPoint(40, 39), new XPoint(40, 789), new XPoint(555, 789), new XPoint(555, 40), new XPoint(39, 40) };
            gfx.DrawLines(pen, points);

            // Alle Linien hinzufügen
            ///Zählervariablen erstellen: i=Punkte; j=Dicke Linie; k=Lange Linie/Stenozeilenende
            int i = 51; int j = 2; int k = 1;

            //Linien einfügen
            while (i <= 778)
            {
                //Liniendicke einstellen
                int lineHeight = 1;
                //Jede vierte Linie (beginnend ab 3.) dicker
                if ((j % 4) == 0)
                {
                    lineHeight = 2;
                }

                //Linienbreite einstellen
                int lineWidthXStart = 120;
                //Jede vierte Linie (beginnend ab 4.) breiter
                if ((k % 4) == 0)
                {
                    lineWidthXStart = 40;
                }

                //Stifteigenschaften festlegen
                pen = new XPen(XColors.Black, lineHeight);
                //Linie zeichnen
                gfx.DrawLine(pen, lineWidthXStart, i, 554, i);

                //Linie 11 Punkte weiter unten erstellen (i), Zeilenanzahl erhöhe
                i += 11; j++; k++;
            }

            //Texteigenschaften
            XFont font = new XFont("Verdana", 10);

            //Arraydurchlauf-Variable
            int l = 0;

            //Text-Ausgabe in Array zerlegen
            string[] wordOrLetter = elementList.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries);

            //Bis zu 17 Buchstaben/Wort -Ketten ausgeben
            foreach (string outputWordOrLetter in wordOrLetter)
            {
                //Text ausgeben
                gfx.DrawString(outputWordOrLetter, font, XBrushes.Black, new XRect(45, (70 + (44 * l)), page.Width, page.Height), XStringFormats.TopLeft);
                //Zähler-Variable erhöhen
                l++;
                //Nach 17 Elementen abbrechen
                if (l > 16)
                {
                    break;
                }
            }

            //Speicherdialog initialisieren und Eigenschaften festlegen
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName     = "StenoÜbung";                         //Standarddateiname
            dlg.DefaultExt   = ".pdf";                               //Standarddateierweiterung
            dlg.Filter       = "PDF documents (.pdf)|*.pdf";         //Nur .pdf als Dateierweiterung zulassen
            dlg.AddExtension = true;                                 //Erweiterung hinzufügen, wenn nicht in Nutzereingabe
            dlg.Title        = "Stenographie-Übungsblatt speichern"; //Titel des Dialogs

            // Speicherdialog anzeigen und bei positiver Rückmeldung speichern
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                // Save document
                filename = dlg.FileName;
                document.Save(filename);
                //Erfolgsmeldung ausgeben
                MessageBox.Show(
                    "Die PDF wurde generiert und unter \r\n" +
                    "\r\n" +
                    filename + "\r\n" +
                    "\r\n" +
                    "gespeichert.\r\n" +
                    "\r\n" +
                    "(Die PDF-Datei kann bis zu 17 Buchstaben oder Wörter aufnehmen. Fehlende wurden durch Leerzeichen ersetzt und überschüssige entfernt.)"
                    );
            }
            else
            {
                //Fehlermeldung
                MessageBox.Show("Das Speichern ist fehlgeschlagen.");
            }
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        public byte[] Create(string content)
        {
            // http://pdfsharp.net/wiki/PrivateFonts-sample.ashx
            // http://stackoverflow.com/questions/31568349/error-accessing-fonts-in-azure-web-app-when-using-pdfsharp
            var familyName = "Verdana";

            using (PdfDocument document = new PdfDocument())
            {
                document.Info.Title = "Jira Agile Cards";

                XmlDocument xml = new XmlDocument();
                xml.LoadXml(content);

                if (xml.DocumentElement == null)
                {
                    throw new NotSupportedException("Xml document is invalid!");
                }

                var nodes = xml.DocumentElement.SelectNodes("//rss/channel/item");
                if (nodes == null)
                {
                    throw new NotSupportedException("Xml document is invalid!");
                }

                foreach (XmlNode node in nodes)
                {
                    var summary  = GetNodeValue(node, "summary");
                    var issueNo  = GetNodeValue(node, "key");
                    var parentNo = GetNodeValue(node, "parent");
                    var priority = GetNodeValue(node, "priority");
                    var taskType = GetNodeValue(node, "type");

                    var taskEstimate = GetNodeValue(node, "timeoriginalestimate");

                    if (taskType == "Story")
                    {
                        taskEstimate = GetNodeValue(node, "aggregatetimeoriginalestimate");
                        var customFields = node.SelectNodes("customfields/customfield");
                        if (customFields != null)
                        {
                            foreach (XmlNode customField in customFields)
                            {
                                var name = GetNodeValue(customField, "customfieldname");
                                if (name == "Story Points")
                                {
                                    var values = customField.SelectSingleNode("customfieldvalues");
                                    if (values != null)
                                    {
                                        var value = GetNodeValue(values, "customfieldvalue");
                                        if (!string.IsNullOrEmpty(value))
                                        {
                                            taskEstimate = value;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    var page = document.AddPage();
                    page.Size        = PageSize.A4;
                    page.Orientation = PageOrientation.Landscape;

                    XGraphics gfx = XGraphics.FromPdfPage(page);

                    gfx.DrawLine(XPens.Black, new XPoint(10, 450), new XPoint(610, 450));

                    XTextFormatter tf = new XTextFormatter(gfx)
                    {
                        Alignment = XParagraphAlignment.Left
                    };

                    var   summaryRectangle = new XRect(10, 10, 600, 450);
                    XFont summaryFont      = new XFont(familyName, 48, XFontStyle.Regular);
                    tf.DrawString(summary, summaryFont, XBrushes.Black, summaryRectangle, XStringFormats.TopLeft);

                    XFont issueNoFont      = new XFont(familyName, 36, XFontStyle.Regular);
                    var   issueNoRectangle = new XRect(10, 460, 290, 50);
                    tf.Alignment = XParagraphAlignment.Left;
                    tf.DrawString(issueNo, issueNoFont, XBrushes.Black, issueNoRectangle);

                    XFont parentNoFont      = new XFont(familyName, 26, XFontStyle.Regular);
                    var   parentNoRectangle = new XRect(320, 460, 290, 50);
                    tf.Alignment = XParagraphAlignment.Right;
                    tf.DrawString(parentNo, parentNoFont, XBrushes.DimGray, parentNoRectangle);

                    XFont priorityFont      = new XFont(familyName, 24, XFontStyle.Italic);
                    var   priorityRectangle = new XRect(10, 510, 290, 50);
                    tf.Alignment = XParagraphAlignment.Left;
                    tf.DrawString(priority, priorityFont, XBrushes.Black, priorityRectangle);

                    XFont taskTypeFont      = new XFont(familyName, 24, XFontStyle.Italic);
                    var   taskTypeRectangle = new XRect(320, 510, 290, 50);
                    tf.Alignment = XParagraphAlignment.Right;
                    tf.DrawString(taskType, taskTypeFont, XBrushes.Black, taskTypeRectangle);

                    var p1 = new XPoint(650, 10);
                    var p2 = new XPoint(800, 10);
                    var p3 = new XPoint(800, 160);
                    var p4 = new XPoint(650, 160);

                    gfx.DrawLines(XPens.Black, new[] { p1, p2, p3, p4, p1 });

                    XFont estimateFont      = new XFont(familyName, 48, XFontStyle.Regular);
                    var   estimateRectangle = new XRect(650, 50, 150, 100);
                    tf.Alignment = XParagraphAlignment.Center;
                    tf.DrawString(taskEstimate, estimateFont, XBrushes.Black, estimateRectangle);
                }

                using (var exportStream = new MemoryStream())
                {
                    document.Save(exportStream);
                    var array = exportStream.ToArray();
                    return(array);
                }
            }
        }
Exemplo n.º 18
0
        public void DrawHandMadeArc(XGraphics gfx, XPen pen, XRect rect, double startAngle, double sweepAngle)
        {
            const double deg2rad = Math.PI / 180;
            double       dx      = rect.Width / 2;
            double       dy      = rect.Height / 2;
            double       x0      = rect.X + dx;
            double       y0      = rect.Y + dy;

            double a = startAngle;

            if (a < 0)
            {
                a = a + (1 + Math.Floor((Math.Abs(a) / 360))) * 360;
            }
            else if (a > 360)
            {
                a = a - Math.Floor(a / 360) * 360;
            }

            double b = startAngle + sweepAngle;

            if (b < 0)
            {
                b = b + (1 + Math.Floor((Math.Abs(b) / 360))) * 360;
            }
            else if (b > 360)
            {
                b = b - Math.Floor(b / 360) * 360;
            }

            a *= deg2rad;
            b *= deg2rad;

            if (rect.Width != rect.Height)
            {
                double sina = Math.Sin(a);
                if (Math.Abs(sina) > 1E-10)
                {
                    if (a < Math.PI)
                    {
                        a = Math.PI / 2 - Math.Atan(dy * Math.Cos(a) / (dx * sina));
                    }
                    else
                    {
                        a = 3 * Math.PI / 2 - Math.Atan(dy * Math.Cos(a) / (dx * sina));
                    }
                }
                double sinb = Math.Sin(b);
                if (Math.Abs(sinb) > 1E-10)
                {
                    if (b < Math.PI)
                    {
                        b = Math.PI / 2 - Math.Atan(dy * Math.Cos(b) / (dx * sinb));
                    }
                    else
                    {
                        b = 3 * Math.PI / 2 - Math.Atan(dy * Math.Cos(b) / (dx * sinb));
                    }
                }
            }

            int    count;
            double adeg = a / deg2rad;
            double bdeg = b / deg2rad;

            if (adeg < bdeg)
            {
                if (sweepAngle > 0)
                {
                    count = (int)(bdeg - adeg) + 1;
                }
                else
                {
                    count = 361 - (int)(bdeg - adeg);
                }
            }
            else
            {
                if (sweepAngle > 0)
                {
                    count = 361 - (int)(adeg - bdeg);
                }
                else
                {
                    count = (int)(adeg - bdeg) + 1;
                }
            }
            if (count < 2)
            {
                count = 2;
            }
            XPoint[] points = new XPoint[count];
            double   delta  = sweepAngle > 0 ? deg2rad : -deg2rad;

#if true_
            gfx.DrawLine(XPens.Green, x0, y0, x0 + dx * Math.Cos(a), y0 + dy * Math.Sin(a));
            gfx.DrawLine(XPens.Green, x0, y0, x0 + dx * Math.Cos(b), y0 + dy * Math.Sin(b));
#endif
            for (int idx = 0; idx < count; idx++)
            {
                double angle;
                if (idx + 1 != count)
                {
                    angle = a + idx * delta;
                }
                else
                {
                    angle = b;
                }
                points[idx].X = x0 + dx * Math.Cos(angle);
                points[idx].Y = y0 + dy * Math.Sin(angle);
            }
            gfx.DrawLines(pen, points);
        }
Exemplo n.º 19
0
 void DrawAxes(XGraphics gfx, XPen pen, PointF origin, float length)
 {
     gfx.DrawLines(pen, origin.X, origin.Y - length, origin.X, origin.Y, origin.X + length, origin.Y);
 }
Exemplo n.º 20
0
 void IDrawingCanvas.DrawLines(PenEx pen, PointF[] polyLine)
 {
     _graphics.DrawLines((Pen)pen, polyLine.Select(p => PdfConverter.Convert(p)).ToArray());
 }
Exemplo n.º 21
0
        public static byte[] GenPDFFile(metka m_)
        {
            PdfDocument document = new PdfDocument();

            Zen.Barcode.Code128BarcodeDraw bc  = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
            Zen.Barcode.Code128BarcodeDraw bc1 = Zen.Barcode.BarcodeDrawFactory.Code128WithChecksum;
            double ilosc = 0;

            for (int i = 0; i < m_.il_stron; i++)
            {
                PdfPage page = document.AddPage();
                page.Size = PdfSharp.PageSize.A5;
                // Get an XGraphics object for drawing
                XGraphics gfx   = XGraphics.FromPdfPage(page);
                XFont     font  = new XFont("Verdana", 15, XFontStyle.BoldItalic);
                XFont     font1 = new XFont("Verdana", 10, XFontStyle.Regular);
                XFont     font2 = new XFont("Verdana", 15, XFontStyle.Regular);
                XFont     font3 = new XFont("Verdana", 8, XFontStyle.Regular);
                XFont     font4 = new XFont("Verdana", 8, XFontStyle.Italic);
                // kod kreskowy
                Image  im  = bc.Draw(m_.nr_zlec_galw.ToString(), 20, 2);
                XImage xim = XImage.FromGdiPlusImage(im);
                gfx.DrawImage(xim, new Point(20, 10));
                gfx.DrawString("Utw.: " + DateTime.Now.ToString(), font1, XBrushes.Black,
                               new XRect(210, 10, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString("Przez: " + m_.userid, font3, XBrushes.Black,
                               new XRect(210, 22, 300, 22),
                               XStringFormats.TopLeft);



                gfx.DrawString(m_.nazwa, font, XBrushes.Black,
                               new XRect(20, 40, 400, 22),
                               XStringFormats.TopLeft);


                gfx.DrawString(m_.kod_zlecenia + " (Kod zlecenia)", font1, XBrushes.Black,
                               new XRect(20, 65, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString(m_.kod_materialu_galw + " (Kod materialu)", font1, XBrushes.Black,
                               new XRect(20, 80, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString(m_.kolor, font2, XBrushes.Black,
                               new XRect(20, 95, 300, 22),
                               XStringFormats.TopLeft);



                gfx.DrawString("Ilość szt: " + m_.ilosc_szt[i].ToString(), font1, XBrushes.Black,
                               new XRect(255, 65, 300, 22),
                               XStringFormats.TopLeft);

                gfx.DrawString("Nr rysunku: " + m_.nr_rysunku, font1, XBrushes.Black,
                               new XRect(255, 80, 300, 22),
                               XStringFormats.TopLeft);
                gfx.DrawString("Zlec_IPO: " + m_.nr_zlec_galw, font1, XBrushes.Black,
                               new XRect(255, 95, 300, 22),
                               XStringFormats.TopLeft);


                baza_metekDataContext db1 = new baza_metekDataContext();
                var pow = from c in db1.GAL_POWIERZCHNIEs
                          where c.NR_RYS == m_.nr_rysunku && (bool)c.STATUS
                          select c;
                if (pow.Count() == 1)
                {
                    var pows = pow.Single();

                    gfx.DrawString("Pow: " + Math.Round((double)pows.POW, 3).ToString() + "(" + Math.Round(((double)pows.POW * m_.ilosc_szt[i]), 3).ToString() + ") dm2", font1, XBrushes.Black,
                                   new XRect(255, 110, 300, 22),
                                   XStringFormats.TopLeft);
                }

                gfx.DrawString("" + m_.komentarz, font4, XBrushes.Black,
                               new XRect(200, 125, 300, 22),
                               XStringFormats.TopLeft);

                ilosc = ilosc + m_.ilosc_szt[i];



                MemoryStream ms = new MemoryStream();
                m_.rysunek.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

                Image  n_rys    = System.Drawing.Image.FromStream(ms);
                double r_width  = 150;
                double ratio    = r_width / n_rys.Width;
                double r_height = (double)n_rys.Height * ratio;
                XImage rys      = XImage.FromGdiPlusImage(n_rys);

                gfx.DrawImage(rys, 15, 150, r_width, r_height);
                Image  im1  = bc.Draw("" + m_.nr_zlec_galw, 10, 2);
                XImage xim1 = XImage.FromGdiPlusImage(im1);
                gfx.DrawImage(xim1, new Point(15, 130));

                gfx.DrawString("  Belka   ,  il.szt", font4, XBrushes.Black,
                               new XRect(255, 140, 300, 22),
                               XStringFormats.TopLeft);


                XPen     pen    = new XPen(XColors.Black, 1);
                XPoint[] points = new XPoint[] { new XPoint(255, 150), new XPoint(355, 150), new XPoint(355, 190), new XPoint(255, 190), new XPoint(255, 150) };
                gfx.DrawLines(pen, points);

                points = new XPoint[] { new XPoint(355, 190), new XPoint(355, 230), new XPoint(255, 230), new XPoint(255, 190) };
                gfx.DrawLines(pen, points);
                points = new XPoint[] { new XPoint(355, 230), new XPoint(355, 270), new XPoint(255, 270), new XPoint(255, 230) };
                gfx.DrawLines(pen, points);
            }



            // Save the document...
            //string filename = "HelloWorld.pdf";
            MemoryStream str = new MemoryStream();

            document.Save(str, true);
            Metki_PDF m_pdf = new Metki_PDF();

            m_pdf.Nr_zlecenia = m_.nr_zlec_galw.ToString();
            m_pdf.Data_utw    = DateTime.Now;
            m_pdf.PDF         = str.ToArray();
            m_pdf.Ilosc       = (int)ilosc;
            baza_metekDataContext db = new baza_metekDataContext();

            db.Metki_PDFs.InsertOnSubmit(m_pdf);
            db.SubmitChanges();

            Metki_baza m = new Metki_baza();

            m.Data_utw    = DateTime.Now;
            m.Ilosc       = (int)m_.ilosc_szt[0];
            m.Nr_kodu     = m_.kod_zlecenia;
            m.Nr_zlecenia = m_.nr_zlec_galw.ToString();
            m.User_id     = "galwanika";
            db.Metki_bazas.InsertOnSubmit(m);
            db.SubmitChanges();

            return(str.ToArray());
        }