/// <summary>
        /// Create the watermarks.
        /// </summary>
        /// <returns>An array of watermarks to apply</returns>
        public static Watermark[] CreateWatermarks()
        {
            List <Watermark> watermarks = new List <Watermark>();

            // ** Specify the default settings for properties
            Defaults wmDefaults = new Defaults();

            wmDefaults.FillColor      = "#000000";
            wmDefaults.LineColor      = "#000000";
            wmDefaults.FontFamilyName = "Arial";
            wmDefaults.FontSize       = "10";

            // **************** 'Confidential' Text ***************

            // ** 'Confidential' watermark for front page
            Watermark confidential = new Watermark();

            confidential.Defaults  = wmDefaults;
            confidential.StartPage = 1;
            confidential.EndPage   = 1;
            confidential.Rotation  = "-45";
            confidential.Width     = "500";
            confidential.Height    = "500";
            confidential.HPosition = HPosition.Center;
            confidential.VPosition = VPosition.Middle;
            confidential.ZOrder    = -1;

            // ** Create a new Text element that goes inside the watermark
            Text cfText = new Text();

            cfText.Content      = "Confidential";
            cfText.FontSize     = "40";
            cfText.FontStyle    = FontStyle.Bold | FontStyle.Italic;
            cfText.Width        = "500";
            cfText.Height       = "500";
            cfText.Transparency = "0.10";

            // ** And add it to the list of watermark elements.
            confidential.Elements = new Element[] { cfText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(confidential);


            // **************** Watermark for Odd pages ***************

            Watermark oddPages = new Watermark();

            oddPages.Defaults     = wmDefaults;
            oddPages.StartPage    = 3;
            oddPages.PageInterval = 2;
            oddPages.Width        = "600";
            oddPages.Height       = "50";
            oddPages.HPosition    = HPosition.Right;
            oddPages.VPosition    = VPosition.Bottom;

            // ** Add a horizontal line
            Line line = new Line();

            line.X     = "1";
            line.Y     = "1";
            line.EndX  = "600";
            line.EndY  = "1";
            line.Width = "5";

            // ** Add a page counter
            Text oddText = new Text();

            oddText.Content   = "Page: {PAGE} of {NUMPAGES}";
            oddText.Width     = "100";
            oddText.Height    = "20";
            oddText.X         = "475";
            oddText.Y         = "15";
            oddText.LineWidth = "-1";
            oddText.FontStyle = FontStyle.Regular;
            oddText.HAlign    = HAlign.Right;

            // ** And add it to the list of watermark elements
            oddPages.Elements = new Element[] { line, oddText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(oddPages);

            // **************** Watermark for Even pages ***************

            Watermark evenPages = new Watermark();

            evenPages.Defaults     = wmDefaults;
            evenPages.StartPage    = 2;
            evenPages.PageInterval = 2;
            evenPages.Width        = "600";
            evenPages.Height       = "50";
            evenPages.HPosition    = HPosition.Left;
            evenPages.VPosition    = VPosition.Bottom;

            // ** No need to create an additional line,re-use the previous one

            // ** Add a page counter
            Text evenText = new Text();

            evenText.Content   = "Page: {PAGE} of {NUMPAGES}";
            evenText.Width     = "100";
            evenText.Height    = "20";
            evenText.X         = "25";
            evenText.Y         = "15";
            evenText.LineWidth = "-1";
            evenText.FontStyle = FontStyle.Regular;
            evenText.HAlign    = HAlign.Left;

            // ** And add it to the list of watermark elements
            evenPages.Elements = new Element[] { line, evenText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(evenPages);

            return(watermarks.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create the watermarks.
        /// </summary>
        /// <returns>An array of watermarks to apply</returns>
        public static Watermark[] CreateWatermarks()
        {
            List <Watermark> watermarks = new List <Watermark>();

            // ** Specify the default settings for properties
            Defaults wmDefaults = new Defaults();

            wmDefaults.FillColor      = "#000000";
            wmDefaults.LineColor      = "#000000";
            wmDefaults.FontFamilyName = "Arial";
            wmDefaults.FontSize       = "10";

            // **************** 'Confidential' Text ***************

            // ** 'Confidential' watermark for front page
            Watermark confidential = new Watermark();

            confidential.Defaults  = wmDefaults;
            confidential.Rotation  = "-45";
            confidential.Width     = "500";
            confidential.Height    = "500";
            confidential.HPosition = HPosition.Center;
            confidential.VPosition = VPosition.Middle;
            confidential.ZOrder    = -1;
            // ** For PowerPoint traditional page numbering is used
            confidential.StartPage = 1;
            confidential.EndPage   = 1;
            // ** In case of Word and Excel this only appears on pages which has 'First Page Header'
            confidential.PageType = PageType.First;

            // ** Create a new Text element that goes inside the watermark
            Text cfText = new Text();

            cfText.Content      = "Confidential";
            cfText.FontSize     = "40";
            cfText.FontStyle    = FontStyle.Bold | FontStyle.Italic;
            cfText.Width        = "500";
            cfText.Height       = "500";
            cfText.Transparency = "0.10";

            // ** And add it to the list of watermark elements.
            confidential.Elements = new Element[] { cfText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(confidential);


            // **************** Watermark for Odd pages ***************

            Watermark oddPages = new Watermark();

            oddPages.Defaults  = wmDefaults;
            oddPages.Width     = "600";
            oddPages.Height    = "50";
            oddPages.HPosition = HPosition.Right;
            oddPages.VPosition = VPosition.Bottom;
            // ** For PowerPoint traditional page numbering is used
            oddPages.StartPage = 3;
            oddPages.EndPage   = 2;
            // ** In case of Word and Excel this only appears on pages which has 'Odd Page Header'
            oddPages.PageType = PageType.Default;

            // ** Add a horizontal line
            Line line = new Line();

            line.X     = "1";
            line.Y     = "1";
            line.EndX  = "600";
            line.EndY  = "1";
            line.Width = "5";

            // ** Add a page counter
            Text oddText = new Text();

            oddText.Content   = "Page: {PAGE} of {NUMPAGES}";
            oddText.Width     = "100";
            oddText.Height    = "20";
            oddText.X         = "475";
            oddText.Y         = "15";
            oddText.LineWidth = "-1";
            oddText.FontStyle = FontStyle.Regular;
            oddText.HAlign    = HAlign.Right;

            // ** And add it to the list of watermark elements
            oddPages.Elements = new Element[] { line, oddText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(oddPages);

            // **************** Watermark for Even pages ***************

            Watermark evenPages = new Watermark();

            evenPages.Defaults  = wmDefaults;
            evenPages.Width     = "600";
            evenPages.Height    = "50";
            evenPages.HPosition = HPosition.Left;
            evenPages.VPosition = VPosition.Bottom;
            // ** For PowerPoint traditional page numbering is used
            evenPages.StartPage    = 2;
            evenPages.PageInterval = 2;
            // ** In case of Word and Excel this only appears on pages which has 'Even Page Header'
            evenPages.PageType = PageType.Even;

            // ** No need to create an additional line,re-use the previous one

            // ** Add a page counter
            Text evenText = new Text();

            evenText.Content   = "Page: {PAGE} of {NUMPAGES}";
            evenText.Width     = "100";
            evenText.Height    = "20";
            evenText.X         = "25";
            evenText.Y         = "15";
            evenText.LineWidth = "-1";
            evenText.FontStyle = FontStyle.Regular;
            evenText.HAlign    = HAlign.Left;

            // ** And add it to the list of watermark elements
            evenPages.Elements = new Element[] { line, evenText };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(evenPages);

            // **************** Watermark for all pages except first ***************

            Watermark contentPages = new Watermark();

            contentPages.Defaults  = wmDefaults;
            contentPages.Width     = "200";
            contentPages.Height    = "85";
            contentPages.HPosition = HPosition.Center;
            contentPages.VPosition = VPosition.Bottom;
            // ** For PowerPoint traditional page numbering is used
            contentPages.StartPage = 2;
            // ** In case of Word and Excel this only appears on pages which does not have 'First Page Header'
            contentPages.PageType = PageType.Even | PageType.Default;

            // ** Add a barcode
            LinearBarcode barcode = new LinearBarcode();

            barcode.Text        = "012345678";
            barcode.BarcodeType = BarcodeType.Code39;
            // ** Change fill color to white because wmDefaults defines it as black
            barcode.FillColor = "#ffffff";
            barcode.LineColor = "#000000";
            barcode.Width     = "200";
            barcode.Height    = "50";
            barcode.HPosition = HPosition.Center;
            barcode.VPosition = VPosition.Top;

            // ** And add it to the list of watermark elements
            contentPages.Elements = new Element[] { barcode };

            // ** And add the watermark to the list of watermarks
            watermarks.Add(contentPages);

            return(watermarks.ToArray());
        }