π δΈζζζ‘£
π· 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.
<dependency>
<groupId>org.easywatermark</groupId>
<artifactId>easy-watermark</artifactId>
<version>latest version</version>
</dependency>
public class WatermarkExample {
public static void main(String[] args) {
byte[] result = EasyWatermark.create()
.file(fileData)
.text("Easy-Watermark")
.execute();
}
}
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;
}
public class UsingPresetWatermarkType {
public static void main(String[] args) {
byte[] result = EasyWatermark.create()
.file(fileData)
.text("Easy-Watermark")
.easyWatermarkType(EasyWatermarkTypeEnum.CENTER)
.execute();
}
}
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();
}
}
If you have more suggestions, feel free to raise an issue! π