itext给pdf文件添加居中水印
发布网友
发布时间:2022-04-27 13:14
我来回答
共2个回答
热心网友
时间:2023-09-22 14:18
public class StampStationery {
public static final String filename = "F://demo.pdf";
public static void main(String[] args) throws IOException,
DocumentException{
Document document = new Document(new Rectangle(400, 400));
PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream(filename));
document.open();
PdfContentByte cb = writer.getDirectContent();
String content = "hello word!";
cb.beginText();
Font f = new Font();
f.setSize(18);
Phrase p = new Phrase(content, f);
//(100,200) 是x,y坐标 45 是偏移角度 字体的演示自己设置
ColumnText.showTextAligned(cb, 0, p, 100, 200, 45);
cb.endText();
document.close();
}
}
热心网友
时间:2023-09-22 14:18
建议去看iText in Action