Senti,io ho preso il tuo codice pari pari, l'ho provato e non mi da il problema da te descritto.
Questo e' il codice
codice:
package itext;
import java.io.FileOutputStream;
import java.util.HashMap;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
/**
* Reads the pages of an existing PDF file, adds pagenumbers and a watermark.
*/
public class Main {
/**
* Reads the pages of an existing PDF file, adds pagenumbers and a watermark.
* @param args no arguments needed
*/
public static void main(String[] args) {
System.out.println("Add watermarks and pagenumbers");
try {
// we create a reader for a certain document
PdfReader reader = new PdfReader("C:/Documents and Settings/Simone/itext/build/classes/itext/ChapterSection.pdf");
// we create a stamper that will copy the document to a new file
PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("watermark_pagenumbers.pdf"));
// adding some metadata
Image img = Image.getInstance("C:/Documents and Settings/Simone/itext/build/classes/itext/watermark.gif");
img.setAbsolutePosition(150, 300);
byte gradient[] = new byte[256];
for (int k = 0; k < 256; ++k)
gradient[k] = (byte) 80;
Image smask = Image.getInstance(256, 1, 1, 8, gradient);
smask.makeMask();
img.setImageMask(smask);
PdfContentByte over = null;
over = stamp.getOverContent(1);
over.addImage(img);
stamp.close();
} catch (Exception de) {
de.printStackTrace();
}
}
}
e questa la gif

Sei sicuro che la tua gif abbia sfondo trasparente?