如何使pdf只在itext中读取

时间:2012-05-19 04:57:49

标签: java pdf-generation itext

我的代码如下

public static void main(String[] args) {
        try 
        {
            PdfReader reader = new PdfReader("D:\\SF_Users.pdf");
            int n = reader.getNumberOfPages();
            Rectangle psize = reader.getPageSize(1);
            Document document = new Document(psize);
            PdfWriter writer = PdfWriter.getInstance(document,
                    new FileOutputStream("D:\\new.pdf"));
            document.open();
            PdfContentByte pdf = writer.getDirectContent();
            document.newPage();
            PdfImportedPage page = writer.getImportedPage(reader, 1);
            pdf.addTemplate(page, .5f, 0, 0, .5f, 60, 120);
            document.close();
        } catch (Exception de) {
        }
    }

在这里,我可以在写作时阅读pdf,我想让它只读

谢谢

1 个答案:

答案 0 :(得分:4)

您是否尝试过使用PdfEncryptionSettings API?

  

文档的打开权限可以是AllowPrinting,AllowModifyContents,AllowCopy,AllowModifyAnnotations,AllowFillIn,AllowScreenReaders,AllowAssembly和AllowDegradedPrinting。