@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // IE workaround: write into byte array first. ByteArrayOutputStream baos = createTemporaryOutputStream(); PdfReader reader = readPdfResource(); PdfStamper stamper = new PdfStamper(reader, baos); mergePdfDocument(model, stamper, request, response); stamper.close(); // Flush to HTTP response. writeToResponse(response, baos); }
@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // IE workaround: write into byte array first. ByteArrayOutputStream baos = createTemporaryOutputStream(); PdfReader reader = readPdfResource(); PdfStamper stamper = new PdfStamper(reader, baos); mergePdfDocument(model, stamper, request, response); stamper.close(); // Flush to HTTP response. writeToResponse(response, baos); }
public void run() throws IOException, DocumentException { final PdfReader reader = new PdfReader(inputFile); final PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile)); replaceLinksWithPageBookmarks(reader, stamper); stamper.close(); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * @param strength128Bits <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, byte userPassword[], byte ownerPassword[], int permissions, boolean strength128Bits) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os); stamper.setEncryption(userPassword, ownerPassword, permissions, strength128Bits); stamper.close(); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param strength <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, boolean strength, String userPassword, String ownerPassword, int permissions) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os); stamper.setEncryption(strength, userPassword, ownerPassword, permissions); stamper.close(); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * @param strength128Bits <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, byte[] userPassword, byte[] ownerPassword, int permissions, boolean strength128Bits) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os); stamper.setEncryption(userPassword, ownerPassword, permissions, strength128Bits); stamper.close(); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * @param strength128Bits <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length * @param globalDate * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, byte userPassword[], byte ownerPassword[], int permissions, boolean strength128Bits, Calendar globalDate) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os, globalDate); stamper.setEncryption(userPassword, ownerPassword, permissions, strength128Bits); stamper.close(globalDate); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param strength <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * @param globalDate * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, boolean strength, String userPassword, String ownerPassword, int permissions, Calendar globalDate) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os, globalDate); stamper.setEncryption(strength, userPassword, ownerPassword, permissions); stamper.close(globalDate); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param strength <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, boolean strength, String userPassword, String ownerPassword, int permissions) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os); stamper.setEncryption(strength, userPassword, ownerPassword, permissions); stamper.close(); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param type the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128. * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * values delete the key in the original info dictionary * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, int type, String userPassword, String ownerPassword, int permissions) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os); stamper.setEncryption(type, userPassword, ownerPassword, permissions); stamper.close(); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param type the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128. * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * values delete the key in the original info dictionary * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, int type, String userPassword, String ownerPassword, int permissions) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os); stamper.setEncryption(type, userPassword, ownerPassword, permissions); stamper.close(); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param type the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128. * Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * values delete the key in the original info dictionary * @param globalDate * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, int type, String userPassword, String ownerPassword, int permissions, Calendar globalDate) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os, globalDate); stamper.setEncryption(type, userPassword, ownerPassword, permissions); stamper.close(globalDate); }
private ByteArrayOutputStream insertImage(ByteArrayOutputStream out, Image image) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(out.size()); PdfReader reader = new PdfReader(out.toByteArray()); PdfStamper stamper = new PdfStamper(reader, os); for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfContentByte canvas = stamper.getUnderContent(i); canvas.addImage(image); } reader.close(); stamper.close(); return os; } catch (Exception e) { throw new RuntimeException(e); } } }
private ByteArrayOutputStream insertImage(ByteArrayOutputStream out, Image image) { try { ByteArrayOutputStream os = new ByteArrayOutputStream(out.size()); PdfReader reader = new PdfReader(out.toByteArray()); PdfStamper stamper = new PdfStamper(reader, os); for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfContentByte canvas = stamper.getUnderContent(i); canvas.addImage(image); } reader.close(); stamper.close(); return os; } catch (Exception e) { throw new RuntimeException(e); } } }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param strength <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * @param newInfo an optional <CODE>String</CODE> map to add or change * the info dictionary. Entries with <CODE>null</CODE> * values delete the key in the original info dictionary * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, boolean strength, String userPassword, String ownerPassword, int permissions, HashMap newInfo) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os); stamper.setEncryption(strength, userPassword, ownerPassword, permissions); stamper.setMoreInfo(newInfo); stamper.close(); }
/** Entry point to encrypt a PDF document. The encryption parameters are the same as in * <code>PdfWriter</code>. The userPassword and the * ownerPassword can be null or have zero length. In this case the ownerPassword * is replaced by a random string. The open permissions for the document can be * AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations, * AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting. * The permissions can be combined by ORing them. * @param reader the read PDF * @param os the output destination * @param userPassword the user password. Can be null or empty * @param ownerPassword the owner password. Can be null or empty * @param permissions the user permissions * @param strength128Bits <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length * @param newInfo an optional <CODE>String</CODE> map to add or change * the info dictionary. Entries with <CODE>null</CODE> * values delete the key in the original info dictionary * @throws DocumentException on error * @throws IOException on error */ public static void encrypt(PdfReader reader, OutputStream os, byte userPassword[], byte ownerPassword[], int permissions, boolean strength128Bits, HashMap newInfo) throws DocumentException, IOException { PdfStamper stamper = new PdfStamper(reader, os); stamper.setEncryption(userPassword, ownerPassword, permissions, strength128Bits); stamper.setMoreInfo(newInfo); stamper.close(); }
/** */ public static Map<String, Object> getAcroFieldsFromPdf(DispatchContext dctx, Map<String, ? extends Object> context) { Map<String, Object> acroFieldMap = new HashMap<>(); try { ByteArrayOutputStream os = new ByteArrayOutputStream(); Delegator delegator = dctx.getDelegator(); ByteBuffer byteBuffer = getInputByteBuffer(context, delegator); PdfReader r = new PdfReader(byteBuffer.array()); PdfStamper s = new PdfStamper(r,os); AcroFields fs = s.getAcroFields(); Map<String, Object> map = UtilGenerics.checkMap(fs.getFields()); s.setFormFlattening(true); for (String fieldName : map.keySet()) { String parmValue = fs.getField(fieldName); acroFieldMap.put(fieldName, parmValue); } } catch (DocumentException | GeneralException | IOException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } Map<String, Object> results = ServiceUtil.returnSuccess(); results.put("acroFieldMap", acroFieldMap); return results; }
@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // IE workaround: write into byte array first. ByteArrayOutputStream baos = createTemporaryOutputStream(); PdfReader reader = readPdfResource(); PdfStamper stamper = new PdfStamper(reader, baos); mergePdfDocument(model, stamper, request, response); stamper.close(); // Flush to HTTP response. writeToResponse(response, baos); }
@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { // IE workaround: write into byte array first. ByteArrayOutputStream baos = createTemporaryOutputStream(); PdfReader reader = readPdfResource(); PdfStamper stamper = new PdfStamper(reader, baos); mergePdfDocument(model, stamper, request, response); stamper.close(); // Flush to HTTP response. writeToResponse(response, baos); }
@Override public void encodeBegin(FacesContext facesContext) throws IOException { log.info("Loading template #0", getURL()); if (getURL().indexOf("://") < 0) { reader = new PdfReader(ResourceLoader.instance().getResourceAsStream(getURL())); } else { reader = new PdfReader(new URL(getURL())); } buffer = new ByteArrayOutputStream(); try { stamper = new PdfStamper(reader, buffer); Contexts.getEventContext().set(STAMPER_KEY, stamper); } catch (DocumentException e) { throw new FacesException("Could not create PDF stamper", e); } fields = stamper.getAcroFields(); Contexts.getEventContext().set(FIELDS_KEY, fields); }