示例#1
0
        public override void Run(
            )
        {
            // 1. Opening the PDF file...
            string filePath = PromptFileChoice("Please select a PDF file");

            using (var file = new File(filePath))
            {
                Document document = file.Document;

                PageStamper stamper = new PageStamper(); // NOTE: Page stamper is used to draw contents on existing pages.

                // 2. Iterating through the document pages...
                foreach (Page page in document.Pages)
                {
                    Console.WriteLine("\nScanning page " + page.Number + "...\n");

                    stamper.Page = page;

                    Extract(
                        new ContentScanner(page), // Wraps the page contents into a scanner.
                        stamper.Foreground
                        );

                    stamper.Flush();
                }

                // 3. Decorated version serialization.
                Serialize(file);
            }
        }
示例#2
0
        private void Stamp(
            Document document
            )
        {
            // 1. Instantiate the stamper!
            /* NOTE: The PageStamper is optimized for dealing with pages. */
            PageStamper stamper = new PageStamper();

            // 2. Numbering each page...
            StandardType1Font font = new StandardType1Font(
                document,
                StandardType1Font.FamilyEnum.Courier,
                true,
                false
                );
            DeviceRGBColor redColor = DeviceRGBColor.Get(SKColors.Red);
            int            margin   = 32;

            foreach (Page page in document.Pages)
            {
                // 2.1. Associate the page to the stamper!
                stamper.Page = page;

                // 2.2. Stamping the page number on the foreground...
                {
                    PrimitiveComposer foreground = stamper.Foreground;

                    foreground.SetFont(font, 16);
                    foreground.SetFillColor(redColor);

                    SKSize pageSize   = page.Size;
                    int    pageNumber = page.Number;
                    bool   pageIsEven = (pageNumber % 2 == 0);
                    foreground.ShowText(
                        pageNumber.ToString(),
                        new SKPoint(
                            (pageIsEven
                          ? margin
                          : pageSize.Width - margin),
                            pageSize.Height - margin
                            ),
                        (pageIsEven
                        ? XAlignmentEnum.Left
                        : XAlignmentEnum.Right),
                        YAlignmentEnum.Bottom,
                        0
                        );
                }

                // 2.3. End the stamping!
                stamper.Flush();
            }
        }
示例#3
0
        private void ApplyWatermark(FormXObject watermark)
        {
            // 1. Instantiate the stamper!
            /* NOTE: The PageStamper is optimized for dealing with pages. */
            PageStamper stamper = new PageStamper();

            // 2. Inserting the watermark into each page of the document...
            foreach (Page page in watermark.Document.Pages)
            {
                // 2.1. Associate the page to the stamper!
                stamper.Page = page;

                // 2.2. Stamping the watermark on the foreground...
                // Get the content composer!
                PrimitiveComposer composer = stamper.Foreground;
                // Show the watermark into the page background!
                composer.ShowXObject(watermark);

                // 2.3. End the stamping!
                stamper.Flush();
            }
        }