Example usage for com.lowagie.text.pdf PdfReader isOpenedWithFullPermissions

List of usage examples for com.lowagie.text.pdf PdfReader isOpenedWithFullPermissions

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfReader isOpenedWithFullPermissions.

Prototype

public final boolean isOpenedWithFullPermissions() 

Source Link

Document

Checks if the document was opened with the owner password so that the end application can decide what level of access restrictions to apply.

Usage

From source file:org.pdfsam.console.utils.PdfUtility.java

License:Open Source License

private static void unethical(PdfReader reader) throws NoSuchFieldException, IllegalAccessException {
    if (!reader.isOpenedWithFullPermissions()) {
        Field field = reader.getClass().getDeclaredField("encrypted");
        field.setAccessible(true);/*from w  w w .j  a v  a  2 s.  c  o m*/
        field.setBoolean(reader, false);
    }
}

From source file:org.pdfsam.guiclient.commons.business.loaders.callable.AddPdfDocument.java

License:Open Source License

/**
* 
* @param fileToAdd file to add/*  w  ww. j  a v a2  s. c  o m*/
* @param password password to open the file
* @return the item to add to the table
*/
PdfSelectionTableItem getPdfSelectionTableItem(File fileToAdd, String password, String pageSelection) {
    PdfSelectionTableItem tableItem = null;
    PdfReader pdfReader = null;
    if (fileToAdd != null) {
        tableItem = new PdfSelectionTableItem();
        tableItem.setInputFile(fileToAdd);
        tableItem.setPassword(password);
        tableItem.setPageSelection(pageSelection);
        try {
            //fix 04/11/08 for memory usage
            pdfReader = new PdfReader(new RandomAccessFileOrArray(fileToAdd.getAbsolutePath()),
                    (password != null) ? password.getBytes() : null);
            tableItem.setEncrypted(pdfReader.isEncrypted());
            tableItem.setFullPermission(pdfReader.isOpenedWithFullPermissions());
            if (tableItem.isEncrypted()) {
                tableItem.setPermissions(getPermissionsVerbose(pdfReader.getPermissions()));
                int cMode = pdfReader.getCryptoMode();
                switch (cMode) {
                case PdfWriter.STANDARD_ENCRYPTION_40:
                    tableItem.setEncryptionAlgorithm(EncryptionUtility.RC4_40);
                    break;
                case PdfWriter.STANDARD_ENCRYPTION_128:
                    tableItem.setEncryptionAlgorithm(EncryptionUtility.RC4_128);
                    break;
                case PdfWriter.ENCRYPTION_AES_128:
                    tableItem.setEncryptionAlgorithm(EncryptionUtility.AES_128);
                    break;
                default:
                    break;
                }
            }
            tableItem.setPagesNumber(Integer.toString(pdfReader.getNumberOfPages()));
            tableItem.setFileSize(fileToAdd.length());
            tableItem.setPdfVersion(pdfReader.getPdfVersion());
            tableItem.setSyntaxErrors(pdfReader.isRebuilt());
            initTableItemDocumentData(pdfReader, tableItem);
        } catch (Exception e) {
            tableItem.setLoadedWithErrors(true);
            LOG.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                    "Error loading ") + fileToAdd.getAbsolutePath() + " :", e);
        } finally {
            if (pdfReader != null) {
                pdfReader.close();
                pdfReader = null;
            }
        }
    }
    return tableItem;
}

From source file:org.sejda.impl.itext.component.input.AbstractPdfSourceOpener.java

License:Apache License

private PdfReader makeUnethicalIfRequired(PdfReader reader) {
    if (Boolean.getBoolean(Sejda.UNETHICAL_READ_PROPERTY_NAME) && !reader.isOpenedWithFullPermissions()) {
        Field field;//from w w  w  . j a v a  2  s .  c  o  m
        try {
            field = PdfReader.class.getDeclaredField("encrypted");
            field.setAccessible(true);
            field.setBoolean(reader, false);
        } catch (NoSuchFieldException e) {
            // this should not happen
            throw new SejdaRuntimeException("Error making PdfReader unethical", e);
        } catch (IllegalAccessException e) {
            LOG.warn("Unable to make the reader unethical", e);
        }
    }
    return reader;
}