#BAEL-5880: add main source and test for iText

This commit is contained in:
h_sharifi
2022-11-01 15:18:39 +03:30
parent 2ab80881c2
commit d8a230c995
2 changed files with 81 additions and 0 deletions
@@ -0,0 +1,31 @@
package com.baeldung.pdfinfo;
import com.itextpdf.text.pdf.PdfReader;
import java.io.IOException;
import java.util.HashMap;
public class PdfInfoIText {
public static int getNumberOfPage(final String pdfFile) throws IOException {
PdfReader reader = new PdfReader(pdfFile);
int pages = reader.getNumberOfPages();
reader.close();
return pages;
}
public static boolean isPasswordRequired(final String pdfFile) throws IOException {
PdfReader reader = new PdfReader(pdfFile);
boolean isEncrypted = reader.isEncrypted();
reader.close();
return isEncrypted;
}
public static HashMap<String, String> getInfo(final String pdfFile) throws IOException {
PdfReader reader = new PdfReader(pdfFile);
HashMap<String, String> info = reader.getInfo();
reader.close();
return info;
}
}