How to make pdf read only in itext

有些话、适合烂在心里 提交于 2019-12-12 17:16:45

问题


My code follows

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) {
        }
    }

Here i can able to read pdf while writting i want make it read only

Thank You


回答1:


Have you tried using the PdfEncryptionSettings API?

The open permissions for the document can be AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.



来源:https://stackoverflow.com/questions/10662424/how-to-make-pdf-read-only-in-itext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!