Import Java.io.File;
Import Java.io.FileOutputStream;
Import Com.itextpdf.text.Image;
Import Com.itextpdf.text.pdf.PdfArray;
Import Com.itextpdf.text.pdf.PdfContentByte;
Import Com.itextpdf.text.pdf.PdfDictionary;
Import Com.itextpdf.text.pdf.PdfName;
Import Com.itextpdf.text.pdf.PdfObject;
Import Com.itextpdf.text.pdf.PdfReader;
Import Com.itextpdf.text.pdf.PdfStamper;
public class testimage{
Public Testimage () {
}
public static void Addmark (String inpdffile,string outpdffile) {
Pdfreader reader = new Pdfreader (inpdffile, "PDF". GetBytes ());
Pdfstamper stamp = new Pdfstamper (reader, New FileOutputStream (Outpdffile));
Start Signature Insert Watermark
Image img = image.getinstance ("C:/users/tangwei/desktop/sunkai.png");//Watermark Picture Path
Img.setabsoluteposition (50, 50);//Set the location of the watermark picture
Watermark image size is inconsistent with the size of the PDF, you can directly set the image size to insert the watermark,
Do not scale the watermark image in advance, it is clearer after inserting
Imgluqi.scaleabsolute (200, 100);
Pdfcontentbyte under = stamp.getundercontent (1);//Get PDF Current Page
Under.addimage (IMG);
Stamp.close ();//signature complete, close stream output
File Tempfile = new file (inpdffile);
if (tempfile.exists ()) {
Tempfile.delete ();
}
}
Public static void Main (string[] args) {
Addmark ("D:/123.pdf", "d:/123_signatrue");
}
}
This article is from the "13160828" blog, please be sure to keep this source http://13170828.blog.51cto.com/13160828/1951771
Java to add a clear watermark image to the PDF, need a third package jar package: Itextpdf-5.1.3.jar