コード例 #1
0
        public override void Process(iPDF owner, ref PdfDocument Document, ref PdfPage Page, ref XGraphics Graphics)
        {
            if (!string.IsNullOrEmpty(Data))
            {
                var   watermark = Data;
                XSize size      = Graphics.MeasureString(watermark, owner.Font);

                // Define a rotation transformation at the center of the page
                Graphics.TranslateTransform(Page.Width / 2, Page.Height / 2);
                Graphics.RotateTransform(-Math.Atan(Page.Height / Page.Width) * 180 / Math.PI);
                Graphics.TranslateTransform(-Page.Width / 2, -Page.Height / 2);

                // Create a graphical path
                XGraphicsPath path = new XGraphicsPath();

                // Add the text to the path
                path.AddString(watermark, owner.Font.FontFamily, XFontStyle.BoldItalic, 150, new XPoint(0, (Page.Height / 2) - 80), XStringFormats.TopLeft);

                // Create a dimmed red pen and brush
                XPen   pen   = new XPen(XColor.FromArgb(50, 75, 0, 130), 3);
                XBrush brush = new XSolidBrush(XColor.FromArgb(50, 106, 90, 205));

                // Stroke the outline of the path
                Graphics.DrawPath(pen, brush, path);
            }
        }
コード例 #2
0
ファイル: PathClipGlyph.cs プロジェクト: jgshumate1/Migradoc
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

            // Create a new graphical path
            XGraphicsPath path = new XGraphicsPath();

            // Add the outline of the glyphs of the word 'Clip' to the path
            path.AddString("Clip!", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 250, new XPoint(30, 100), XStringFormats.Default);

#if DEBUG_
            gfx.WriteComment("SetClip");
#endif
            // Set the path as clip path
            gfx.IntersectClip(path);
#if DEBUG_
            gfx.WriteComment("Random lines");
#endif
            // Draw some random lines to show that clipping happens
            Random rnd = new Random(42);
            for (int idx = 0; idx < 300; idx++)
            {
                gfx.DrawLine(properties.Pen2.Pen, rnd.Next(600), rnd.Next(500), rnd.Next(600), rnd.Next(500));
            }
        }
コード例 #3
0
        private void DrawGlyphs(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "Draw Glyphs");
            XGraphicsPath xGraphicsPath = new XGraphicsPath();

            xGraphicsPath.AddString("Hello!", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 100.0, new XRect(0.0, 0.0, 250.0, 140.0), XStringFormats.Center);
            gfx.DrawPath(new XPen(XColors.Purple, 2.3), XBrushes.DarkOrchid, xGraphicsPath);
            base.EndBox(gfx);
        }
コード例 #4
0
ファイル: Clock.aspx.cs プロジェクト: jgshumate1/Migradoc
        static void DrawText(XGraphics gfx, XPen pen, XBrush brush)
        {
            XSize         size = gfx.PageSize;
            XGraphicsPath path = new XGraphicsPath();

            path.AddString("PDFsharp",
                           new XFontFamily("Verdana"), XFontStyle.BoldItalic, 60,
                           new XRect(0, size.Height / 3.5, size.Width, 0), XStringFormats.Center);
            gfx.DrawPath(new XPen(pen.Color, 3), brush, path);
        }
コード例 #5
0
ファイル: GlyphsPaths.cs プロジェクト: t00/PdfSharpXps
        void RenderGlyphsPath(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XGraphicsPath path = new XGraphicsPath();

            //path.AddString("Hello!", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 100, new XRect(0, 0, 250, 140),
            //        XStringFormat.Center);
            path.AddString("Hello!", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 100, new XRect(0, 0, 250, 140), XStringFormats.Center);
            gfx.DrawPath(new XPen(XColors.Purple, 2.3), XBrushes.DarkOrchid, path);
        }
