在itext 較新的版本中, 對中文的支援還是存在著問題,在網路上得到的資訊和多方嘗試下,將字型檔xx.TTF放到項目裡面,然後載入到BaseFont 中,可行。如下:BaseFont font = BaseFont.createFont(path + "MSYH.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
 
 
需要jar包: 
官網下載的 itext-5.3.0.zip 下的jar包 
itextpdf-5.3.0.jar 
itext-xtra-5.3.0.jar 
不需要對中文支援的擴充jar包,其由上文提到的 載入字型檔到BaseFont中來實現;
 
具體的加浮水印代碼如下: 
 
package com.sslinm.tools;import java.io.FileOutputStream;/** * 【功能描述:給PDF 加浮水印功能,(文字浮水印和圖片浮水印)】  *  【功能詳細描述:逐條詳細描述功能】 *  * @author 【lfssay】 * @see 【相關類/方法】 * @version 【類版本號碼, 2013-8-20 上午11:22:21】 * @since 【產品/模組版本】 */public class PdfAddWaterMark {    static Log log = LogFactory.getLog(PdfAddWaterMark.class);    public static void main(String[] args) throws DocumentException, IOException {        new PdfAddWaterMark().addWaterMark("E:/tt/1.pdf", "E:/tt/129.pdf", "國家圖書館藏", "E:/tt/1.jpg", 400, 800, 200, 800);    }    /**     *      * 【功能描述:添加圖片和文字浮水印】 【功能詳細描述:功能詳細描述】     *      * @see 【類、類#方法、類#成員】     * @param srcFile     *            待加浮水印檔案     * @param destFile     *            加浮水印後存放地址     * @param text     *            加浮水印的常值內容     * @param imgFile     *            加浮水印圖片檔案     * @param textWidth     *            文字橫座標     * @param textHeight     *            文字縱座標     * @param imgWidth     *            圖片橫座標     * @param imgHeight     *            圖片縱座標     * @throws IOException     * @throws DocumentException     */    public void addWaterMark(String srcFile, String destFile, String text, String imgFile, int textWidth,            int textHeight, int imgWidth, int imgHeight) throws IOException, DocumentException {        // 待加浮水印的檔案        PdfReader reader = new PdfReader(srcFile);        // 加完浮水印的檔案        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(destFile));        int total = reader.getNumberOfPages() + 1;        PdfContentByte content;        String path = this.getClass().getResource("/").getPath();        // 設定字型        // BaseFont base = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",        // BaseFont.EMBEDDED);        //載入字型檔來完成對字型的建立        BaseFont font = BaseFont.createFont(path + "MSYH.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);        // BaseFont base2 = BaseFont.createFont(BaseFont.HELVETICA,        // BaseFont.WINANSI, BaseFont.EMBEDDED);        // 浮水印文字        String waterText = text;        Image image = null;        if (!StringUtils.isBlank(imgFile)) {            image = Image.getInstance(imgFile);            image.setAbsolutePosition(imgWidth, imgHeight);            // 設定圖片的顯示大小             image.scaleToFit(100, 125);        }        int j = waterText.length(); // 文字長度        char c = 0;        int high = 0;// 高度        // 迴圈對每頁插入浮水印        for (int i = 1; i < total; i++) {            // 浮水印的起始            high = 50;            // 浮水印在之前文本之上            content = stamper.getOverContent(i);            if (image != null) {                content.addImage(image);            }            if (!StringUtils.isBlank(text)) {                // 開始                content.beginText();                // 設定顏色 預設為藍色                content.setColorFill(BaseColor.BLUE);                // content.setColorFill(Color.GRAY);                // 設定字型及字型大小                content.setFontAndSize(font, 38);                // 設定起始位置                // content.setTextMatrix(400, 880);                content.setTextMatrix(textWidth, textHeight);                // 開始寫入浮水印                content.showTextAligned(Element.ALIGN_LEFT, text, textWidth, textHeight, 45);                // for (int k = 0; k < j; k++) {                // content.setTextRise(14);                // c = waterText.charAt(k);                // // 將char轉成字串                // content.showText(c + "");                // high -= 5;                // }                content.endText();            }        }        stamper.close();        log.info("===" + srcFile + "===添加浮水印到==" + destFile + "==成功=====");    }}