I would like to know if it's possible to watermark PDF file without any library.
I managed to do that with iText, but I would like to do watermarks in pure JAVA.
If someone knows if and how it's possible, please tell me.
I would like to know if it's possible to watermark PDF file without any library.
I managed to do that with iText, but I would like to do watermarks in pure JAVA.
If someone knows if and how it's possible, please tell me.
Watermarking to PDF can be added using the Java Library iText.
Here's an example of how to use it:
PdfReader reader = new PdfReader("HelloWorld.pdf");
PdfStamper pdfStamper = new PdfStamper(reader,
new FileOutputStream("NewHelloWorld.pdf"));
Image image = Image.getInstance("MyWatermark.png");
for (int i=1; i<= reader.getNumberOfPages(); i++){
PdfContentByte content = pdfStamper.getUnderContent(i);
image.setAbsolutePosition(150f, 750f);
content.addImage(image);
}
pdfStamper.close();
Here is another related example: https://web.archive.org/web/20151023054638/http://itextpdf.com/sandbox/events/Watermarking
In theory? Yes, it is. Most Java libraries that can produce watermarks are probably written in pure Java, so you could write that functionality yourself.
Practically? There aren't (to my knowledge; please correct me if I'm wrong) any core libraries that would allow you to manipulate PDFs in such a way, so you could either put a lot of work into basically copying part of iTexts functionality or just use a library.