-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdfzippasword.java
More file actions
34 lines (27 loc) · 1.22 KB
/
pdfzippasword.java
File metadata and controls
34 lines (27 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
public class pdfzippasword {
public static void main(String[] args) throws IOException, DocumentException {
// TODO Auto-generated method stub
File outEncryptpdfFileName = new File("Protected_PDF.PDF");
FileInputStream filePdfCopy = new FileInputStream("Original_PDF.PDF");
PdfReader pdfReader = new PdfReader(filePdfCopy);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(outEncryptpdfFileName));
String zipPassword1 = "testpass#";
String zipPassword = zipPassword1.trim();
zipPassword= URLEncoder.encode(zipPassword,"UTF-8");
pdfStamper.setEncryption(zipPassword.getBytes("UTF-8"), zipPassword.getBytes("UTF-8"),
PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA);
pdfStamper.close();
pdfReader.close();
filePdfCopy.close();
}
}