Package org.pdfclown.tools

Examples of org.pdfclown.tools.PageStamper


    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...
    for(Page page : watermark.getDocument().getPages())
    {
      // 2.1. Associate the page to the stamper!
      stamper.setPage(page);

      // 2.2. Stamping the watermark on the background...
      // Get the background 'layer' of the page!
      PrimitiveComposer background = stamper.getBackground();
      // Show the watermark into the page background!
      background.showXObject(watermark);

      // 2.3. End the stamping!
      stamper.flush();
    }
  }
View Full Code Here


    catch(Exception e)
    {throw new RuntimeException(filePath + " file access error.",e);}

    Document document = file.getDocument();
   
    PageStamper stamper = new PageStamper(); // NOTE: Page stamper is used to draw contents on existing pages.
   
    // 2. Iterating through the document pages...
    for(Page page : document.getPages())
    {
      System.out.println("\nScanning page " + (page.getIndex()+1) + "...\n");

      stamper.setPage(page);

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

      stamper.flush();
    }

    // 3. Decorated version serialization.
    serialize(file,false);
   
View Full Code Here

    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 = new DeviceRGBColor(1, 0, 0);
    int margin = 32;
    for(Page page : document.getPages())
    {
      // 2.1. Associate the page to the stamper!
      stamper.setPage(page);

      // 2.2. Stamping the page number on the foreground...
      {
        PrimitiveComposer foreground = stamper.getForeground();

        foreground.setFont(font,16);
        foreground.setFillColor(redColor);

        Dimension2D pageSize = page.getSize();
        int pageNumber = page.getIndex() + 1;
        boolean pageIsEven = (pageNumber % 2 == 0);
        foreground.showText(
          Integer.toString(pageNumber),
          new Point2D.Double(
            (pageIsEven
              ? margin
              : pageSize.getWidth() - margin),
            pageSize.getHeight() - margin
            ),
          (pageIsEven
            ? AlignmentXEnum.Left
            : AlignmentXEnum.Right),
          AlignmentYEnum.Bottom,
          0
          );
      }

      // 2.3. End the stamping!
      stamper.flush();
    }
  }
View Full Code Here

TOP

Related Classes of org.pdfclown.tools.PageStamper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.