Example usage for com.lowagie.text.pdf PdfWriter ALLOW_FILL_IN

List of usage examples for com.lowagie.text.pdf PdfWriter ALLOW_FILL_IN

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfWriter ALLOW_FILL_IN.

Prototype

int ALLOW_FILL_IN

To view the source code for com.lowagie.text.pdf PdfWriter ALLOW_FILL_IN.

Click Source Link

Document

The operation permitted when the document is opened with the user password

Usage

From source file:net.sf.dynamicreports.jasper.transformation.ConstantTransform.java

License:Open Source License

protected static Integer pdfPermission(List<PdfPermission> permissions) {
    int permission = 0;
    for (PdfPermission pdfPermission : permissions) {
        switch (pdfPermission) {
        case PRINTING:
            return permission | PdfWriter.ALLOW_PRINTING;
        case MODIFY_CONTENTS:
            return permission | PdfWriter.ALLOW_MODIFY_CONTENTS;
        case COPY:
            return permission | PdfWriter.ALLOW_COPY;
        case MODIFY_ANNOTATIONS:
            return permission | PdfWriter.ALLOW_MODIFY_ANNOTATIONS;
        case FILL_IN:
            return permission | PdfWriter.ALLOW_FILL_IN;
        case SCREEN_READERS:
            return permission | PdfWriter.ALLOW_SCREENREADERS;
        case ASSEMBLY:
            return permission | PdfWriter.ALLOW_ASSEMBLY;
        case DEGRADED_PRINTING:
            return permission | PdfWriter.ALLOW_DEGRADED_PRINTING;
        default:/*from  w w w.j  a va 2 s.c o  m*/
            throw new JasperDesignException("PdfPermission " + pdfPermission.name() + " not supported");
        }
    }
    return permission;
}

From source file:net.sf.jsignpdf.SignerLogic.java

License:Mozilla Public License

/**
 * Signs a single file./*from   w w  w  .  j a v  a  2s .  c  o  m*/
 * 
 * @return true when signing is finished succesfully, false otherwise
 */
