88import java .io .IOException ;
99import java .util .ArrayList ;
1010import java .util .List ;
11+ import org .apache .pdfbox .Loader ;
1112import org .apache .pdfbox .cos .COSDictionary ;
1213import org .apache .pdfbox .cos .COSName ;
1314import org .apache .pdfbox .pdmodel .PDDocument ;
@@ -37,7 +38,7 @@ private PDFUtils() {
3738 * @param inputSource The PDF file.
3839 */
3940 public static int getNumberOfPages (LocalInputSource inputSource ) throws IOException {
40- PDDocument document = PDDocument . load (inputSource .getFile ());
41+ PDDocument document = Loader . loadPDF (inputSource .getFile ());
4142 int pageCount = document .getNumberOfPages ();
4243 document .close ();
4344 return pageCount ;
@@ -81,7 +82,7 @@ private static byte[] createPdfFromExistingPdf(
8182 * @param pageNumbers Lit of page numbers to merge together.
8283 */
8384 public static byte [] mergePdfPages (File file , List <Integer > pageNumbers ) throws IOException {
84- PDDocument document = PDDocument . load (file );
85+ PDDocument document = Loader . loadPDF (file );
8586 return createPdfFromExistingPdf (document , pageNumbers , true );
8687 }
8788
@@ -100,7 +101,7 @@ public static byte[] mergePdfPages(
100101
101102
102103 public static boolean isPdfEmpty (File file ) throws IOException {
103- return checkIfPdfIsEmpty (PDDocument . load (file ));
104+ return checkIfPdfIsEmpty (Loader . loadPDF (file ));
104105 }
105106
106107 private static boolean checkIfPdfIsEmpty (PDDocument document ) throws IOException {
@@ -143,7 +144,7 @@ public static List<PdfPageImage> pdfToImages(String filePath) throws IOException
143144 * @return List of all pages as images.
144145 */
145146 public static List <PdfPageImage > pdfToImages (LocalInputSource source ) throws IOException {
146- PDDocument document = PDDocument . load (source .getFile ());
147+ PDDocument document = Loader . loadPDF (source .getFile ());
147148 PDFRenderer pdfRenderer = new PDFRenderer (document );
148149 List <PdfPageImage > pdfPageImages = new ArrayList <>();
149150 for (int i = 0 ; i < document .getNumberOfPages (); i ++) {
@@ -182,7 +183,7 @@ public static PdfPageImage pdfPageToImage(
182183 int pageNumber
183184 ) throws IOException {
184185 int index = pageNumber - 1 ;
185- PDDocument document = PDDocument . load (source .getFile ());
186+ PDDocument document = Loader . loadPDF (source .getFile ());
186187 PDFRenderer pdfRenderer = new PDFRenderer (document );
187188 BufferedImage imageBuffer = pdfPageToImageBuffer (index , document , pdfRenderer );
188189 document .close ();
0 commit comments