コード例 #6
0
ファイル: PathGlyph.cs プロジェクト: jgshumate1/Migradoc
        public override void RenderPage(XGraphics gfx)
        {
            base.RenderPage(gfx);

#if true__
            XPen pen = new XPen(XColors.DarkGreen, 20);
            gfx.DrawLine(pen, 0, 0, 1000, 1000);
#endif

            XGraphicsPath path = new XGraphicsPath();

            path.AddString("@", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 500, new XPoint(90, 60), XStringFormats.Default);
            gfx.DrawPath(properties.Pen2.Pen, properties.Brush2.Brush, path);
        }
コード例 #7
0
        /// <summary>
        /// Converts text to path.
        /// </summary>
        void DrawGlyphs(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "Draw Glyphs");

#if CORE
            DrawMessage(gfx, "AddString is not implemented in PDFsharp Core.");
#else
            var path = new XGraphicsPath();
            // AddString is not implemented int PDFsharp Core.
            path.AddString("Hello!", new XFontFamily("Times New Roman"), XFontStyle.BoldItalic, 100, new XRect(0, 0, 250, 140), XStringFormats.Center);
            gfx.DrawPath(new XPen(XColors.Purple, 2.3), XBrushes.DarkOrchid, path);
#endif

            EndBox(gfx);
        }
コード例 #8
0
        private void DrawClipPath(XGraphics gfx, int number)
        {
            base.BeginBox(gfx, number, "Clip through Path");
            XGraphicsPath xGraphicsPath = new XGraphicsPath();

            xGraphicsPath.AddString("Clip!", new XFontFamily("Verdana"), XFontStyle.Bold, 90.0, new XRect(0.0, 0.0, 250.0, 140.0), XStringFormats.Center);
            gfx.IntersectClip(xGraphicsPath);
            XPen xPen = XPens.DarkRed.Clone();

            xPen.DashStyle = XDashStyle.Dot;
            for (double num = 0.0; num <= 90.0; num += 0.5)
            {
                gfx.DrawLine(xPen, 0.0, 0.0, 250.0 * Math.Cos(num / 90.0 * 3.1415926535897931), 250.0 * Math.Sin(num / 90.0 * 3.1415926535897931));
            }
            base.EndBox(gfx);
        }
コード例 #9
0
        private void DrawWaterMark(int wx, int wy, string wText, XFont wFont, Color wColor)
        {
            XSize sf = gfx.MeasureString(wText, wFont);

            gfx.TranslateTransform(wx / 2, wy / 2);

            //double Agle = -Math.Atan(wy / wx) * 180 / Math.PI;
            //gfx.RotateTransform((float)Agle);
            //gfx.TranslateTransform(-wx / 2, -wy / 2);

            XStringFormat wformat = new XStringFormat();

            wformat.Alignment     = XStringAlignment.Near;
            wformat.LineAlignment = XLineAlignment.Near;

            // XBrush wbrush = new XSolidBrush(Color.FromArgb(20, Color.Black));
            XBrush wbrush = new XSolidBrush(Color.FromArgb(20, wColor));

            wx = (int)(wx - sf.Width) / 2;
            wy = (int)(wy - sf.Height) / 2;

            XPoint Point_xy = new XPoint(wx, wy);
            //gfx.DrawString(wText, wFont, wbrush, Point_xy, wformat);


            // OUTLINED METHOD
            // System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            // StringFormat wformat2 = new StringFormat();
            // wformat2.Alignment = StringAlignment.Near;
            // wformat2.LineAlignment = StringAlignment.Near;
            Point Point_xy2 = new Point(wx, wy);
            // path.AddString(wText, new FontFamily("Arial"), (int)FontStyle.Italic, 120, Point_xy2, wformat2);

            // Pen pen = new Pen(Color.FromArgb(64,Color.Black), 3);
            //gfx.Graphics.DrawPath(pen, path);


            XGraphicsPath path = new XGraphicsPath();

            path.AddString(wText, wFont.FontFamily, XFontStyle.Italic, 103, Point_xy2, wformat);
            Pen pen = new Pen(Color.FromArgb(64, wColor), 3);

            //e.Graphics.DrawPath(pen, path);
            gfx.DrawPath(pen, path);
        }