public boolean signFile() {
    final String outFile = options.getOutFileX();
    if (!validateInOutFiles(options.getInFile(), outFile)) {
        LOGGER.info(RES.get("console.skippingSigning"));
        return false;
    }

    boolean finished = false;
    Throwable tmpException = null;
    FileOutputStream fout = null;
    try {
        SSLInitializer.init(options);

        final PrivateKeyInfo pkInfo = KeyStoreUtils.getPkInfo(options);
        final PrivateKey key = pkInfo.getKey();
        final Certificate[] chain = pkInfo.getChain();
        if (ArrayUtils.isEmpty(chain)) {
            // the certificate was not found
            LOGGER.info(RES.get("console.certificateChainEmpty"));
            return false;
        }
        LOGGER.info(RES.get("console.createPdfReader", options.getInFile()));
        PdfReader reader;
        try {
            reader = new PdfReader(options.getInFile(), options.getPdfOwnerPwdStrX().getBytes());
        } catch (Exception e) {
            try {
                reader = new PdfReader(options.getInFile(), new byte[0]);
            } catch (Exception e2) {
                // try to read without password
                reader = new PdfReader(options.getInFile());
            }
        }

        LOGGER.info(RES.get("console.createOutPdf", outFile));
        fout = new FileOutputStream(outFile);

        final HashAlgorithm hashAlgorithm = options.getHashAlgorithmX();

        LOGGER.info(RES.get("console.createSignature"));
        char tmpPdfVersion = '\0'; // default version - the same as input
        if (reader.getPdfVersion() < hashAlgorithm.getPdfVersion()) {
            // this covers also problems with visible signatures (embedded
            // fonts) in PDF 1.2, because the minimal version
            // for hash algorithms is 1.3 (for SHA1)
            if (options.isAppendX()) {
                // if we are in append mode and version should be updated
                // then return false (not possible)
                LOGGER.info(RES.get("console.updateVersionNotPossibleInAppendMode"));
                return false;
            }
            tmpPdfVersion = hashAlgorithm.getPdfVersion();
            LOGGER.info(RES.get("console.updateVersion",
                    new String[] { String.valueOf(reader.getPdfVersion()), String.valueOf(tmpPdfVersion) }));
        }

        final PdfStamper stp = PdfStamper.createSignature(reader, fout, tmpPdfVersion, null,
                options.isAppendX());
        if (!options.isAppendX()) {
            // we are not in append mode, let's remove existing signatures
            // (otherwise we're getting to troubles)
            final AcroFields acroFields = stp.getAcroFields();
            @SuppressWarnings("unchecked")
            final List<String> sigNames = acroFields.getSignatureNames();
            for (String sigName : sigNames) {
                acroFields.removeField(sigName);
            }
        }
        if (options.isAdvanced() && options.getPdfEncryption() != PDFEncryption.NONE) {
            LOGGER.info(RES.get("console.setEncryption"));
            final int tmpRight = options.getRightPrinting().getRight()
                    | (options.isRightCopy() ? PdfWriter.ALLOW_COPY : 0)
                    | (options.isRightAssembly() ? PdfWriter.ALLOW_ASSEMBLY : 0)
                    | (options.isRightFillIn() ? PdfWriter.ALLOW_FILL_IN : 0)
                    | (options.isRightScreanReaders() ? PdfWriter.ALLOW_SCREENREADERS : 0)
                    | (options.isRightModifyAnnotations() ? PdfWriter.ALLOW_MODIFY_ANNOTATIONS : 0)
                    | (options.isRightModifyContents() ? PdfWriter.ALLOW_MODIFY_CONTENTS : 0);
            switch (options.getPdfEncryption()) {
            case PASSWORD:
                stp.setEncryption(true, options.getPdfUserPwdStr(), options.getPdfOwnerPwdStrX(), tmpRight);
                break;
            case CERTIFICATE:
                final X509Certificate encCert = KeyStoreUtils
                        .loadCertificate(options.getPdfEncryptionCertFile());
                if (encCert == null) {
                    LOGGER.error(RES.get("console.pdfEncError.wrongCertificateFile",
                            StringUtils.defaultString(options.getPdfEncryptionCertFile())));
                    return false;
                }
                if (!KeyStoreUtils.isEncryptionSupported(encCert)) {
                    LOGGER.error(RES.get("console.pdfEncError.cantUseCertificate",
                            encCert.getSubjectDN().getName()));
                    return false;
                }
                stp.setEncryption(new Certificate[] { encCert }, new int[] { tmpRight },
                        PdfWriter.ENCRYPTION_AES_128);
                break;
            default:
                LOGGER.error(RES.get("console.unsupportedEncryptionType"));
                return false;
            }
        }

        final PdfSignatureAppearance sap = stp.getSignatureAppearance();
        sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
        final String reason = options.getReason();
        if (StringUtils.isNotEmpty(reason)) {
            LOGGER.info(RES.get("console.setReason", reason));
            sap.setReason(reason);
        }
        final String location = options.getLocation();
        if (StringUtils.isNotEmpty(location)) {
            LOGGER.info(RES.get("console.setLocation", location));
            sap.setLocation(location);
        }
        final String contact = options.getContact();
        if (StringUtils.isNotEmpty(contact)) {
            LOGGER.info(RES.get("console.setContact", contact));
            sap.setContact(contact);
        }
        LOGGER.info(RES.get("console.setCertificationLevel"));
        sap.setCertificationLevel(options.getCertLevelX().getLevel());

        if (options.isVisible()) {
            // visible signature is enabled
            LOGGER.info(RES.get("console.configureVisible"));
            LOGGER.info(RES.get("console.setAcro6Layers", Boolean.toString(options.isAcro6Layers())));
            sap.setAcro6Layers(options.isAcro6Layers());

            final String tmpImgPath = options.getImgPath();
            if (tmpImgPath != null) {
                LOGGER.info(RES.get("console.createImage", tmpImgPath));
                final Image img = Image.getInstance(tmpImgPath);
                LOGGER.info(RES.get("console.setSignatureGraphic"));
                sap.setSignatureGraphic(img);
            }
            final String tmpBgImgPath = options.getBgImgPath();
            if (tmpBgImgPath != null) {
                LOGGER.info(RES.get("console.createImage", tmpBgImgPath));
                final Image img = Image.getInstance(tmpBgImgPath);
                LOGGER.info(RES.get("console.setImage"));
                sap.setImage(img);
            }
            LOGGER.info(RES.get("console.setImageScale"));
            sap.setImageScale(options.getBgImgScale());
            LOGGER.info(RES.get("console.setL2Text"));
            final String signer = PdfPKCS7.getSubjectFields((X509Certificate) chain[0]).getField("CN");
            final String timestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z")
                    .format(sap.getSignDate().getTime());
            if (options.getL2Text() != null) {
                final Map<String, String> replacements = new HashMap<String, String>();
                replacements.put(L2TEXT_PLACEHOLDER_SIGNER, StringUtils.defaultString(signer));
                replacements.put(L2TEXT_PLACEHOLDER_TIMESTAMP, timestamp);
                replacements.put(L2TEXT_PLACEHOLDER_LOCATION, StringUtils.defaultString(location));
                replacements.put(L2TEXT_PLACEHOLDER_REASON, StringUtils.defaultString(reason));
                replacements.put(L2TEXT_PLACEHOLDER_CONTACT, StringUtils.defaultString(contact));
                final String l2text = StrSubstitutor.replace(options.getL2Text(), replacements);
                sap.setLayer2Text(l2text);
            } else {
                final StringBuilder buf = new StringBuilder();
                buf.append(RES.get("default.l2text.signedBy")).append(" ").append(signer).append('\n');
                buf.append(RES.get("default.l2text.date")).append(" ").append(timestamp);
                if (StringUtils.isNotEmpty(reason))
                    buf.append('\n').append(RES.get("default.l2text.reason")).append(" ").append(reason);
                if (StringUtils.isNotEmpty(location))
                    buf.append('\n').append(RES.get("default.l2text.location")).append(" ").append(location);
                sap.setLayer2Text(buf.toString());
            }
            if (FontUtils.getL2BaseFont() != null) {
                sap.setLayer2Font(new Font(FontUtils.getL2BaseFont(), options.getL2TextFontSize()));
            }
            LOGGER.info(RES.get("console.setL4Text"));
            sap.setLayer4Text(options.getL4Text());
            LOGGER.info(RES.get("console.setRender"));
            RenderMode renderMode = options.getRenderMode();
            if (renderMode == RenderMode.GRAPHIC_AND_DESCRIPTION && sap.getSignatureGraphic() == null) {
                LOGGER.warn(
                        "Render mode of visible signature is set to GRAPHIC_AND_DESCRIPTION, but no image is loaded. Fallback to DESCRIPTION_ONLY.");
                LOGGER.info(RES.get("console.renderModeFallback"));
                renderMode = RenderMode.DESCRIPTION_ONLY;
            }
            sap.setRender(renderMode.getRender());
            LOGGER.info(RES.get("console.setVisibleSignature"));
            int page = options.getPage();
            if (page < 1 || page > reader.getNumberOfPages()) {
                page = reader.getNumberOfPages();
            }
            sap.setVisibleSignature(new Rectangle(options.getPositionLLX(), options.getPositionLLY(),
                    options.getPositionURX(), options.getPositionURY()), page, null);
        }

        LOGGER.info(RES.get("console.processing"));
        final PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName("adbe.pkcs7.detached"));
        if (!StringUtils.isEmpty(reason)) {
            dic.setReason(sap.getReason());
        }
        if (!StringUtils.isEmpty(location)) {
            dic.setLocation(sap.getLocation());
        }
        if (!StringUtils.isEmpty(contact)) {
            dic.setContact(sap.getContact());
        }
        dic.setDate(new PdfDate(sap.getSignDate()));
        sap.setCryptoDictionary(dic);

        final Proxy tmpProxy = options.createProxy();

        final CRLInfo crlInfo = new CRLInfo(options, chain);

        // CRLs are stored twice in PDF c.f.
        // PdfPKCS7.getAuthenticatedAttributeBytes
        final int contentEstimated = (int) (Constants.DEFVAL_SIG_SIZE + 2L * crlInfo.getByteCount());
        final Map<PdfName, Integer> exc = new HashMap<PdfName, Integer>();
        exc.put(PdfName.CONTENTS, new Integer(contentEstimated * 2 + 2));
        sap.preClose(exc);

        PdfPKCS7 sgn = new PdfPKCS7(key, chain, crlInfo.getCrls(), hashAlgorithm.getAlgorithmName(), null,
                false);
        InputStream data = sap.getRangeStream();
        final MessageDigest messageDigest = MessageDigest.getInstance(hashAlgorithm.getAlgorithmName());
        byte buf[] = new byte[8192];
        int n;
        while ((n = data.read(buf)) > 0) {
            messageDigest.update(buf, 0, n);
        }
        byte hash[] = messageDigest.digest();
        Calendar cal = Calendar.getInstance();
        byte[] ocsp = null;
        if (options.isOcspEnabledX() && chain.length >= 2) {
            LOGGER.info(RES.get("console.getOCSPURL"));
            String url = PdfPKCS7.getOCSPURL((X509Certificate) chain[0]);
            if (StringUtils.isEmpty(url)) {
                // get from options
                LOGGER.info(RES.get("console.noOCSPURL"));
                url = options.getOcspServerUrl();
            }
            if (!StringUtils.isEmpty(url)) {
                LOGGER.info(RES.get("console.readingOCSP", url));
                final OcspClientBouncyCastle ocspClient = new OcspClientBouncyCastle((X509Certificate) chain[0],
                        (X509Certificate) chain[1], url);
                ocspClient.setProxy(tmpProxy);
                ocsp = ocspClient.getEncoded();
            }
        }
        byte sh[] = sgn.getAuthenticatedAttributeBytes(hash, cal, ocsp);
        sgn.update(sh, 0, sh.length);

        TSAClientBouncyCastle tsc = null;
        if (options.isTimestampX() && !StringUtils.isEmpty(options.getTsaUrl())) {
            LOGGER.info(RES.get("console.creatingTsaClient"));
            if (options.getTsaServerAuthn() == ServerAuthentication.PASSWORD) {
                tsc = new TSAClientBouncyCastle(options.getTsaUrl(),
                        StringUtils.defaultString(options.getTsaUser()),
                        StringUtils.defaultString(options.getTsaPasswd()));
            } else {
                tsc = new TSAClientBouncyCastle(options.getTsaUrl());

            }
            final String tsaHashAlg = options.getTsaHashAlgWithFallback();
            LOGGER.info(RES.get("console.settingTsaHashAlg", tsaHashAlg));
            tsc.setHashAlgorithm(tsaHashAlg);
            tsc.setProxy(tmpProxy);
            final String policyOid = options.getTsaPolicy();
            if (StringUtils.isNotEmpty(policyOid)) {
                LOGGER.info(RES.get("console.settingTsaPolicy", policyOid));
                tsc.setPolicy(policyOid);
            }
        }
        byte[] encodedSig = sgn.getEncodedPKCS7(hash, cal, tsc, ocsp);

        if (contentEstimated + 2 < encodedSig.length) {
            System.err.println(
                    "SigSize - contentEstimated=" + contentEstimated + ", sigLen=" + encodedSig.length);
            throw new Exception("Not enough space");
        }

        byte[] paddedSig = new byte[contentEstimated];
        System.arraycopy(encodedSig, 0, paddedSig, 0, encodedSig.length);

        PdfDictionary dic2 = new PdfDictionary();
        dic2.put(PdfName.CONTENTS, new PdfString(paddedSig).setHexWriting(true));
        LOGGER.info(RES.get("console.closeStream"));
        sap.close(dic2);
        fout.close();
        fout = null;
        finished = true;
    } catch (Exception e) {
        LOGGER.error(RES.get("console.exception"), e);
    } catch (OutOfMemoryError e) {
        LOGGER.fatal(RES.get("console.memoryError"), e);
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        LOGGER.info(RES.get("console.finished." + (finished ? "ok" : "error")));
        options.fireSignerFinishedEvent(tmpException);
    }
    return finished;
}

