欢迎访问个人博客:www.yyxxk.com
jar:itext-4.2.1.jar
在很多公文的落款处都需要绝对定位,所以记录此代码如下:
1 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("test.pdf")); 2 PdfContentByte cb = writer.getDirectContent(); 3 BaseFont bf= BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.EMBEDDED); 4 cb.beginText(); 5 cb.setFontAndSize(bf, 12); 6 cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text + "This text is centered", 250, 700, 0); 7 cb.endText();
有时候也需要图片(公章)绝对定位 :
1 Image image = Image.getInstance(request.getSession().getServletContext().getRealPath("/")+"common/images/starpilot/signet.png"); 2 image.scaleAbsolute(mmTopx(40), mmTopx(39)); 3 image.setAbsolutePosition(400, flagHeight); 4 document.add(image);