package example.iText;
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfEncryptor;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;
public class PdfHandle {
public static void hideBars(String inputFile, String outFile) {
// 复制一个PDF
try {
// 创建一个reader
PdfReader reader = new PdfReader(inputFile);
reader.setViewerPreferences(PdfWriter.HideMenubar
| PdfWriter.HideToolbar);
reader.setViewerPreferences(PdfWriter.HideWindowUI);
//设置权限
PdfEncryptor.encrypt(reader, new FileOutputStream(outFile), new String("hellogtm").getBytes(),
new String("hellogtm123").getBytes(), PdfWriter.ALLOW_ASSEMBLY | PdfWriter.ALLOW_FILL_IN
| PdfWriter.ALLOW_SCREENREADERS, false);
} catch (Exception de) {
de.printStackTrace();
}
}
public static void test() {
PdfHandle pp = new PdfHandle();
pp.hideBars("d:\\\\1.pdf", "d:\\2.pdf");
//pp.notAllowPrint("d:\\2.pdf", "d:\\3.pdf");
System.out.println("pdf文件转换完毕!");
}
}
所需库见附件
`itext 隐藏pdf工具栏 菜单栏
最新推荐文章于 2022-08-10 09:54:13 发布