English

Watermark PDF, Word, Excel, PowerPoint & image files in .NET and Java

Add or remove watermarks from PDF, DOCX, XLSX, PPTX, ODT, RTF, TXT, VSD, EML, MSG, PNG, and JPG files in .NET and Java. Preserve your digital assets by accurately applying text and image-based watermarks.

Try our APIs for FreeGet Temporary License

Watermark documents and images to amplify the protection of your digital content

Watermarking is the process of adding a logo or other identifying mark to a digital file. The purpose of a watermark is to identify the file's owner, assert copyrighting, deter unauthorized access to your content, and add branding to your assets. You may also use watermarks to track a file’s origin and prevent others from stealing or using your content without permission. There are several ways to watermark digital content, the most common being to add a visual mark to the file in text or image, using an app or a software program.

Automating the process would make it more efficient if you regularly watermark documents and images of different types, thus saving loads of time and effort. This is where GroupDocs.Watermark APIs for .NET and Java are extremely useful. They make the watermarking process simpler, boost effectiveness, and enable you to ensure the protection of your digital images and documents. You can build C#, VB.NET, and Java apps to add or remove watermarks of text and image types in PDF, Word, Excel, PowerPoint, OpenDocument, Visio, Email, Rich Text, and different image files.

Getting started

To successfully run the code samples shared in the subsequent sections and set up your working environment, please ensure having correctly installed GroupDocs.Watermark API for .NET or Java versions along with any other prerequisites.

We provide several installation options for the .NET and Java versions, please review the information shared below for more help.

GroupDocs.Watermark for .NET installation

You can install via NuGet, or directly download the MSI installer or DLLs from the downloads section. The command for the Package Manager Console is given below:

PM> Install-Package GroupDocs.Watermark 

GroupDocs.Watermark for Java installation

Please visit the downloads section for obtaining the JAR file, or, use the latest Maven configuration in your Java apps:

<repository>
    <id>GroupDocsJavaAPI</id>
    <name>GroupDocs Java API</name>
        <url>https://repository.groupdocs.com/repo/</url>
</repository>
<dependency>
        <groupId>com.groupdocs</groupId>
            <artifactId>groupdocs-watermark</artifactId>
        <version>21.3</version> 
</dependency>

Use cases for adding or removing watermarks in .NET and Java

After configuring GroupDocs.Watermark (for .NET or Java) successfully, we can review some of the most common use cases to watermark documents and images.

Use cases for adding or removing watermarks in .NET and Java

How to add watermarks to Word documents in .NET and Java?

Text watermarks are a widely used type of watermark that can be used to protect sensitive content in digitally processed files. You can prevent unauthorized copying or printing of a file using text-based watermarks. GroupDocs.Watermark APIs allow .NET and Java developers to integrate the functionality of watermarking Word documents into their existing software modules or build applications for mobile or HTML web interfaces enabling users to enjoy text watermarking features effortlessly.

How to add watermarks to Word documents in .NET and Java?

Apply text watermarks to word-processing documents in .NET

If you are looking to watermark Word documents by inserting text-based watermarks please use the C# code given below:

    WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
