-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasswordRemover.java
35 lines (35 loc) · 1.43 KB
/
passwordRemover.java
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
35
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileOutputStream;
public class passwordRemover {
public static void main(String[] args) {
String sourceFile="file path of the source pdf file";
String outFile="file path of the out pdf file";
try {
PdfReader.unethicalreading=true;
PdfReader pdfReader = new PdfReader(sourceFile);
Document document = new Document();
FileOutputStream out = new FileOutputStream(outFile);
PdfWriter pdfWriter = PdfWriter.getInstance(document,out);
document.open();
PdfContentByte cb = pdfWriter.getDirectContent();
int pageOfCurrentReaderPDF=0;
int pageNumber=pdfReader.getNumberOfPages();
System.out.println(pageNumber);
while (pageOfCurrentReaderPDF < pageNumber) {
document.newPage();
pageOfCurrentReaderPDF++;
PdfImportedPage page = pdfWriter.getImportedPage(pdfReader, pageOfCurrentReaderPDF);
cb.addTemplate(page, 0, 0);
}
out.flush();
document.close();
out.close();
}catch (Exception e){
e.printStackTrace();
}
}
}