コード例 #10
0
        void RenderClipPath(XGraphics gfx)
        {
            gfx.TranslateTransform(15, 20);

            XGraphicsPath path = new XGraphicsPath();

            path.AddString("Clip!", new XFontFamily("Verdana"), XFontStyle.Bold, 90, new XRect(0, 0, 250, 140),
                           XStringFormats.Center);

            gfx.IntersectClip(path);

            gfx.DrawRectangle(XBrushes.LightSalmon, new XRect(0, 0, 10000, 10000));
            // Draw a beam of dotted lines
            XPen pen = XPens.DarkRed.Clone();

            pen.DashStyle = XDashStyle.Dot;
            for (double r = 0; r <= 90; r += 0.5)
            {
                gfx.DrawLine(pen, 0, 0, 1000 * Math.Cos(r / 90 * Math.PI), 1000 * Math.Sin(r / 90 * Math.PI));
            }
        }
コード例 #11
0
        static void DrawClipPath(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "Clip through Path");

            XGraphicsPath path = new XGraphicsPath();

            path.AddString("Clip!", new XFontFamily("Verdana"), XFontStyle.Bold, 90, new XRect(0, 0, 250, 140),
                           XStringFormats.Center);

            gfx.IntersectClip(path);

            // Draw a beam of dotted lines
            XPen pen = XPens.DarkRed.Clone();

            pen.DashStyle = XDashStyle.Dot;
            for (double r = 0; r <= 90; r += 0.5)
            {
                gfx.DrawLine(pen, 0, 0, 250 * System.Math.Cos(r / 90 * System.Math.PI), 250 * System.Math.Sin(r / 90 * System.Math.PI));
            }

            EndBox(gfx);
        }
コード例 #12
0
        /// <summary>
        /// Clips through path.
        /// </summary>
        void DrawClipPath(XGraphics gfx, int number)
        {
            BeginBox(gfx, number, "Clip through Path");

#if CORE
            DrawMessage(gfx, "AddString is not implemented in PDFsharp Core.");
#else
            var path = new XGraphicsPath();
            path.AddString("Clip!", new XFontFamily("Verdana"), XFontStyle.Bold, 90, new XRect(0, 0, 250, 140), XStringFormats.Center);
            gfx.IntersectClip(path);

            // Draw a beam of dotted lines.
            var pen = XPens.DarkRed.Clone();
            pen.DashStyle = XDashStyle.Dot;
            for (double r = 0; r <= 90; r += 0.5)
            {
                gfx.DrawLine(pen, 0, 0, 250 * Math.Cos(r / 90 * Math.PI), 250 * Math.Sin(r / 90 * Math.PI));
            }
#endif

            EndBox(gfx);
        }
コード例 #13
0
        public static void Variant3(PdfPage page, XFont font, string watermark)
        {
            // Variation 3: Draw a watermark as a transparent graphical path above text.
            // NYI: Does not work in Core build.

            // Get an XGraphics object for drawing above the existing content.
            var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

            // Get the size (in points) of the text.
            var size = gfx.MeasureString(watermark, font);

            // Define a rotation transformation at the center of the page.
            gfx.TranslateTransform(page.Width / 2, page.Height / 2);
            gfx.RotateTransform(-System.Math.Atan(page.Height / page.Width) * 180 / System.Math.PI);
            gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

            // Create a graphical path.
            var path = new XGraphicsPath();

            // Create a string format.
            var format = new XStringFormat();

            format.Alignment     = XStringAlignment.Near;
            format.LineAlignment = XLineAlignment.Near;

            // Add the text to the path.
            // AddString is not implemented in PDFsharp Core.
            path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                           new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                           format);

            // Create a dimmed red pen and brush.
            var    pen   = new XPen(XColor.FromArgb(50, 75, 0, 130), 3);
            XBrush brush = new XSolidBrush(XColor.FromArgb(50, 106, 90, 205));

            // Stroke the outline of the path.
            gfx.DrawPath(pen, brush, path);
        }
