Ejemplo n.º 1
0
        public static void DrawCrosshairs(PdfSharp.Drawing.XGraphics gfx, double width, double height, PdfMargin margin)
        {
            PdfSharp.Drawing.XPen[] pens = new PdfSharp.Drawing.XPen[] { PdfSharp.Drawing.XPens.Black, PdfSharp.Drawing.XPens.Black };
            // pens = new PdfSharp.Drawing.XPen[] { PdfSharp.Drawing.XPens.Yellow, PdfSharp.Drawing.XPens.Red };

            double halfPenWidth = pens[0].Width / 2.0;

            DrawCrossTopLeft(gfx, width, height, margin, halfPenWidth, pens);
            DrawCrossTopRight(gfx, width, height, margin, halfPenWidth, pens);
            DrawCrossBottomLeft(gfx, width, height, margin, halfPenWidth, pens);
            DrawCrossBottomRight(gfx, width, height, margin, halfPenWidth, pens);
        }
Ejemplo n.º 2
0
        private void AddImageToPdf(System.Drawing.Image image, double width_pt, double heigth_pt)
        {
            var rect = new System.Drawing.RectangleF {
                X      = (float)_horizontalePosition,
                Y      = (float)_verticalPosition,
                Width  = (float)width_pt,
                Height = (float)heigth_pt
            };

            PdfSharp.Drawing.XImage xImage = PdfSharp.Drawing.XImage.FromGdiPlusImage(image);
            PdfSharp.Drawing.XPen   pen    = new PdfSharp.Drawing.XPen(PdfSharp.Drawing.XColors.Black, 1f);
            _graphics.DrawImage(xImage, rect);
            _graphics.DrawRectangle(pen, rect);
            _verticalPosition += heigth_pt;
            _isPageEmpty       = false;
        }
Ejemplo n.º 3
0
        } // End Sub CreatePdf

        public void DrawPath(System.Xml.XmlNode xn)
        {
            string d = xn.Attributes["d"].Value;
            string f = xn.Attributes["fill"].Value;
            string s = xn.Attributes["stroke"].Value;


            System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml(f);


            System.Collections.Generic.List <System.Drawing.Point> pathPoints = GetPathPointsPoints(d);

            if (pathPoints == null)
            {
                return;
            }



            double width = 1.0;

            PdfSharp.Drawing.XPen pen = PdfSharp.Drawing.XPens.Black;// Pen: Line
            //PdfSharp.Drawing.XPen pen2 = new PdfSharp.Drawing.XPen(PdfSharp.Drawing.XColor.FromArgb(255, System.Drawing.Color.Black), width);
            PdfSharp.Drawing.XPen pen2 = new PdfSharp.Drawing.XPen(PdfSharp.Drawing.XColor.FromArgb(System.Drawing.Color.Black), width);



            // Brush: Fill
            // PdfSharp.Drawing.XBrush brush = PdfSharp.Drawing.XBrushes.Red;
            PdfSharp.Drawing.XBrush brush = new PdfSharp.Drawing.XSolidBrush(PdfSharp.Drawing.XColor.FromArgb(col));
            // System.Console.WriteLine(pen);
            // System.Console.WriteLine(pen2);

            this.gfxPdf.DrawPolygon(pen2, brush
                                    , pathPoints.ToArray()
                                    , PdfSharp.Drawing.XFillMode.Winding
                                    );

            System.Console.WriteLine(d);
            // http://www.pdfsharp.net/wiki/Clock-sample.ashx
        }
Ejemplo n.º 4
0
        public static void DrawBorder(PdfSharp.Drawing.XGraphics gfx, double width, double height, PdfMargin margin)
        {
            PdfSharp.Drawing.XPen[] pens = new PdfSharp.Drawing.XPen[] { PdfSharp.Drawing.XPens.Black, PdfSharp.Drawing.XPens.Black, PdfSharp.Drawing.XPens.Black, PdfSharp.Drawing.XPens.Black };
            // pens = new PdfSharp.Drawing.XPen[] { PdfSharp.Drawing.XPens.Yellow, PdfSharp.Drawing.XPens.HotPink, PdfSharp.Drawing.XPens.Blue, PdfSharp.Drawing.XPens.Green };

            double halfPenWidth = pens[0].Width / 2.0;

            double x1 = 0;
            double y1 = margin.Top - halfPenWidth;
            double x2 = width;
            double y2 = margin.Top - halfPenWidth;

            gfx.DrawLine(pens[0], x1, y1, x2, y2); // Horizontal Top - Yellow

            // y1 = height-pageMargin;
            x1 = 0;
            y1 = height - margin.Bottom + halfPenWidth;
            x2 = width;                            // 1/4 + 1/8 ()*0.5= 3/16
            y2 = height - margin.Bottom + halfPenWidth;
            gfx.DrawLine(pens[1], x1, y1, x2, y2); // Horizontal Bottom  - Hotpink



            x1 = margin.Left - halfPenWidth;
            y1 = 0;
            x2 = margin.Left - halfPenWidth;
            y2 = height;
            gfx.DrawLine(pens[2], x1, y1, x2, y2); // Vertical Left - Blue


            x1 = width - margin.Right + halfPenWidth;
            y1 = 0;
            x2 = width - margin.Right + halfPenWidth;
            y2 = height;
            gfx.DrawLine(pens[3], x1, y1, x2, y2); // Vertical Right - Green
        }