From source file:org.allcolor.yahp.cl.converter.CDocumentReconstructor.java

License:Open Source License

/**
 * return the itext security flags for encryption
 * //from  w  ww  .  j a v a 2  s.  c  om
 * @param properties
 *            the converter properties
 * 
 * @return the itext security flags
 */
private static final int getSecurityFlags(final Map properties) {
    int securityType = 0;
    securityType = "true".equals(properties.get(IHtmlToPdfTransformer.PDF_ALLOW_PRINTING))
            ? (securityType | PdfWriter.ALLOW_PRINTING)
            : securityType;
    securityType = "true".equals(properties.get(IHtmlToPdfTransformer.PDF_ALLOW_MODIFY_CONTENTS))
            ? (securityType | PdfWriter.ALLOW_MODIFY_CONTENTS)
            : securityType;
    securityType = "true".equals(properties.get(IHtmlToPdfTransformer.PDF_ALLOW_COPY))
            ? (securityType | PdfWriter.ALLOW_COPY)
            : securityType;
    securityType = "true".equals(properties.get(IHtmlToPdfTransformer.PDF_ALLOW_MODIFT_ANNOTATIONS))
            ? (securityType | PdfWriter.ALLOW_MODIFY_ANNOTATIONS)
            : securityType;
    securityType = "true".equals(properties.get(IHtmlToPdfTransformer.PDF_ALLOW_FILLIN))
            ? (securityType | PdfWriter.ALLOW_FILL_IN)
            : securityType;
    securityType = "true".equals(properties.get(IHtmlToPdfTransformer.PDF_ALLOW_SCREEN_READERS))
            ? (securityType | PdfWriter.ALLOW_SCREENREADERS)
            : securityType;
    securityType = "true".equals(properties.get(IHtmlToPdfTransformer.PDF_ALLOW_ASSEMBLY))
            ? (securityType | PdfWriter.ALLOW_ASSEMBLY)
            : securityType;
    securityType = "true".equals(properties.get(IHtmlToPdfTransformer.PDF_ALLOW_DEGRADED_PRINTING))
            ? (securityType | PdfWriter.ALLOW_DEGRADED_PRINTING)
            : securityType;

    return securityType;
}

