/easy-watermark

Easy Watermark is a simple and easy-to-use watermarking framework that adds watermarks to different types of files using the same method.

Primary LanguageJavaApache License 2.0Apache-2.0

πŸ’§ EasyWatermark

🌍 δΈ­ζ–‡ζ–‡ζ‘£
πŸ“· Image Watermark Example | πŸ“„ Pdf Watermark Example | πŸ“ Docx Watermark Example

EasyWatermark is a simple and easy-to-use watermarking framework. It abstracts methods for adding watermarks to various file types. With just a few lines of code, you can add the same style of watermark to different types of files.

πŸš€ Quick Start

1️⃣ Add Dependency

<dependency>
    <groupId>org.easywatermark</groupId>
    <artifactId>easy-watermark</artifactId>
    <version>latest version</version>
</dependency>

2️⃣ Add Watermark

public class WatermarkExample {

    public static void main(String[] args) {
        byte[] result = EasyWatermark.create()
                .file(fileData)
                .text("Easy-Watermark")
                .execute();
    }
    
}

πŸ”§ More Configurations

🎯 Preset Watermark Types

  • CUSTOM: Custom watermark (under development)
  • CENTER: Centered watermark
    • VERTICAL_CENTER: Vertically centered
    • LEFT_CENTER: Left centered
    • RIGHT_CENTER: Right centered
    • TOP_CENTER: Top centered
    • BOTTOM_CENTER: Bottom centered
  • OVERSPREAD: Full-page watermark with tilt angle options
    • LOW: Watermark covers 33%
    • NORMAL: Watermark covers 66%
    • HIGH: Watermark covers 90%
  • DIAGONAL: Diagonal watermark
    • TOP_TO_BOTTOM: From top to bottom
    • BOTTOM_TO_TOP: From bottom to top

βš™οΈ Watermark Configuration

Use the WatermarkConfig class to set properties like opacity, color, font, and more.

public class WatermarkConfig {
    private float alpha = 1.0f;  // Opacity
    private Color color = Color.BLACK;
    private File fontFile;
    private String fontName = "Dialog";  // Default font
    private int fontSize = 12;
    private int fontStyle = Font.PLAIN;
}

πŸ› οΈ Advanced Usage

Using Preset Watermark Types

public class UsingPresetWatermarkType {

    public static void main(String[] args) {
        byte[] result = EasyWatermark.create()
                .file(fileData)
                .text("Easy-Watermark")
                .easyWatermarkType(EasyWatermarkTypeEnum.CENTER)
                .execute();
    }
  
}

Custom Watermark and Font Configuration

public class CustomWatermarkExample {

    public static void main(String[] args) {
        WatermarkConfig watermarkConfig = new WatermarkConfig();
        watermarkConfig.setAlpha(0.5f);  // Set transparency

        FontConfig fontConfig = new FontConfig();
        fontConfig.setFontSize(30);  // Set font size

        byte[] result = EasyWatermark.create()
                .file(fileData)
                .config(watermarkConfig)
                .config(fontConfig)
                .easyWatermarkType(EasyWatermarkTypeEnum.CENTER)
                .text("Easy-Watermark")
                .execute();
    }
    
}

πŸ“… Development Plan

  • Add watermark to image files
  • Add watermark to PDF files
  • Add watermark to Word files
  • Improve custom watermark methods
  • Add watermark to Excel files
  • Add watermark to PowerPoint files
  • Hidden watermark

πŸ™Œ Others

If you have more suggestions, feel free to raise an issue! 😊