This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Machine Learning with R: Expert techniques for predictive modeling and have Brett Lantz on-line!
See this thread for details.
Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How to Add Tiled Text or Image Watermarks to PDF in Java

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding tiled watermarks to PDF documents is an effective way to prevent documents from being pirated. A tiled watermark lets you have tiles of your watermark all over a PDF page. You can specify either a text to be used as a tile, or you can specify a picture for that. This article will demonstrate how to add a tiling watermark effect to PDF documents using Free Spire.PDF for Java.

Before start, you should learn about two important concepts in Spire.PDF – tiling brush and coordinate system. A tiling brush, represented by PdfTitlingBrush class, is used to define the contents of the tile that you use to paint a region. A coordinate system is used to determine where the contents (text or/and images) shoule be placed on a tile.

How is the coordinate system defined?

  • The origin of the coordinate system (0, 0) represents the top-left corner of a graphics in Spire.PDF.
  • The x-axis extends to the right and the y-axis extends downward.

  • How to create a tiling brush?

  • Step 1. Create a PdfTilingBrush object. Set its width and height to half of the width and height of a PDF page respectively. You can change the ratio according to the actual situation.
  • Step 2: Translate coordinate system to the lower right.
  • Step 3: Rotate coordinate system 45 degrees. Step 2 and step 3 enable that the text watermark lies in the center of the brush and is tilted at 45 degrees.
  • Step 4: Draw text from the starting point (0, 0) of the new coordinate system.



  • If you want to place an image at the center of a brush, you do not need to transform the coordinate system but calculate the X, Y coordinates directly. After a tiling brush is created, you can use it to paint the whole area of a page to get a tiling background effect.



    The following sections provide detailed code snippets showing you how to add text and image watermarks to PDF.

    Adding tiled text watermark
    Output:


    Adding tiled image watermark

    Output:

     
    What a show! What atmosphere! What fun! What a tiny ad!
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!