コード例 #14
0
        static void Main()
        {
            const string watermark = "PDFsharp";
            const int    emSize    = 150;

            // Get a fresh copy of the sample PDF file
            const string filename = "Portable Document Format.pdf";

            File.Copy(Path.Combine("../../../../../PDFs/", filename),
                      Path.Combine(Directory.GetCurrentDirectory(), filename), true);

            // Create the font for drawing the watermark
            XFont font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic);

            // Open an existing document for editing and loop through its pages
            PdfDocument document = PdfReader.Open(filename);

            // Set version to PDF 1.4 (Acrobat 5) because we use transparency.
            if (document.Version < 14)
            {
                document.Version = 14;
            }

            for (int idx = 0; idx < document.Pages.Count; idx++)
            {
                //if (idx == 1) break;
                PdfPage page = document.Pages[idx];

                switch (idx % 3)
                {
                case 0:
                {
                    // Variation 1: Draw watermark as text string

                    // Get an XGraphics object for drawing beneath the existing content
                    XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

#if true_
                    // Fill background with linear gradient color
                    XRect rect = page.MediaBox.ToXRect();
                    XLinearGradientBrush gbrush = new XLinearGradientBrush(rect,
                                                                           XColors.LightSalmon, XColors.WhiteSmoke, XLinearGradientMode.Vertical);
                    gfx.DrawRectangle(gbrush, rect);
#endif

                    // Get the size (in point) of the text
                    XSize size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a string format
                    XStringFormat format = new XStringFormat();
                    format.Alignment     = XStringAlignment.Near;
                    format.LineAlignment = XLineAlignment.Near;

                    // Create a dimmed red brush
                    XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));

                    // Draw the string
                    gfx.DrawString(watermark, font, brush,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   format);
                }
                break;

                case 1:
                {
                    // Variation 2: Draw watermark as outlined graphical path

                    // Get an XGraphics object for drawing beneath the existing content
                    XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

                    // Get the size (in point) of the text
                    XSize size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a graphical path
                    XGraphicsPath path = new XGraphicsPath();

                    // Add the text to the path
                    path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   XStringFormats.Default);

                    // Create a dimmed red pen
                    XPen pen = new XPen(XColor.FromArgb(128, 255, 0, 0), 2);

                    // Stroke the outline of the path
                    gfx.DrawPath(pen, path);
                }
                break;

                case 2:
                {
                    // Variation 3: Draw watermark as transparent graphical path above text

                    // Get an XGraphics object for drawing above the existing content
                    XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

                    // Get the size (in point) of the text
                    XSize size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a graphical path
                    XGraphicsPath path = new XGraphicsPath();

                    // Add the text to the path
                    path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   XStringFormats.Default);

                    // Create a dimmed red pen and brush
                    XPen   pen   = new XPen(XColor.FromArgb(50, 75, 0, 130), 3);
                    XBrush brush = new XSolidBrush(XColor.FromArgb(50, 106, 90, 205));

                    // Stroke the outline of the path
                    gfx.DrawPath(pen, brush, path);
                }
                break;
                }
            }
            // Save the document...
            document.Save(filename);
            // ...and start a viewer
            Process.Start(filename);
        }