using (Watermarker watermarker = new Watermarker("path/sample.docx”, loadOptions))
{
    TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));
    Apply watermark settings
    watermark.VerticalAlignment = VerticalAlignment.Center;
    watermark.HorizontalAlignment = HorizontalAlignment.Center;
    watermark.RotateAngle = 25.0;
    watermark.ForegroundColor = Color.Red;
    watermark.Opacity = 1.0;

    WordProcessingWatermarkSectionOptions options = new WordProcessingWatermarkSectionOptions();

    // Setting shape name
    options.Name = "Shape 1";

    // Set the descriptive (alternative) text to be associated with the shape
    options.AlternativeText = "Test watermark";

    watermarker.Add(watermark, options);
    watermarker.Save("path/document-text-watermarked.docx”);
} 

Insert a text-based watermark to Word documents in Java

You can also watermark Word documents by adding text watermarks in Java using the following sample coding:

    WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();                                   
Watermarker watermarker = new Watermarker(("path/sample.docx”, loadOptions);                          
                                                                                                           
TextWatermark watermark = new TextWatermark("Test watermark", new Font("Arial", 19));                      
                                                                                                           
//Apply watermark settings                                                                             
watermark.setVerticalAlignment(VerticalAlignment.Center);                                                  
watermark.setHorizontalAlignment(HorizontalAlignment.Center);                                              
watermark.setRotateAngle(25.0);                                                                            
watermark.setForegroundColor(Color.getRed());                                                              
watermark.setOpacity(1.0);                                                                                 
                                                                                                           
WordProcessingWatermarkSectionOptions options = new WordProcessingWatermarkSectionOptions();               
                                                                                                           
// Setting the shape name                                                                                      
options.setName("Shape 1");                                                                                
                                                                                                           
// Set the descriptive (alternative) text to be associated with the shape                           
options.setAlternativeText("Test watermark");                                                              
                                                                                                           
watermarker.add(watermark, options);                                                                       
                                                                                                           
watermarker.save(("path/document-text-watermarked.docx”);                                                               
                                                                                                           
watermarker.close();      

An easy way to add image-based watermarks to PDF documents in C# .NET and Java apps

Using images as watermarks is a great way to label legal or official documents as they are easier to add and difficult to remove compared to text watermarks. Image-based watermarks can also be used effectively to add branding or other information to a document. GroupDocs.Watermark APIs support multiple types of image-based watermarks for your PDF files in .NET and Java.

An easy way to add image-based watermarks to PDF documents in C# .NET and Java apps

Add image-based watermarks to PDF documents in .NET

Watermark PDF documents with image-based labels using the C# code shown below:

// Add image watermark to PDF file page(s) 
PdfLoadOptions loadOptions = new PdfLoadOptions();
using (Watermarker watermarker = new Watermarker("path/sample.pdf", loadOptions))
{
     
    ImageWatermark imageWatermark = new ImageWatermark("watermark-image.png")
    {
        // Setting watermark appearance
        Opacity = 0.7,
        X = 70,
        Y = 350
    };
    // Adding image watermark to the second page (page index starts from zero)  
    PdfArtifactWatermarkOptions imageWatermarkOptions = new PdfArtifactWatermarkOptions();
    imageWatermarkOptions.PageIndex = 1;
    watermarker.Add(imageWatermark, imageWatermarkOptions);

    watermarker.Save("path/image-watermarked.pdf");
}    

Watermark PDF files in Java applications with images

To watermark PDF files in Java with image labels, please use this sample code:

// Apply Image Watermark to the second page of the PDF file 
PdfLoadOptions loadOptions = new PdfLoadOptions();
Watermarker watermarker = new Watermarker("path/sample.pdf", loadOptions);

// Load image and set appearance
ImageWatermark imageWatermark = new ImageWatermark(Constants.LockPng);
imageWatermark.setOpacity(0.7);
imageWatermark.setX(130);
imageWatermark.setY(390);

// Add watermark image to the second page of the PDF file (page index starts at zero)
PdfArtifactWatermarkOptions imageWatermarkOptions = new PdfArtifactWatermarkOptions();
imageWatermarkOptions.setPageIndex(1);
watermarker.add(imageWatermark, imageWatermarkOptions);
imageWatermark.close();

// Save the watermarked PDF
watermarker.save("path/image-watermarked.pdf");
watermarker.close();     

How to add watermarks to Excel spreadsheets and PowerPoint presentations in .NET and Java?

Microsoft Excel and PowerPoint are two of the most widely used spreadsheet and presentation data types. Users the world over extensively utilize these software applications for reporting, product demonstrations, and many other purposes. GroupDocs.Watermark for .NET and Java APIs enable app developers to programmatically add watermarks to both these data file types. You can add watermarks of text and image types to Excel and PowerPoint documents without requiring Microsoft Office.

How to add watermarks to Excel spreadsheets and PowerPoint presentations in .NET and Java?

Watermark Excel and PowerPoint documents with text and images in .NET

To add watermarks to Excel spreadsheets of text or image type in .NET, please make use of the following C# sample coding:

    SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
    using (Watermarker watermarker = new Watermarker(“path/sample.xlsx”, loadOptions))
    {
        // Add text watermark to the first worksheet
        TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
        SpreadsheetWatermarkShapeOptions textWatermarkOptions = new SpreadsheetWatermarkShapeOptions();
        textWatermarkOptions.WorksheetIndex = 0;
        watermarker.Add(textWatermark, textWatermarkOptions);
    
        // Add image watermark to the second worksheet
        using (ImageWatermark imageWatermark = new ImageWatermark(“watermark-image.jpg”))
        {
            SpreadsheetWatermarkShapeOptions imageWatermarkOptions = new SpreadsheetWatermarkShapeOptions();
            imageWatermarkOptions.WorksheetIndex = 1;
            watermarker.Add(imageWatermark, imageWatermarkOptions);
        }
    
        watermarker.Save(“path/text-image-watermarked.xlsx”);
    }
    
    //Similarly, please use this sample code if you are looking to watermark presentations in .NET: 
    PresentationLoadOptions loadOptions = new PresentationLoadOptions();
    using (Watermarker watermarker = new Watermarker(“path/sample.pptx”, loadOptions))
    {
        // Add text watermark to the first slide
        TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));
        PresentationWatermarkSlideOptions textWatermarkOptions = new PresentationWatermarkSlideOptions();
        textWatermarkOptions.SlideIndex = 0;
        watermarker.Add(textWatermark, textWatermarkOptions);
    
        // Add image watermark to the second slide
        using (ImageWatermark imageWatermark = new ImageWatermark(“path/watermark-image.jpg”))
        {
            PresentationWatermarkSlideOptions imageWatermarkOptions = new PresentationWatermarkSlideOptions();
            imageWatermarkOptions.SlideIndex = 1;
            watermarker.Add(imageWatermark, imageWatermarkOptions);
        }
    
        watermarker.Save(“path/text-image-watermarked.pptx”);
    }        

Watermark Excel and PowerPoint files with text and image labels in Java

Please use the code sample shared below for adding text or image-based watermarks to your Excel spreadsheets in Java:

    SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();                                               
    Watermarker watermarker = new Watermarker(“path/sample.xlsx”, loadOptions);                             
                                                                                                                     
    // Add text watermark to the first worksheet                                                                     
    TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));                         
    SpreadsheetWatermarkShapeOptions textWatermarkOptions = new SpreadsheetWatermarkShapeOptions();                  
    textWatermarkOptions.setWorksheetIndex(0);                                                                       
    watermarker.add(textWatermark, textWatermarkOptions);                                                            
                                                                                                                     
    // Add image watermark to the second worksheet                                                                   
    ImageWatermark imageWatermark = new ImageWatermark(“watermark-image.jpg”);                                           
                                                                                                                     
    SpreadsheetWatermarkShapeOptions imageWatermarkOptions = new SpreadsheetWatermarkShapeOptions();                 
    imageWatermarkOptions.setWorksheetIndex(1);                                                                      
    watermarker.add(imageWatermark, imageWatermarkOptions);                                                          
                                                                                                                     
    watermarker.save(“path/text-image-watermarked.xlsx”);                                                                  
                                                                                                                     
    watermarker.close();                                                                                             
    imageWatermark.close();
    
    //And, to add text or image watermarks to presentations in Java, please use this code: 
    PresentationLoadOptions loadOptions = new PresentationLoadOptions();                                               
    Watermarker watermarker = new Watermarker(“path/samples.pptx”, loadOptions);                              
                                                                                                                       
    // Add text watermark to the first slide                                                                           
    TextWatermark textWatermark = new TextWatermark("Test watermark", new Font("Arial", 8));                           
    PresentationWatermarkSlideOptions textWatermarkOptions = new PresentationWatermarkSlideOptions();                  
    textWatermarkOptions.setSlideIndex(0);                                                                             
    watermarker.add(textWatermark, textWatermarkOptions);                                                              
                                                                                                                       
    // Add image watermark to the second slide                                                                         
    ImageWatermark imageWatermark = new ImageWatermark(“watermark-image.jpg”);                                             
                                                                                                                       
    PresentationWatermarkSlideOptions imageWatermarkOptions = new PresentationWatermarkSlideOptions();                 
    imageWatermarkOptions.setSlideIndex(1);                                                                            
    watermarker.add(imageWatermark, imageWatermarkOptions);                                                            
                                                                                                                       
    watermarker.save(“path/text-image-watermarked.pptx”);                                                                   
                                                                                                                       
    watermarker.close();                                                                                               
    imageWatermark.close(); 

Learn to watermark photos and images in .NET and Java

Just like with different types of documents, you may also need to add an identifier to your images. Due to the immense popularity of content sharing on social platforms, watermarking photos has also become increasingly significant to prevent misuse. Users prefer embedding text or image watermarks to photos before publishing them on the social platform of their choice. GroupDocs.Watermark APIs provide a set of tools to easily add watermarks to PNG, JPG, TIFF, and GIF image files in .NET and Java platforms.

Learn to watermark photos and images in .NET and Java

Embed text watermarks into images in .NET

If you are looking to add watermarks to images using text labels, please use the following C# code which watermarks a JPG image:

    using (Watermarker watermarker = new Watermarker("filePath/sample-image.jpg"))
    {
        // Set the Text and Watermark Font
        Font font = new Font ("Arial", 30, FontStyle.Bold | FontStyle.Italic);
        TextWatermark watermark = new TextWatermark("Text Watermark", font);
    
        // Set Watermark Properties
        watermark.ForegroundColor = Color.Black;
        watermark.TextAlignment = TextAlignment.Right;
        watermark.X = 70;
        watermark.Y = 70;
        watermark.RotateAngle = -30;
        watermark.Opacity = 0.4;
        // watermark.BackgroundColor = Color.Blue;
    
        // Apply the configured watermark to JPG Image
        watermarker.Add(watermark);
        watermarker.Save("filePath/text-watermarked.jpg");
    }        

Watermark images and your photos in Java

You can add watermarks to your photos and other images in Java too. Please use the following Java code to watermark a PNG image:

    TextWatermark watermark = new TextWatermark("Text Watermark", new Font("Arial", 30, FontStyle.Bold | FontStyle.Italic));

    // Set Watermark properties
    watermark.setForegroundColor(Color.getBlack());
    watermark.setTextAlignment(TextAlignment.Right);
    watermark.setRotateAngle(-30);
    watermark.setOpacity(0.4);
    watermark.setX(70);
    watermark.setY(70);
    
    // Apply Watermark to the source PNG Image
    Watermarker watermarker = new Watermarker(“path/sample-image.png”);
    watermarker.add(watermark);
    watermarker.save(“path/text-watermarked.png”);
    watermarker.close();     

Search and remove watermarks in your .NET and Java watermarking apps

Searching and removing the existing watermarks from documents is an important aspect of cleaning or sanitizing the files, or, it could be a business requirement. Consider the scenario of deleting outdated branding added to your digital assets and replacing it with the latest version. With the help of GroupDocs.Watermark APIs for .NET and Java, you can not only add several types of watermarks to data files but also search through the added watermark objects and remove them too.

Search and remove watermarks in your .NET and Java watermarking apps

Find and remove watermarks added to your .NET files

To find the watermark in Word, Excel, PowerPoint, PDF, or Visio files in .NET based on some specific criteria, please use this C# sample coding:

    using (Watermarker watermarker = new Watermarker(“path/sample.pdf”))
{
    // Apply the exact text search string
    TextSearchCriteria textSearchCriteria = new TextSearchCriteria("© 2019");
    // Find all possible watermarks containing the specified text
    PossibleWatermarkCollection possibleWatermarks = watermarker.Search(textSearchCriteria);
    Console.WriteLine("Found {0} possible watermark(s)", possibleWatermarks.Count);
} 

Along with searching the existing watermark labels from your files, you can also remove them. Please use this C# coding for removing watermark with the specified formatting:

    using (Watermarker watermarker = new Watermarker(“path/sample.pdf”))
    {
        TextFormattingSearchCriteria criteria = new TextFormattingSearchCriteria();
        criteria.ForegroundColorRange = new ColorRange();
        criteria.ForegroundColorRange.MinHue = -5;
        criteria.ForegroundColorRange.MaxHue = 10;
        criteria.ForegroundColorRange.MinBrightness = 0.01f;
        criteria.ForegroundColorRange.MaxBrightness = 0.99f;
        criteria.BackgroundColorRange = new ColorRange();
        criteria.BackgroundColorRange.IsEmpty = true;
        criteria.FontName = "Arial";
        criteria.MinFontSize = 19;
        criteria.MaxFontSize = 42;
        criteria.FontBold = true;
    
        PossibleWatermarkCollection watermarks = watermarker.Search(criteria);
        watermarks.Clear();
    
        watermarker.Save(“path/watermark-removed.pdf”);
    }    

Locate and delete watermarks from data files in Java

You can search watermarks in Word, PDF, Excel, and PowerPoint documents in Java. The following code is used to search watermarks on a text search criterion:

    Watermarker watermarker = new Watermarker(“path/sample.pdf”);                                      
                                                                                                         
// Apply the exact text search string                                                                                
TextSearchCriteria textSearchCriteria = new TextSearchCriteria("© 2019");                                
                                                                                                         
// Find all possible watermarks containing the specified text                                            
PossibleWatermarkCollection possibleWatermarks = watermarker.search(textSearchCriteria);                 
System.out.println("Found " + possibleWatermarks.getCount() + " possible watermark(s)");                                                                                                     
watermarker.close(); 

Removing any existing watermark labels in Java is also possible with GroupDocs.Watermark for Java API. This Java coding removes a watermark with specific formatting:

Watermarker watermarker = new Watermarker(“path/sample.pdf”);                                      
                                                                                                         
TextFormattingSearchCriteria criteria = new TextFormattingSearchCriteria();                              
criteria.setForegroundColorRange(new ColorRange());                                                      
criteria.getForegroundColorRange().setMinHue(-5);                                                        
criteria.getForegroundColorRange().setMaxHue(10);                                                        
criteria.getForegroundColorRange().setMinBrightness(0.01f);                                              
criteria.getForegroundColorRange().setMaxBrightness(0.99f);                                              
criteria.setBackgroundColorRange(new ColorRange());                                                      
criteria.getBackgroundColorRange().setEmpty(true);                                                       
criteria.setFontName("Arial");                                                                           
criteria.setMinFontSize(19);                                                                             
criteria.setMaxFontSize(42);                                                                             
criteria.setFontBold(true);                                                                              
                                                                                                         
PossibleWatermarkCollection watermarks = watermarker.search(criteria);                                   
watermarks.clear();                                                                                      
watermarker.save(“path/watermark-removed.pdf”);                                                                             
watermarker.close(); 

Are you looking to watermark documents and images of PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, VSD, MSG, EML, RTF, TXT, PNG, JPG, TIFF, and other file formats on the fly using your mobile devices? If yes, please try our Free Watermarking Apps and have a great document and image watermarking experience.

Looking for help?

Checkout our support channels for help with your questions related to Conholdate product API features and working.