List of usage examples for com.lowagie.text.pdf PdfWriter ALLOW_SCREENREADERS
int ALLOW_SCREENREADERS
To view the source code for com.lowagie.text.pdf PdfWriter ALLOW_SCREENREADERS.
Click Source Link
From source file:com.jaspersoft.ireport.designer.options.export.PdfExportParametersPanel.java
License:Open Source License
public void load() { setInit(true);/*from w w w.jav a2 s . co m*/ 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 {/*from ww w . java 2s. c o m*/ 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.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 www. j ava 2 s .c om // 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//from ww w . jav a 2 s .com * 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;//from w w w . ja v a2s . co 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/* w ww . ja v a 2 s . co m*/ * @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]"); }
From source file:net.laubenberger.bogatyr.helper.HelperPdf.java
License:Open Source License
/** * Encrypt a PDF with a given user and password. * //from www . j a va 2 s. c o m * @param source * {@link File} * @param dest * {@link File} for the encrypted PDF * @param user * of the dest {@link File} * @param password * of the dest {@link File} * @throws DocumentException * @throws IOException * @since 0.9.4 */ public static void encrypt(final File source, final File dest, final byte[] user, final byte[] password) throws IOException, DocumentException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(source, dest, user, password)); if (null == source) { throw new RuntimeExceptionIsNull("source"); //$NON-NLS-1$ } if (null == dest) { throw new RuntimeExceptionIsNull("dest"); //$NON-NLS-1$ } if (HelperObject.isEquals(source, dest)) { throw new RuntimeExceptionIsEquals("source", "dest"); //$NON-NLS-1$ //$NON-NLS-2$ } if (null == user) { throw new RuntimeExceptionIsNull("user"); //$NON-NLS-1$ } if (!HelperArray.isValid(user)) { throw new RuntimeExceptionIsEmpty("user"); //$NON-NLS-1$ } if (null == password) { throw new RuntimeExceptionIsNull("password"); //$NON-NLS-1$ } if (!HelperArray.isValid(password)) { throw new RuntimeExceptionIsEmpty("password"); //$NON-NLS-1$ } PdfReader reader = null; OutputStream os = null; try { reader = new PdfReader(source.getAbsolutePath()); os = new FileOutputStream(dest); PdfEncryptor.encrypt(reader, os, user, password, PdfWriter.ALLOW_ASSEMBLY | PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_FILL_IN | PdfWriter.ALLOW_MODIFY_ANNOTATIONS | PdfWriter.ALLOW_MODIFY_CONTENTS | PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_SCREENREADERS, true); } finally { if (null != os) { os.close(); } if (null != reader) { reader.close(); } } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.laubenberger.bogatyr.helper.HelperPdf.java
License:Open Source License
/** * Removes all restrictions from a PDF with a given password. * /*from w ww . j a v a 2 s. c om*/ * @param source * {@link File} * @param dest * {@link File} for the unlocked PDF * @param password * of the source {@link File} * @throws DocumentException * @throws IOException * @since 0.9.0 */ public static void unlock(final File source, final File dest, final byte[] password) throws IOException, DocumentException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(source, dest, password)); if (null == source) { throw new RuntimeExceptionIsNull("source"); //$NON-NLS-1$ } if (null == dest) { throw new RuntimeExceptionIsNull("dest"); //$NON-NLS-1$ } if (HelperObject.isEquals(source, dest)) { throw new RuntimeExceptionIsEquals("source", "dest"); //$NON-NLS-1$ //$NON-NLS-2$ } if (null == password) { throw new RuntimeExceptionIsNull("password"); //$NON-NLS-1$ } if (!HelperArray.isValid(password)) { throw new RuntimeExceptionIsEmpty("password"); //$NON-NLS-1$ } PdfReader reader = null; OutputStream os = null; try { reader = new PdfReader(source.getAbsolutePath(), password); os = new FileOutputStream(dest); PdfEncryptor.encrypt(reader, os, null, null, PdfWriter.ALLOW_ASSEMBLY | PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_FILL_IN | PdfWriter.ALLOW_MODIFY_ANNOTATIONS | PdfWriter.ALLOW_MODIFY_CONTENTS | PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_SCREENREADERS, true); } finally { if (null != os) { os.close(); } if (null != reader) { reader.close(); } } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.laubenberger.wichtel.helper.HelperPdf.java
License:Open Source License
/** * Encrypt a PDF with a given user and password. * /*from www. j a v a 2s. c o m*/ * @param source * {@link File} * @param dest * {@link File} for the encrypted PDF * @param user * of the dest {@link File} * @param password * of the dest {@link File} * @throws DocumentException * @throws IOException * @since 0.0.1 */ public static void encrypt(final File source, final File dest, final byte[] user, final byte... password) throws IOException, DocumentException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(source, dest, user, password)); if (null == source) { throw new RuntimeExceptionIsNull("source"); //$NON-NLS-1$ } if (null == dest) { throw new RuntimeExceptionIsNull("dest"); //$NON-NLS-1$ } if (HelperObject.isEquals(source, dest)) { throw new RuntimeExceptionIsEquals("source", "dest"); //$NON-NLS-1$ //$NON-NLS-2$ } if (null == user) { throw new RuntimeExceptionIsNull("user"); //$NON-NLS-1$ } if (!HelperArray.isValid(user)) { throw new RuntimeExceptionIsEmpty("user"); //$NON-NLS-1$ } if (null == password) { throw new RuntimeExceptionIsNull("password"); //$NON-NLS-1$ } if (!HelperArray.isValid(password)) { throw new RuntimeExceptionIsEmpty("password"); //$NON-NLS-1$ } PdfReader reader = null; try (OutputStream os = new FileOutputStream(dest)) { reader = new PdfReader(source.getAbsolutePath()); PdfEncryptor.encrypt(reader, os, user, password, PdfWriter.ALLOW_ASSEMBLY | PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_FILL_IN | PdfWriter.ALLOW_MODIFY_ANNOTATIONS | PdfWriter.ALLOW_MODIFY_CONTENTS | PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_SCREENREADERS, true); } finally { if (null != reader) { reader.close(); } } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }
From source file:net.laubenberger.wichtel.helper.HelperPdf.java
License:Open Source License
/** * Removes all restrictions from a PDF with a given password. * /*from ww w .ja v a 2 s .c o m*/ * @param source * {@link File} * @param dest * {@link File} for the unlocked PDF * @param password * of the source {@link File} * @throws DocumentException * @throws IOException * @since 0.0.1 */ public static void unlock(final File source, final File dest, final byte... password) throws IOException, DocumentException { // $JUnit$ if (log.isDebugEnabled()) log.debug(HelperLog.methodStart(source, dest, password)); if (null == source) { throw new RuntimeExceptionIsNull("source"); //$NON-NLS-1$ } if (null == dest) { throw new RuntimeExceptionIsNull("dest"); //$NON-NLS-1$ } if (HelperObject.isEquals(source, dest)) { throw new RuntimeExceptionIsEquals("source", "dest"); //$NON-NLS-1$ //$NON-NLS-2$ } if (null == password) { throw new RuntimeExceptionIsNull("password"); //$NON-NLS-1$ } if (!HelperArray.isValid(password)) { throw new RuntimeExceptionIsEmpty("password"); //$NON-NLS-1$ } PdfReader reader = null; try (OutputStream os = new FileOutputStream(dest)) { reader = new PdfReader(source.getAbsolutePath(), password); PdfEncryptor.encrypt(reader, os, null, null, PdfWriter.ALLOW_ASSEMBLY | PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_FILL_IN | PdfWriter.ALLOW_MODIFY_ANNOTATIONS | PdfWriter.ALLOW_MODIFY_CONTENTS | PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_SCREENREADERS, true); } finally { if (null != reader) { reader.close(); } } if (log.isDebugEnabled()) log.debug(HelperLog.methodExit()); }