Ejemplo n.º 5
0
        static void WriteTest()
        {
            using (PdfSharp.Pdf.PdfDocument document = new PdfSharp.Pdf.PdfDocument())
            {
                document.Info.Title    = "Family Tree";
                document.Info.Author   = "FamilyTree Ltd. - Stefan Steiger";
                document.Info.Subject  = "Family Tree";
                document.Info.Keywords = "Family Tree, Genealogical Tree, Genealogy, Bloodline, Pedigree";


                PdfSharp.Pdf.Security.PdfSecuritySettings securitySettings = document.SecuritySettings;

                // Setting one of the passwords automatically sets the security level to
                // PdfDocumentSecurityLevel.Encrypted128Bit.
                securitySettings.UserPassword  = "******";
                securitySettings.OwnerPassword = "******";

                // Don't use 40 bit encryption unless needed for compatibility
                //securitySettings.DocumentSecurityLevel = PdfDocumentSecurityLevel.Encrypted40Bit;

                // Restrict some rights.
                securitySettings.PermitAccessibilityExtractContent = false;
                securitySettings.PermitAnnotations      = false;
                securitySettings.PermitAssembleDocument = false;
                securitySettings.PermitExtractContent   = false;
                securitySettings.PermitFormsFill        = true;
                securitySettings.PermitFullQualityPrint = false;
                securitySettings.PermitModifyDocument   = true;
                securitySettings.PermitPrint            = false;



                document.ViewerPreferences.Direction = PdfSharp.Pdf.PdfReadingDirection.LeftToRight;
                PdfSharp.Pdf.PdfPage page = document.AddPage();

                // page.Width = PdfSettings.PaperFormatSettings.Width
                // page.Height = PdfSettings.PaperFormatSettings.Height

                page.Orientation = PdfSharp.PageOrientation.Landscape;
                double dblLineWidth = 1.0;
                string strHtmlColor = "#FF00FF";
                PdfSharp.Drawing.XColor lineColor = XColorHelper.FromHtml(strHtmlColor);
                PdfSharp.Drawing.XPen   pen       = new PdfSharp.Drawing.XPen(lineColor, dblLineWidth);

                PdfSharp.Drawing.XFont font = new PdfSharp.Drawing.XFont("Arial"
                                                                         , 12.0, PdfSharp.Drawing.XFontStyle.Bold
                                                                         );



                using (PdfSharp.Drawing.XGraphics gfx = PdfSharp.Drawing.XGraphics.FromPdfPage(page))
                {
                    gfx.MUH = PdfSharp.Pdf.PdfFontEncoding.Unicode;

                    PdfSharp.Drawing.Layout.XTextFormatter tf = new PdfSharp.Drawing.Layout.XTextFormatter(gfx);
                    tf.Alignment = PdfSharp.Drawing.Layout.XParagraphAlignment.Left;

                    PdfSharp.Drawing.Layout.XTextFormatterEx2 etf = new PdfSharp.Drawing.Layout.XTextFormatterEx2(gfx);


                    gfx.DrawRectangle(pen, new PdfSharp.Drawing.XRect(100, 100, 100, 100));

                    using (PdfSharp.Drawing.XImage img = PdfSharp.Drawing.XImage.FromFile(@"D:\username\Documents\Visual Studio 2017\Projects\PdfSharp\TestApplication\Wikipedesketch1.png"))
                    {
                        gfx.DrawImage(img, 500, 500);
                    }

                    string text = "Lalala";

                    tf.DrawString(text
                                  , font
                                  , PdfSharp.Drawing.XBrushes.Black
                                  , new PdfSharp.Drawing.XRect(300, 300, 100, 100)
                                  , PdfSharp.Drawing.XStringFormats.TopLeft
                                  );
                } // End Using gfx

                // Save the document...
                string filename = "TestFilePwProtected.pdf";
                document.Save(filename);
                // ...and start a viewer.
                System.Diagnostics.Process.Start(filename);
            } // End Using document
        }     // End Sub WriteTest
Ejemplo n.º 6
0
 private void AddImageToPdf(System.Drawing.Image image, double width_pt, double heigth_pt) {
     var rect = new System.Drawing.RectangleF {
         X = (float)_horizontalePosition,
         Y = (float)_verticalPosition,
         Width = (float)width_pt,
         Height = (float)heigth_pt
     };
     PdfSharp.Drawing.XImage xImage = PdfSharp.Drawing.XImage.FromGdiPlusImage(image);
     PdfSharp.Drawing.XPen pen = new PdfSharp.Drawing.XPen(PdfSharp.Drawing.XColors.Black, 1f);
     _graphics.DrawImage(xImage, rect);
     _graphics.DrawRectangle(pen, rect);
     _verticalPosition += heigth_pt;
     _isPageEmpty = false;
 }