How to make pdf read only in itext

2019-07-16 10:32发布

问题:

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.