From source file:org.lucee.extension.pdf.PDFStruct.java

License:Open Source License

public Struct getInfo() {

    PdfReader pr = null;//w w w. j a  v  a2s  . c  o m
    try {
        pr = getPdfReader();
        // PdfDictionary catalog = pr.getCatalog();
        int permissions = pr.getPermissions();
        boolean encrypted = pr.isEncrypted();

        Struct info = CFMLEngineFactory.getInstance().getCreationUtil().createStruct();
        info.setEL("FilePath", getFilePath());

        // access
        info.setEL("ChangingDocument", allowed(encrypted, permissions, PdfWriter.ALLOW_MODIFY_CONTENTS));
        info.setEL("Commenting", allowed(encrypted, permissions, PdfWriter.ALLOW_MODIFY_ANNOTATIONS));
        info.setEL("ContentExtraction", allowed(encrypted, permissions, PdfWriter.ALLOW_SCREENREADERS));
        info.setEL("CopyContent", allowed(encrypted, permissions, PdfWriter.ALLOW_COPY));
        info.setEL("DocumentAssembly",
                allowed(encrypted, permissions, PdfWriter.ALLOW_ASSEMBLY + PdfWriter.ALLOW_MODIFY_CONTENTS));
        info.setEL("FillingForm",
                allowed(encrypted, permissions, PdfWriter.ALLOW_FILL_IN + PdfWriter.ALLOW_MODIFY_ANNOTATIONS));
        info.setEL("Printing", allowed(encrypted, permissions, PdfWriter.ALLOW_PRINTING));
        info.setEL("Secure", "");
        info.setEL("Signing", allowed(encrypted, permissions, PdfWriter.ALLOW_MODIFY_ANNOTATIONS
                + PdfWriter.ALLOW_MODIFY_CONTENTS + PdfWriter.ALLOW_FILL_IN));

        info.setEL("Encryption", encrypted ? "Password Security" : "No Security");// MUST
        info.setEL("TotalPages", CFMLEngineFactory.getInstance().getCastUtil().toDouble(pr.getNumberOfPages()));
        info.setEL("Version", "1." + pr.getPdfVersion());
        info.setEL("permissions", "" + permissions);
        info.setEL("permiss", "" + PdfWriter.ALLOW_FILL_IN);

        info.setEL("Application", "");
        info.setEL("Author", "");
        info.setEL("CenterWindowOnScreen", "");
        info.setEL("Created", "");
        info.setEL("FitToWindow", "");
        info.setEL("HideMenubar", "");
        info.setEL("HideToolbar", "");
        info.setEL("HideWindowUI", "");
        info.setEL("Keywords", "");
        info.setEL("Language", "");
        info.setEL("Modified", "");
        info.setEL("PageLayout", "");
        info.setEL("Producer", "");
        info.setEL("Properties", "");
        info.setEL("ShowDocumentsOption", "");
        info.setEL("ShowWindowsOption", "");
        info.setEL("Subject", "");
        info.setEL("Title", "");
        info.setEL("Trapped", "");

        // info
        HashMap imap = pr.getInfo();
        Iterator it = imap.entrySet().iterator();
        Map.Entry entry;
        while (it.hasNext()) {
            entry = (Entry) it.next();
            info.setEL(CFMLEngineFactory.getInstance().getCastUtil().toString(entry.getKey(), null),
                    entry.getValue());
        }
        return info;
    } catch (PageException pe) {
        throw CFMLEngineFactory.getInstance().getExceptionUtil().createPageRuntimeException(pe);
    } finally {
        if (pr != null)
            pr.close();
    }
}

