public void addPages(String inputURL, String outputURL) throws IOException,
                        DocumentException {
                // 待加水印的文件
                PdfReader reader = new PdfReader(inputURL);
                // 加完水印的文件
                PdfStamper stamper = new PdfStamper(reader, new 
FileOutputStream(
                                outputURL));
                int total = reader.getNumberOfPages() + 1;
                PdfContentByte content;
                // 设置字体
                BaseFont base = BaseFont.createFont("STSong-Light", 
"UniGB-UCS2-H",
                                BaseFont.EMBEDDED);
                // 水印文字
                String waterText = "";
                // 循环对每页插入水印
                for (int i = 1; i < total; i++) {
                        waterText = String.valueOf(i);
                        content = stamper.getUnderContent(i);
                        // 开始
                        content.beginText();
                        // 设置颜色
                        // content.setColorFill(Color.GRAY);
                        // 设置字体及字号
                        content.setFontAndSize(base, 10);
                        // 设置起始位置
                        content.setTextMatrix(290, 20);
                        // 开始写入水印
                        content.showText(waterText);
                        content.endText();
                }
                stamper.close();
        }
-- 
View this message in context: 
http://old.nabble.com/Adding-Cover-Page-and-Header-Footer-to-Existing-PDF-tp20213336p27432722.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to