1 48 49 package com.lowagie.text.pdf; 50 51 import java.io.IOException ; 52 import java.io.OutputStream ; 53 import java.util.HashMap ; 54 55 import com.lowagie.text.DocumentException; 56 57 61 public class PdfEncryptor { 62 63 private PdfEncryptor(){ 64 } 65 66 81 public static void encrypt(PdfReader reader, OutputStream os, byte userPassword[], byte ownerPassword[], int permissions, boolean strength128Bits) throws DocumentException, IOException { 82 PdfStamper stamper = new PdfStamper(reader, os); 83 stamper.setEncryption(userPassword, ownerPassword, permissions, strength128Bits); 84 stamper.close(); 85 } 86 87 106 public static void encrypt(PdfReader reader, OutputStream os, byte userPassword[], byte ownerPassword[], int permissions, boolean strength128Bits, HashMap newInfo) throws DocumentException, IOException { 107 PdfStamper stamper = new PdfStamper(reader, os); 108 stamper.setEncryption(userPassword, ownerPassword, permissions, strength128Bits); 109 stamper.setMoreInfo(newInfo); 110 stamper.close(); 111 } 112 113 128 public static void encrypt(PdfReader reader, OutputStream os, boolean strength, String userPassword, String ownerPassword, int permissions) throws DocumentException, IOException { 129 PdfStamper stamper = new PdfStamper(reader, os); 130 stamper.setEncryption(strength, userPassword, ownerPassword, permissions); 131 stamper.close(); 132 } 133 134 153 public static void encrypt(PdfReader reader, OutputStream os, boolean strength, String userPassword, String ownerPassword, int permissions, HashMap newInfo) throws DocumentException, IOException { 154 PdfStamper stamper = new PdfStamper(reader, os); 155 stamper.setEncryption(strength, userPassword, ownerPassword, permissions); 156 stamper.setMoreInfo(newInfo); 157 stamper.close(); 158 } 159 160 161 181 public static void encrypt(PdfReader reader, OutputStream os, int type, String userPassword, String ownerPassword, int permissions, HashMap newInfo) throws DocumentException, IOException { 182 PdfStamper stamper = new PdfStamper(reader, os); 183 stamper.setEncryption(type, userPassword, ownerPassword, permissions); 184 stamper.setMoreInfo(newInfo); 185 stamper.close(); 186 } 187 188 206 public static void encrypt(PdfReader reader, OutputStream os, int type, String userPassword, String ownerPassword, int permissions) throws DocumentException, IOException { 207 PdfStamper stamper = new PdfStamper(reader, os); 208 stamper.setEncryption(type, userPassword, ownerPassword, permissions); 209 stamper.close(); 210 } 211 212 217 public static String getPermissionsVerbose(int permissions) { 218 StringBuffer buf = new StringBuffer ("Allowed:"); 219 if ((PdfWriter.AllowPrinting & permissions) == PdfWriter.AllowPrinting) buf.append(" Printing"); 220 if ((PdfWriter.AllowModifyContents & permissions) == PdfWriter.AllowModifyContents) buf.append(" Modify contents"); 221 if ((PdfWriter.AllowCopy & permissions) == PdfWriter.AllowCopy) buf.append(" Copy"); 222 if ((PdfWriter.AllowModifyAnnotations & permissions) == PdfWriter.AllowModifyAnnotations) buf.append(" Modify annotations"); 223 if ((PdfWriter.AllowFillIn & permissions) == PdfWriter.AllowFillIn) buf.append(" Fill in"); 224 if ((PdfWriter.AllowScreenReaders & permissions) == PdfWriter.AllowScreenReaders) buf.append(" Screen readers"); 225 if ((PdfWriter.AllowAssembly & permissions) == PdfWriter.AllowAssembly) buf.append(" Assembly"); 226 if ((PdfWriter.AllowDegradedPrinting & permissions) == PdfWriter.AllowDegradedPrinting) buf.append(" Degraded printing"); 227 return buf.toString(); 228 } 229 } | Popular Tags |