From source file:org.lucee.extension.pdf.util.PDFUtil.java

License:Open Source License

/**
 * convert a string defintion of a permision in a integer Constant (PdfWriter.ALLOW_XXX)
 * //from   w  w  w . j a  v a  2  s .c o m
 * @param strPermission
 * @return
 * @throws ApplicationException
 */
public static int toPermission(String strPermission) throws PageException {
    strPermission = strPermission.trim().toLowerCase();
    if ("allowassembly".equals(strPermission))
        return PdfWriter.ALLOW_ASSEMBLY;
    else if ("none".equals(strPermission))
        return 0;
    else if ("all".equals(strPermission))
        return PERMISSION_ALL;
    else if ("assembly".equals(strPermission))
        return PdfWriter.ALLOW_ASSEMBLY;
    else if ("documentassembly".equals(strPermission))
        return PdfWriter.ALLOW_ASSEMBLY;
    else if ("allowdegradedprinting".equals(strPermission))
        return PdfWriter.ALLOW_DEGRADED_PRINTING;
    else if ("degradedprinting".equals(strPermission))
        return PdfWriter.ALLOW_DEGRADED_PRINTING;
    else if ("printing".equals(strPermission))
        return PdfWriter.ALLOW_DEGRADED_PRINTING;
    else if ("allowfillin".equals(strPermission))
        return PdfWriter.ALLOW_FILL_IN;
    else if ("fillin".equals(strPermission))
        return PdfWriter.ALLOW_FILL_IN;
    else if ("fillingform".equals(strPermission))
        return PdfWriter.ALLOW_FILL_IN;
    else if ("allowmodifyannotations".equals(strPermission))
        return PdfWriter.ALLOW_MODIFY_ANNOTATIONS;
    else if ("modifyannotations".equals(strPermission))
        return PdfWriter.ALLOW_MODIFY_ANNOTATIONS;
    else if ("allowmodifycontents".equals(strPermission))
        return PdfWriter.ALLOW_MODIFY_CONTENTS;
    else if ("modifycontents".equals(strPermission))
        return PdfWriter.ALLOW_MODIFY_CONTENTS;
    else if ("allowcopy".equals(strPermission))
        return PdfWriter.ALLOW_COPY;
    else if ("copy".equals(strPermission))
        return PdfWriter.ALLOW_COPY;
    else if ("copycontent".equals(strPermission))
        return PdfWriter.ALLOW_COPY;
    else if ("allowprinting".equals(strPermission))
        return PdfWriter.ALLOW_PRINTING;
    else if ("printing".equals(strPermission))
        return PdfWriter.ALLOW_PRINTING;
    else if ("allowscreenreaders".equals(strPermission))
        return PdfWriter.ALLOW_SCREENREADERS;
    else if ("screenreaders".equals(strPermission))
        return PdfWriter.ALLOW_SCREENREADERS;

    else
        throw CFMLEngineFactory.getInstance().getExceptionUtil()
                .createApplicationException("invalid permission [" + strPermission
                        + "], valid permission values are [AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly, AllowDegradedPrinting]");
}