コード例 #15
0
        public Stream GeneratePdfLabels(List <string> Addresses, LabelFormat lf, int QtyEachLabel)
        {
            Stream generatePdfLabels = new MemoryStream();
            // The label sheet is basically a table and each cell is a single label
            // Format related
            int CellsPerPage  = lf.RowCount * lf.ColumnCount;
            int CellsThisPage = 0;
            //XRect ContentRectangle = new XRect();       // A single cell content rectangle. This is the rectangle that can be used for contents and accounts for margins and padding.
            XSize  ContentSize = new XSize(); // Size of content area inside a cell.
            double ContentLeftPos;            // left edge of current content area.
            double ContentTopPos;             // Top edge of current content area

            // Layout related
            XColor        StrokeColor = XColors.DarkBlue;
            XColor        FillColor   = XColors.DarkBlue;
            XPen          Pen         = new XPen(StrokeColor, 0.1);
            XBrush        Brush       = new XSolidBrush(FillColor);
            XGraphics     Gfx;
            XGraphicsPath Path = new XGraphicsPath();

            //int LoopTemp = 0;         // Counts each itteration. Used with QtyEachLabel
            int         CurrentColumn = 1;
            int         CurrentRow    = 1;
            PdfDocument Doc           = new PdfDocument();
            PdfPage     page          = new PdfPage();

            //AddPage(Doc, page, lf);
            Doc.AddPage(page);
            Gfx = XGraphics.FromPdfPage(page);

            // Ensure that at least 1 of each label is printed.
            if (QtyEachLabel < 1)
            {
                QtyEachLabel = 1;
            }

            // Define the content area size
            ContentSize = new XSize(XUnit.FromMillimeter(lf.LabelWidth - lf.LabelPaddingLeft - lf.LabelPaddingRight).Point,
                                    XUnit.FromMillimeter(lf.LabelHeight - lf.LabelPaddingTop - lf.LabelPaddingBottom).Point);

            if (Addresses != null)
            {
                if (Addresses.Count > 0)
                // We actually have addresses to output.
                {
                    WriteLine();
                    foreach (string Address in Addresses)
                    {
                        // Once for each address
                        for (int LoopTemp = 0; LoopTemp < QtyEachLabel; LoopTemp++)
                        // Once for each copy of this address.
                        {
                            WriteLine($"Obradjuje se : {Address} ");
                            //WriteLine($"Nalepnica: {CellsThisPage} od :{CellsPerPage} ");
                            if (CellsThisPage == CellsPerPage)
                            {
                                //AddPage(Doc, page, lf);
                                //Gfx = XGraphics.FromPdfPage(page);
                                page          = Doc.AddPage();
                                Gfx           = XGraphics.FromPdfPage(page);
                                CellsThisPage = 0;
                            }
                            // This pages worth of cells are filled up. Create a new page


                            // Calculate which row and column we are working on.
                            CurrentColumn = (CellsThisPage + 1) % lf.ColumnCount;
                            double a = (CellsThisPage + 1) / lf.ColumnCount;
                            CurrentRow = (int)Math.Truncate(a);
                            //WriteLine($"Tekuci red: {CurrentRow} tekuca kolona :{CurrentColumn} ");


                            if (CurrentColumn == 0)
                            {
                                // This occurs when you are working on the last column of the row.
                                // This affects the count for column and row
                                CurrentColumn = lf.ColumnCount;
                            }
                            else
                            {
                                // We are not viewing the last column so this number will be decremented by one.
                                CurrentRow = CurrentRow + 1;
                            }



                            // Calculate the left position of the current cell.
                            ContentLeftPos = ((CurrentColumn - 1) * lf.HorizontalPitch) + lf.LeftMargin + lf.LabelPaddingLeft;


                            // Calculate the top position of the current cell.
                            ContentTopPos = ((CurrentRow - 1) * lf.VerticalPitch) + lf.TopMargin + lf.LabelPaddingTop;
                            //WriteLine($"Leva pozicija: {ContentLeftPos} Pozicija od vrha :{ContentTopPos} Velicina sadrzaja : {ContentSize} ");


                            // Define the content rectangle.
                            XPoint xpoint1 = new XPoint(XUnit.FromMillimeter(ContentLeftPos).Point, XUnit.FromMillimeter(ContentTopPos).Point);

                            XRect ContentRectangle = new XRect(xpoint1, ContentSize);


                            Path = new XGraphicsPath();


                            // Add the address string to the page.
                            Path.AddString(Address, new XFontFamily("Arial"),
                                           XFontStyle.Regular,
                                           9,
                                           ContentRectangle,
                                           XStringFormats.TopLeft);


                            Gfx.DrawPath(Pen, Brush, Path);


                            // Increment the cell count
                            CellsThisPage = CellsThisPage + 1;
                        }
                    }
                    Doc.Save(generatePdfLabels, false);
                }
            }
            return(generatePdfLabels);
        }
