List of usage examples for com.lowagie.text.pdf PdfWriter ALLOW_COPY
int ALLOW_COPY
To view the source code for com.lowagie.text.pdf PdfWriter ALLOW_COPY.
Click Source Link
From source file:PdfEncryptApp.java
License:Open Source License
/** * */// w ww. ja v a 2 s . com public void pdf() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/PdfEncryptReport.jrprint"); JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pdf"); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setEncrypted(true); configuration.set128BitKey(true); configuration.setUserPassword("jasper"); configuration.setOwnerPassword("reports"); configuration.setPermissions(PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING); exporter.setConfiguration(configuration); exporter.exportReport(); System.err.println("PDF creation time : " + (System.currentTimeMillis() - start)); }
From source file:com.globalsight.everest.webapp.pagehandler.edit.inctxrv.pdf.PreviewPDFHelper.java
License:Apache License
public static File setCopyOnlyPermission(File p_file) throws DocumentException, IOException { PdfReader reader = new PdfReader(p_file.getAbsolutePath()); String outPutFile = FileUtils.getPrefix(p_file.getAbsolutePath()) + "_hidebars.pdf"; int n = reader.getNumberOfPages(); Rectangle psize = reader.getPageSize(1); float width = psize.height(); float height = psize.width(); Document document = new Document(new Rectangle(width, height)); PdfCopy writer = new PdfCopy(document, new FileOutputStream(outPutFile)); writer.setEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING); try {/*from w w w . ja v a 2s . c om*/ document.open(); int i = 0; while (i < n) { document.newPage(); i++; PdfImportedPage page1 = writer.getImportedPage(reader, i); writer.addPage(page1); } document.close(); } catch (IllegalArgumentException e) { if (!e.getMessage().equals("PdfReader not opened with owner password")) { throw new EnvoyServletException(e); } else { LOGGER.error(e.getMessage(), e); } } return new File(outPutFile); }
From source file:com.globalsight.everest.webapp.pagehandler.edit.online.PreviewPDFPageHandler.java
License:Apache License
public static File setCopyOnlyPermission(File p_file) throws DocumentException, IOException { PdfReader reader = new PdfReader(p_file.getAbsolutePath()); String outPutFile = FileUtils.getPrefix(p_file.getAbsolutePath()) + "_hidebars.pdf"; int n = reader.getNumberOfPages(); Rectangle psize = reader.getPageSize(1); float width = psize.height(); float height = psize.width(); Document document = new Document(new Rectangle(width, height)); PdfCopy writer = new PdfCopy(document, new FileOutputStream(outPutFile)); writer.setEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING); try {/*from w w w .jav a 2 s . c o m*/ document.open(); int i = 0; while (i < n) { document.newPage(); i++; PdfImportedPage page1 = writer.getImportedPage(reader, i); writer.addPage(page1); } document.close(); } catch (IllegalArgumentException e) { if (!e.getMessage().equals("PdfReader not opened with owner password")) { throw new EnvoyServletException(e); } else { CATEGORY.error(e.getMessage(), e); } } return new File(outPutFile); }
From source file:com.jaspersoft.ireport.designer.options.export.PdfExportParametersPanel.java
License:Open Source License
public void load() { setInit(true);/*from ww w.j a va2s.c om*/ Preferences pref = IReportManager.getPreferences(); JRPropertiesUtil jrPropUtils = IRLocalJasperReportsContext.getUtilities(); Misc.setComboboxSelectedTagValue(jComboBoxPDFVersion, pref.get(JRPdfExporterParameter.PROPERTY_PDF_VERSION, jrPropUtils.getProperty(JRPdfExporterParameter.PROPERTY_PDF_VERSION))); Misc.setComboboxSelectedTagValue(jComboBoxPdfA, pref.get(JRPdfExporterParameter.PROPERTY_PDFA_CONFORMANCE, jrPropUtils.getProperty(JRPdfExporterParameter.PROPERTY_PDFA_CONFORMANCE))); jTextFieldICC.setText(pref.get(JRPdfExporterParameter.PROPERTY_PDFA_ICC_PROFILE_PATH, Misc.nvl(jrPropUtils.getProperty(JRPdfExporterParameter.PROPERTY_PDFA_ICC_PROFILE_PATH), ""))); jCheckBoxCreatingBatchModeBookmarks.setSelected(pref.getBoolean( JRPdfExporterParameter.PROPERTY_CREATE_BATCH_MODE_BOOKMARKS, jrPropUtils.getBooleanProperty(JRPdfExporterParameter.PROPERTY_CREATE_BATCH_MODE_BOOKMARKS))); jCheckBoxCompressed.setSelected(pref.getBoolean(JRPdfExporterParameter.PROPERTY_COMPRESSED, jrPropUtils.getBooleanProperty(JRPdfExporterParameter.PROPERTY_COMPRESSED))); jCheckBoxForceLinebreakPolicy .setSelected(pref.getBoolean(JRPdfExporterParameter.PROPERTY_FORCE_LINEBREAK_POLICY, jrPropUtils.getBooleanProperty(JRPdfExporterParameter.PROPERTY_FORCE_LINEBREAK_POLICY))); jCheckBoxForceSVGShapes.setSelected(pref.getBoolean(JRPdfExporterParameter.PROPERTY_FORCE_SVG_SHAPES, jrPropUtils.getBooleanProperty(JRPdfExporterParameter.PROPERTY_FORCE_SVG_SHAPES))); jCheckBoxIsTagged.setSelected(pref.getBoolean(JRPdfExporterParameter.PROPERTY_TAGGED, jrPropUtils.getBooleanProperty(JRPdfExporterParameter.PROPERTY_TAGGED))); jComboBoxEncryption.setSelectedIndex(0); if (pref.getBoolean(JRPdfExporterParameter.PROPERTY_ENCRYPTED, jrPropUtils.getBooleanProperty(JRPdfExporterParameter.PROPERTY_ENCRYPTED))) { jComboBoxEncryption.setSelectedIndex(1); } if (pref.getBoolean(JRPdfExporterParameter.PROPERTY_128_BIT_KEY, jrPropUtils.getBooleanProperty(JRPdfExporterParameter.PROPERTY_128_BIT_KEY))) { jComboBoxEncryption.setSelectedIndex(2); } jTextFieldMetadataAuthor.setText(pref.get("export.pdf.METADATA_AUTHOR", "")); jTextFieldMetadataCreator.setText(pref.get("export.pdf.METADATA_CREATOR", "")); jTextFieldMetadataKeywords.setText(pref.get("export.pdf.METADATA_KEYWORDS", "")); jTextFieldMetadataSubject.setText(pref.get("export.pdf.METADATA_SUBJECT", "")); jTextFieldMetadataTitle.setText(pref.get("export.pdf.METADATA_TITLE", "")); jTextFieldOwnerPassword.setText(pref.get("export.pdf.OWNER_PASSWORD", "")); jTextFieldUserPassword.setText(pref.get("export.pdf.USER_PASSWORD", "")); jTextFieldTagLanguage.setText(pref.get("export.pdf.TAG_LANGUAGE", jrPropUtils.getProperty(JRPdfExporterParameter.PROPERTY_TAG_LANGUAGE))); jTextAreaPDFJavascript.setText(pref.get("export.pdf.PDF_JAVASCRIPT", jrPropUtils.getProperty(JRPdfExporterParameter.PROPERTY_PDF_JAVASCRIPT))); int documentPermissions = pref.getInt("export.pdf.PERMISSIONS", 0); jCheckBoxAllawDegradedPrinting.setSelected((documentPermissions & PdfWriter.ALLOW_DEGRADED_PRINTING) > 0); jCheckBoxAllowAssembly.setSelected((documentPermissions & PdfWriter.ALLOW_ASSEMBLY) > 0); jCheckBoxAllowCopy.setSelected((documentPermissions & PdfWriter.ALLOW_COPY) > 0); jCheckBoxAllowFillIn.setSelected((documentPermissions & PdfWriter.ALLOW_FILL_IN) > 0); jCheckBoxAllowModifyAnnotations.setSelected((documentPermissions & PdfWriter.ALLOW_MODIFY_ANNOTATIONS) > 0); jCheckBoxAllowModifyContents.setSelected((documentPermissions & PdfWriter.ALLOW_MODIFY_CONTENTS) > 0); jCheckBoxAllowPrinting .setSelected((documentPermissions & PdfWriter.ALLOW_PRINTING) == PdfWriter.ALLOW_PRINTING); jCheckBoxAllowScreenReaders.setSelected((documentPermissions & PdfWriter.ALLOW_SCREENREADERS) > 0); setInit(false); }
From source file:com.jaspersoft.ireport.designer.options.export.PdfExportParametersPanel.java
License:Open Source License
public void store() { Preferences pref = IReportManager.getPreferences(); Tag t = (Tag) jComboBoxPDFVersion.getSelectedItem(); if (t.getValue() == null) { pref.remove(JRPdfExporterParameter.PROPERTY_PDF_VERSION); } else {//w w w. ja va2 s. c om pref.put(JRPdfExporterParameter.PROPERTY_PDF_VERSION, "" + t.getValue()); } pref.putBoolean(JRPdfExporterParameter.PROPERTY_CREATE_BATCH_MODE_BOOKMARKS, jCheckBoxCreatingBatchModeBookmarks.isSelected()); pref.putBoolean(JRPdfExporterParameter.PROPERTY_COMPRESSED, jCheckBoxCompressed.isSelected()); pref.putBoolean(JRPdfExporterParameter.PROPERTY_FORCE_LINEBREAK_POLICY, jCheckBoxForceLinebreakPolicy.isSelected()); pref.putBoolean(JRPdfExporterParameter.PROPERTY_FORCE_SVG_SHAPES, jCheckBoxForceSVGShapes.isSelected()); pref.putBoolean(JRPdfExporterParameter.PROPERTY_TAGGED, jCheckBoxIsTagged.isSelected()); int index = jComboBoxEncryption.getSelectedIndex(); pref.putBoolean(JRPdfExporterParameter.PROPERTY_ENCRYPTED, (index != 0)); pref.putBoolean(JRPdfExporterParameter.PROPERTY_128_BIT_KEY, (index == 2)); pref.put("export.pdf.METADATA_AUTHOR", jTextFieldMetadataAuthor.getText()); pref.put("export.pdf.METADATA_CREATOR", jTextFieldMetadataCreator.getText()); pref.put("export.pdf.METADATA_KEYWORDS", jTextFieldMetadataKeywords.getText()); pref.put("export.pdf.METADATA_SUBJECT", jTextFieldMetadataSubject.getText()); pref.put("export.pdf.METADATA_TITLE", jTextFieldMetadataTitle.getText()); pref.put("export.pdf.OWNER_PASSWORD", jTextFieldOwnerPassword.getText()); pref.put("export.pdf.USER_PASSWORD", jTextFieldUserPassword.getText()); pref.put("export.pdf.TAG_LANGUAGE", jTextFieldTagLanguage.getText()); pref.put("export.pdf.PDF_JAVASCRIPT", jTextAreaPDFJavascript.getText()); t = (Tag) jComboBoxPdfA.getSelectedItem(); if (t.getValue() == null) { pref.remove(JRPdfExporterParameter.PROPERTY_PDFA_CONFORMANCE); } else { pref.put(JRPdfExporterParameter.PROPERTY_PDFA_CONFORMANCE, "" + t.getValue()); } pref.put(JRPdfExporterParameter.PROPERTY_PDFA_ICC_PROFILE_PATH, jTextFieldICC.getText()); int documentPermissions = 0; if (jCheckBoxAllawDegradedPrinting.isSelected()) documentPermissions |= PdfWriter.ALLOW_DEGRADED_PRINTING; if (jCheckBoxAllowAssembly.isSelected()) documentPermissions |= PdfWriter.ALLOW_ASSEMBLY; if (jCheckBoxAllowCopy.isSelected()) documentPermissions |= PdfWriter.ALLOW_COPY; if (jCheckBoxAllowFillIn.isSelected()) documentPermissions |= PdfWriter.ALLOW_FILL_IN; if (jCheckBoxAllowModifyAnnotations.isSelected()) documentPermissions |= PdfWriter.ALLOW_MODIFY_ANNOTATIONS; if (jCheckBoxAllowModifyContents.isSelected()) documentPermissions |= PdfWriter.ALLOW_MODIFY_CONTENTS; if (jCheckBoxAllowPrinting.isSelected()) documentPermissions |= PdfWriter.ALLOW_PRINTING; if (jCheckBoxAllowScreenReaders.isSelected()) documentPermissions |= PdfWriter.ALLOW_SCREENREADERS; pref.putInt("export.pdf.PERMISSIONS", documentPermissions); }
From source file:com.mirth.connect.connectors.doc.DocumentMessageDispatcher.java
License:Open Source License
private void writeDocument(String template, File file, MessageObject messageObject) throws Exception { // add tags to the template to create a valid HTML document StringBuilder contents = new StringBuilder(); if (template.lastIndexOf("<html") < 0) { contents.append("<html>"); if (template.lastIndexOf("<body") < 0) { contents.append("<body>"); contents.append(template);/*from ww w . ja va2s. c o m*/ contents.append("</body>"); } else { contents.append(template); } contents.append("</html>"); } else { contents.append(template); } if (connector.getDocumentType().toLowerCase().equals("pdf")) { FileOutputStream renderFos = null; try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); org.w3c.dom.Document document = builder .parse(new InputSource(new StringReader(contents.toString()))); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(document, null); renderFos = new FileOutputStream(file); renderer.layout(); renderer.createPDF(renderFos, true); } catch (Throwable e) { throw new Exception(e); } finally { if (renderFos != null) { renderFos.close(); } } if (connector.isEncrypt() && (connector.getPassword() != null)) { FileInputStream encryptFis = null; FileOutputStream encryptFos = null; try { encryptFis = new FileInputStream(file); PdfReader reader = new PdfReader(encryptFis); encryptFos = new FileOutputStream(file); PdfEncryptor.encrypt(reader, encryptFos, true, replacer.replaceValues(connector.getPassword(), messageObject), null, PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY); } catch (Exception e) { throw e; } finally { if (encryptFis != null) { encryptFis.close(); } if (encryptFos != null) { encryptFos.close(); } } } } else if (connector.getDocumentType().toLowerCase().equals("rtf")) { com.lowagie.text.Document document = null; try { document = new com.lowagie.text.Document(); ByteArrayInputStream bais = new ByteArrayInputStream(contents.toString().getBytes()); RtfWriter2.getInstance(document, new FileOutputStream(file)); document.open(); HtmlParser parser = new HtmlParser(); parser.go(document, bais); } finally { if (document != null) { document.close(); } } } }
From source file:com.naryx.tagfusion.cfm.document.cfDOCUMENT.java
License:Open Source License
private void setPermissions(cfSession _Session, PDFEncryption _pdfEnc) throws cfmRunTimeException { // apply encryption String encryption = getDynamic(_Session, "ENCRYPTION").getString().toLowerCase(); if (encryption.equals("40") || encryption.equals("40-bit")) { _pdfEnc.setEncryptionType(PdfWriter.STANDARD_ENCRYPTION_40); } else if (encryption.equals("128") || encryption.equals("128-bit")) { _pdfEnc.setEncryptionType(PdfWriter.STANDARD_ENCRYPTION_128); } else if (encryption.equals("aes")) { _pdfEnc.setEncryptionType(PdfWriter.ENCRYPTION_AES_128); } else if (!encryption.equals("none")) { throw newRunTimeException( "Invalid ENCRYPTION value. Supported values include \"40-bit\", \"128-bit\", \"AES\" and \"none\""); }//from w w w. j a v a 2 s .co m // Default to no permissions int permissionsMask = 0; if (containsAttribute("PERMISSIONS")) { String[] permissions = getDynamic(_Session, "PERMISSIONS").getString().toLowerCase().split(","); if (permissions.length > 0) { for (int i = 0; i < permissions.length; i++) { String nextPermission = permissions[i]; if (nextPermission.equals("allowprinting")) { permissionsMask |= PdfWriter.ALLOW_PRINTING; } else if (nextPermission.equals("allowmodifycontents")) { permissionsMask |= PdfWriter.ALLOW_MODIFY_CONTENTS; } else if (nextPermission.equals("allowcopy")) { permissionsMask |= PdfWriter.ALLOW_COPY; } else if (nextPermission.equals("allowmodifyannotations")) { permissionsMask |= PdfWriter.ALLOW_MODIFY_ANNOTATIONS; } else if (nextPermission.equals("allowscreenreaders")) { if (_pdfEnc.getEncryptionType() == PdfWriter.STANDARD_ENCRYPTION_40) throw newRunTimeException("AllowScreenReaders is not valid with 40-bit encryption"); permissionsMask |= PdfWriter.ALLOW_SCREENREADERS; } else if (nextPermission.equals("allowassembly")) { if (_pdfEnc.getEncryptionType() == PdfWriter.STANDARD_ENCRYPTION_40) throw newRunTimeException("AllowAssembly is not valid with 40-bit encryption"); permissionsMask |= PdfWriter.ALLOW_ASSEMBLY; } else if (nextPermission.equals("allowdegradedprinting")) { if (_pdfEnc.getEncryptionType() == PdfWriter.STANDARD_ENCRYPTION_40) throw newRunTimeException("AllowDegradedPrinting is not valid with 40-bit encryption"); permissionsMask |= PdfWriter.ALLOW_DEGRADED_PRINTING; } else if (nextPermission.equals("allowfillin")) { if (_pdfEnc.getEncryptionType() == PdfWriter.STANDARD_ENCRYPTION_40) throw newRunTimeException("AllowFillIn is not valid with 40-bit encryption"); permissionsMask |= PdfWriter.ALLOW_FILL_IN; } else { throw newRunTimeException("Invalid permissions value: " + nextPermission); } } } } // Set the allowed permissions _pdfEnc.setAllowedPrivileges(permissionsMask); if (containsAttribute("OWNERPASSWORD")) _pdfEnc.setOwnerPassword(getDynamic(_Session, "OWNERPASSWORD").getString().getBytes()); if (containsAttribute("USERPASSWORD")) _pdfEnc.setUserPassword(getDynamic(_Session, "USERPASSWORD").getString().getBytes()); }
From source file:com.servoy.extensions.plugins.pdf_output.PDFProvider.java
License:Open Source License
/** * Add password protection and security options to the PDF * * @author Scott Buttler// w w w. j a v a 2s . c o m * Adapted from the PDF Pro plugin with full approval from the author * * @sampleas js_encrypt(byte[], String) * * @param data the PDF * @param ownerPassword the owner password * @param userPassword the user password * @param allowAssembly whether to set the allow assembly permission * @param allowCopy whether to set the allow copy permission * @param allowDegradedPrinting whether to set the allow degraded printing permission * @param allowFillIn whether to set the allow fill in permission * @param allowModifyAnnotations whether to set the allow modify annotations permission * @param allowModifyContents whether to set the allow modify contents permission * @param allowPrinting whether to set the allow printing permission * @param allowScreenreaders whether to set the allow screen readers permission * @param is128bit whether to use 128-bit encryption * @param metaData a JavaScript object ({@link Scriptable}) that contains the metadata as property/value pairs * * @return the encrypted PDF * * @throws Exception */ public byte[] js_encrypt(byte[] data, String ownerPassword, String userPassword, boolean allowAssembly, boolean allowCopy, boolean allowDegradedPrinting, boolean allowFillIn, boolean allowModifyAnnotations, boolean allowModifyContents, boolean allowPrinting, boolean allowScreenreaders, boolean is128bit, Scriptable metaData) throws Exception { if (data == null) throw new IllegalArgumentException("Missing argument"); //$NON-NLS-1$ int sec = 0; if (allowAssembly) { sec = sec | PdfWriter.ALLOW_ASSEMBLY; } if (allowCopy) { sec = sec | PdfWriter.ALLOW_COPY; } if (allowDegradedPrinting) { sec = sec | PdfWriter.ALLOW_DEGRADED_PRINTING; } if (allowFillIn) { sec = sec | PdfWriter.ALLOW_FILL_IN; } if (allowModifyAnnotations) { sec = sec | PdfWriter.ALLOW_MODIFY_ANNOTATIONS; } if (allowModifyContents) { sec = sec | PdfWriter.ALLOW_MODIFY_CONTENTS; } if (allowPrinting) { sec = sec | PdfWriter.ALLOW_PRINTING; } if (allowScreenreaders) { sec = sec | PdfWriter.ALLOW_SCREENREADERS; } Map<String, Object> map = ITextTools.getMapFromScriptable(metaData); ByteArrayInputStream bais = new ByteArrayInputStream(data); return ITextTools.encrypt(bais, ownerPassword, userPassword, sec, is128bit, map); }
From source file:lucee.runtime.text.pdf.PDFDocument.java
License:Open Source License
public Struct getInfo() { PdfReader pr = null;/*w w w .ja v a 2 s .c o m*/ try { pr = getPdfReader(); //PdfDictionary catalog = pr.getCatalog(); int permissions = pr.getPermissions(); boolean encrypted = pr.isEncrypted(); Struct info = new StructImpl(); 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", Caster.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(Caster.toString(entry.getKey(), null), entry.getValue()); } return info; } catch (PageException pe) { throw new PageRuntimeException(pe); } finally { if (pr != null) pr.close(); } }
From source file:lucee.runtime.text.pdf.PDFUtil.java
License:Open Source License
/** * convert a string defintion of a permision in a integer Constant (PdfWriter.ALLOW_XXX) * @param strPermission/*from w w w . j a v a2 s .c om*/ * @return * @throws ApplicationException */ public static int toPermission(String strPermission) throws ApplicationException { 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 new ApplicationException("invalid permission [" + strPermission + "], valid permission values are [AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, AllowFillIn, AllowScreenReaders, AllowAssembly, AllowDegradedPrinting]"); }