From source file:org.pdfsam.console.business.parser.validators.EncryptCmdValidator.java

License:Open Source License

/**
 * @param encryptionType encryption algorithm
 * @return The permissions map based on the chosen encryption
 *///from   w ww .j ava 2  s  . co  m
private Hashtable getPermissionsMap(String encryptionType) {
    Hashtable retMap = new Hashtable(12);
    if (EncryptParsedCommand.E_RC4_40.equals(encryptionType)) {
        retMap.put(EncryptParsedCommand.E_PRINT, new Integer(PdfWriter.ALLOW_PRINTING));
        retMap.put(EncryptParsedCommand.E_MODIFY, new Integer(PdfWriter.ALLOW_MODIFY_CONTENTS));
        retMap.put(EncryptParsedCommand.E_COPY, new Integer(PdfWriter.ALLOW_COPY));
        retMap.put(EncryptParsedCommand.E_ANNOTATION, new Integer(PdfWriter.ALLOW_MODIFY_ANNOTATIONS));
    } else {
        retMap.put(EncryptParsedCommand.E_PRINT, new Integer(PdfWriter.ALLOW_PRINTING));
        retMap.put(EncryptParsedCommand.E_MODIFY, new Integer(PdfWriter.ALLOW_MODIFY_CONTENTS));
        retMap.put(EncryptParsedCommand.E_COPY, new Integer(PdfWriter.ALLOW_COPY));
        retMap.put(EncryptParsedCommand.E_ANNOTATION, new Integer(PdfWriter.ALLOW_MODIFY_ANNOTATIONS));
        retMap.put(EncryptParsedCommand.E_FILL, new Integer(PdfWriter.ALLOW_FILL_IN));
        retMap.put(EncryptParsedCommand.E_SCREEN, new Integer(PdfWriter.ALLOW_SCREENREADERS));
        retMap.put(EncryptParsedCommand.E_ASSEMBLY, new Integer(PdfWriter.ALLOW_ASSEMBLY));
        retMap.put(EncryptParsedCommand.E_DPRINT, new Integer(PdfWriter.ALLOW_DEGRADED_PRINTING));
    }

    return retMap;
}

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

