Example usage for org.apache.pdfbox.pdmodel PDDocument load

List of usage examples for org.apache.pdfbox.pdmodel PDDocument load

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel PDDocument load.

Prototype

public static PDDocument load(byte[] input, String password, InputStream keyStore, String alias)
        throws IOException 

Source Link

Document

Parses a PDF.

Usage

From source file:com.ackpdfbox.app.Decrypt.java

License:Apache License

private void decrypt() throws IOException {
    PDDocument document = null;/*  w  w  w  .  j a v a 2 s  . co m*/
    try {
        InputStream keyStoreStream = null;
        if (keyStore != null) {
            keyStoreStream = new FileInputStream(keyStore);
        }

        document = PDDocument.load(new File(infile), password, keyStoreStream, alias);

        if (document.isEncrypted()) {
            AccessPermission ap = document.getCurrentAccessPermission();
            if (ap.isOwnerPermission()) {
                document.setAllSecurityToBeRemoved(true);
                document.save(outfile);
            } else {
                throw new IOException(
                        "Error: You are only allowed to decrypt a document with the owner password.");
            }
        } else {
            System.err.println("Error: Document is not encrypted.");
        }
    } finally {
        if (document != null) {
            document.close();
        }
    }
}