http://www.open-open.com/34.htm
在JAVA使用IText对PDF进行操作(网上例子很多)
http://www.ibm.com/developerworks/cn/opensource/os-javapdf/
当然这里要讲下中文问题,中文需要iTextAsian.jar
import com.lowagie.text.Font;
......
document.add(new Paragraph("这里是中文",FontChinese));
......
加密
Itext中我加密没成功过所以我选择PDFBox
public void PDFadmin(String filepath)
{
try
{
PDDocument pdf =
PDDocument.load(filepath);
//create the encryption options
PDStandardEncryption encryptionOptions =
new PDStandardEncryption();
encryptionOptions.setCanPrint( false );
pdf.setEncryptionDictionary(
encryptionOptions );
//encrypt the document
pdf.encrypt( "master", "admin" );
System.out.println("isEncrypted : " + pdf.isEncrypted());
//save the encrypted document
//to the file system
pdf.save(filepath);
}
catch (Exception e) {
// TODO: handle exception
}
}
其中admin是密码,网上有很多例子写的是是null 然后都是只加密没密码(晕这算加密),你可以随便改成你想要的密码。