License:Open Source License

/**
 * It gives a human readable version of the document permissions
 * @param permissions/*  w ww  .  ja v a 2  s.  c o m*/
 * @return
 */
private String getPermissionsVerbose(int permissions) {
    StringBuffer buf = new StringBuffer();
    if ((PdfWriter.ALLOW_PRINTING & permissions) == PdfWriter.ALLOW_PRINTING)
        buf.append(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Print"));
    if ((PdfWriter.ALLOW_MODIFY_CONTENTS & permissions) == PdfWriter.ALLOW_MODIFY_CONTENTS)
        buf.append(
                ", " + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "Modify"));
    if ((PdfWriter.ALLOW_COPY & permissions) == PdfWriter.ALLOW_COPY)
        buf.append(", " + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "Copy or extract"));
    if ((PdfWriter.ALLOW_MODIFY_ANNOTATIONS & permissions) == PdfWriter.ALLOW_MODIFY_ANNOTATIONS)
        buf.append(", " + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "Add or modify text annotations"));
    if ((PdfWriter.ALLOW_FILL_IN & permissions) == PdfWriter.ALLOW_FILL_IN)
        buf.append(", " + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "Fill form fields"));
    if ((PdfWriter.ALLOW_SCREENREADERS & permissions) == PdfWriter.ALLOW_SCREENREADERS)
        buf.append(", " + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "Extract for use by accessibility dev."));
    if ((PdfWriter.ALLOW_ASSEMBLY & permissions) == PdfWriter.ALLOW_ASSEMBLY)
        buf.append(", " + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "Manipulate pages and add bookmarks"));
    if ((PdfWriter.ALLOW_DEGRADED_PRINTING & permissions) == PdfWriter.ALLOW_DEGRADED_PRINTING)
        buf.append(", " + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                "Low quality print"));
    return buf.toString();
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfDocumentWriter.java