コード例 #16
0
        static void Main()
        {
            const string watermark = "PDFsharp";
            const int    emSize    = 150;

            // Get a fresh copy of the sample PDF file.
            const string filename = "Portable Document Format.pdf";
            var          file     = Path.Combine(Directory.GetCurrentDirectory(), filename);

            File.Copy(Path.Combine("../../../../assets/PDFs/", filename), file, true);

            // Remove ReadOnly attribute from the copy.
            File.SetAttributes(file, File.GetAttributes(file) & ~FileAttributes.ReadOnly);

            // Create the font for drawing the watermark.
            var font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic);

            // Open an existing document for editing and loop through its pages.
            var document = PdfReader.Open(filename);

            // Set version to PDF 1.4 (Acrobat 5) because we use transparency.
            if (document.Version < 14)
            {
                document.Version = 14;
            }

            for (var idx = 0; idx < document.Pages.Count; idx++)
            {
                var page = document.Pages[idx];

                switch (idx % 3)
                {
                case 0:
                {
                    // Variation 1: Draw a watermark as a text string.

                    // Get an XGraphics object for drawing beneath the existing content.
                    var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

                    // Get the size (in points) of the text.
                    var size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page.
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a string format.
                    var format = new XStringFormat();
                    format.Alignment     = XStringAlignment.Near;
                    format.LineAlignment = XLineAlignment.Near;

                    // Create a dimmed red brush.
                    XBrush brush = new XSolidBrush(XColor.FromArgb(128, 255, 0, 0));

                    // Draw the string.
                    gfx.DrawString(watermark, font, brush,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   format);
                }
                break;

                case 1:
                {
                    // Variation 2: Draw a watermark as an outlined graphical path.
                    // NYI: Does not work in Core build.

                    // Get an XGraphics object for drawing beneath the existing content.
                    var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend);

                    // Get the size (in points) of the text.
                    var size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page.
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a graphical path.
                    var path = new XGraphicsPath();

                    // Create a string format.
                    var format = new XStringFormat();
                    format.Alignment     = XStringAlignment.Near;
                    format.LineAlignment = XLineAlignment.Near;

                    // Add the text to the path.
                    // AddString is not implemented in PDFsharp Core.
                    path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   format);

                    // Create a dimmed red pen.
                    var pen = new XPen(XColor.FromArgb(128, 255, 0, 0), 2);

                    // Stroke the outline of the path.
                    gfx.DrawPath(pen, path);
                }
                break;

                case 2:
                {
                    // Variation 3: Draw a watermark as a transparent graphical path above text.
                    // NYI: Does not work in Core build.

                    // Get an XGraphics object for drawing above the existing content.
                    var gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

                    // Get the size (in points) of the text.
                    var size = gfx.MeasureString(watermark, font);

                    // Define a rotation transformation at the center of the page.
                    gfx.TranslateTransform(page.Width / 2, page.Height / 2);
                    gfx.RotateTransform(-Math.Atan(page.Height / page.Width) * 180 / Math.PI);
                    gfx.TranslateTransform(-page.Width / 2, -page.Height / 2);

                    // Create a graphical path.
                    var path = new XGraphicsPath();

                    // Create a string format.
                    var format = new XStringFormat();
                    format.Alignment     = XStringAlignment.Near;
                    format.LineAlignment = XLineAlignment.Near;

                    // Add the text to the path.
                    // AddString is not implemented in PDFsharp Core.
                    path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                                   new XPoint((page.Width - size.Width) / 2, (page.Height - size.Height) / 2),
                                   format);

                    // Create a dimmed red pen and brush.
                    var    pen   = new XPen(XColor.FromArgb(50, 75, 0, 130), 3);
                    XBrush brush = new XSolidBrush(XColor.FromArgb(50, 106, 90, 205));

                    // Stroke the outline of the path.
                    gfx.DrawPath(pen, brush, path);
                }
                break;
                }
            }
            // Save the document...
            document.Save(filename);
            // ...and start a viewer
            Process.Start(filename);
        }