List of usage examples for com.itextpdf.text.pdf PdfWriter ENCRYPTION_AES_128
int ENCRYPTION_AES_128
To view the source code for com.itextpdf.text.pdf PdfWriter ENCRYPTION_AES_128.
Click Source Link
From source file:com.github.albfernandez.joinpdf.JoinPdf.java
License:Open Source License
private void setParametersAndHeaders(final PdfWriter writer, final Document document) throws DocumentException { if (this.extraCompression) { writer.setFullCompression();/*ww w . j a va 2 s. c o m*/ } if (this.isCrypt() && bouncyCastleLoaded) { int permisos = PdfWriter.ALLOW_PRINTING; writer.setEncryption(null, null, permisos, PdfWriter.ENCRYPTION_AES_128); } if (!StringUtils.isBlank(this.getMetadataAuthor())) { document.addAuthor(this.getMetadataAuthor()); } if (!StringUtils.isBlank(this.getMetadataKeywords())) { document.addKeywords(this.getMetadataKeywords()); } if (!StringUtils.isBlank(this.getMetadataTitle())) { document.addTitle(this.getMetadataTitle()); } if (!StringUtils.isBlank(this.getMetadataSubject())) { document.addSubject(this.getMetadataSubject()); } }
From source file:com.vectorprint.report.itext.style.stylers.DocumentSettings.java
License:Open Source License
@Override public final <E> E style(E element, Object data) throws VectorPrintException { document.setPageSize(new Rectangle(getValue(WIDTH, Float.class), getValue(HEIGHT, Float.class))); document.setMargins(getValue(ReportConstants.MARGIN.margin_left.name(), Float.class), getValue(ReportConstants.MARGIN.margin_right.name(), Float.class), getValue(ReportConstants.MARGIN.margin_top.name(), Float.class), getValue(ReportConstants.MARGIN.margin_bottom.name(), Float.class)); writer.setPdfVersion(PdfWriter.PDF_VERSION_1_5); writer.addViewerPreference(PdfName.NONFULLSCREENPAGEMODE, PdfName.USEOC); writer.addViewerPreference(PdfName.PRINT, PdfName.DUPLEX); document.addProducer();// w w w . j a va 2s .c o m document.addCreationDate(); byte[] password = getValue(PASSWORD, byte[].class); byte[] userpassword = getValue(USER_PASSWORD, byte[].class); byte[] ownerpassword = getValue(OWNER_PASSWORD, byte[].class); if (userpassword == null) { userpassword = password; } if (ownerpassword == null) { ownerpassword = password; } int permissions = ((PermissionsParameter) getParameter(PERMISSIONS, PERMISSION[].class)).getPermission(); ENCRYPTION encryption = getValue(ENCRYPTION_PARAM, ENCRYPTION.class); if (userpassword != null) { int enc = encryption != null ? encryption.encryption : PdfWriter.ENCRYPTION_AES_128; try { writer.setEncryption(userpassword, ownerpassword, permissions, enc); ArrayHelper.clear(password); ArrayHelper.clear(ownerpassword); ArrayHelper.clear(userpassword); } catch (DocumentException ex) { throw new VectorPrintException(ex); } } else if (getValue(CERTIFICATE, URL.class) != null) { int enc = encryption != null ? encryption.encryption : PdfWriter.ENCRYPTION_AES_128; try { writer.setEncryption(new Certificate[] { loadCertificate() }, new int[] { permissions }, enc); } catch (DocumentException ex) { throw new VectorPrintException(ex); } } for (PDFBOX b : PDFBOX.values()) { if (getValue(b.name(), float[].class) != null) { float[] size = getValue(b.name(), float[].class); writer.setBoxSize(b.name(), new Rectangle(size[0], size[1], size[2], size[3])); } } document.addSubject(getValue(SUBJECT, String.class)); document.addAuthor(getValue(AUTHOR, String.class)); document.addTitle(getValue(TITLE, String.class)); document.addCreator(getValue(CREATOR, String.class)); document.addKeywords(getValue(KEYWORDS, String.class)); if (getValue(PDFA, Boolean.class)) { try { pdfA1A(writer); } catch (IOException | DocumentException ex) { throw new VectorPrintException(ex); } } writer.createXmpMetadata(); return (E) document; }
From source file:org.sejda.impl.itext5.util.EncryptionUtils.java
License:Open Source License
/** * Mapping between Sejda and iText encryption algorithms * /*from ww w . j a v a2 s . c o m*/ * @param encryption * @return the iText encryption constant */ public static int getEncryptionAlgorithm(PdfEncryption encryption) { switch (encryption) { case AES_ENC_128: return PdfWriter.ENCRYPTION_AES_128; case STANDARD_ENC_128: return PdfWriter.STANDARD_ENCRYPTION_128; default: return PdfWriter.STANDARD_ENCRYPTION_40; } }