License:Open Source License

/**
 * Extracts the permissions for this PDF. The permissions are returned as flags in the integer value. All permissions
 * are defined as properties which have to be set before the target is opened.
 *
 * @return the permissions./* w w w .j a va  2 s .  c  om*/
 */
private int getPermissions() {
    final String printLevel = config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PrintLevel");

    final boolean allowPrinting = "none".equals(printLevel) == false;
    final boolean allowDegradedPrinting = "degraded".equals(printLevel);

    final boolean allowModifyContents = "true".equals(config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.AllowModifyContents"));
    final boolean allowModifyAnn = "true".equals(config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.AllowModifyAnnotations"));

    final boolean allowCopy = "true".equals(config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.AllowCopy"));
    final boolean allowFillIn = "true".equals(config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.AllowFillIn"));
    final boolean allowScreenReaders = "true".equals(config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.AllowScreenReader"));
    final boolean allowAssembly = "true".equals(config.getConfigProperty(
            "org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.AllowAssembly"));

    int permissions = 0;
    if (allowPrinting) {
        permissions |= PdfWriter.ALLOW_PRINTING;
    }
    if (allowModifyContents) {
        permissions |= PdfWriter.ALLOW_MODIFY_CONTENTS;
    }
    if (allowModifyAnn) {
        permissions |= PdfWriter.ALLOW_MODIFY_ANNOTATIONS;
    }
    if (allowCopy) {
        permissions |= PdfWriter.ALLOW_COPY;
    }
    if (allowFillIn) {
        permissions |= PdfWriter.ALLOW_FILL_IN;
    }
    if (allowScreenReaders) {
        permissions |= PdfWriter.ALLOW_SCREENREADERS;
    }
    if (allowAssembly) {
        permissions |= PdfWriter.ALLOW_ASSEMBLY;
    }
    if (allowDegradedPrinting) {
        permissions |= PdfWriter.ALLOW_DEGRADED_PRINTING;
    }
    return permissions;
}