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 ;
1617import org .apache .pdfbox .pdmodel .PDResources ;
1718import org .apache .pdfbox .pdmodel .common .PDRectangle ;
1819import org .apache .pdfbox .pdmodel .font .PDType1Font ;
20+ import org .apache .pdfbox .pdmodel .font .Standard14Fonts ;
1921import org .apache .pdfbox .pdmodel .graphics .color .PDColor ;
2022import org .apache .pdfbox .pdmodel .graphics .image .PDImageXObject ;
2123import org .apache .pdfbox .rendering .ImageType ;
@@ -37,7 +39,7 @@ private PDFUtils() {
3739 * @param inputSource The PDF file.
3840 */
3941 public static int getNumberOfPages (LocalInputSource inputSource ) throws IOException {
40- PDDocument document = PDDocument . load (inputSource .getFile ());
42+ PDDocument document = Loader . loadPDF (inputSource .getFile ());
4143 int pageCount = document .getNumberOfPages ();
4244 document .close ();
4345 return pageCount ;
@@ -81,7 +83,7 @@ private static byte[] createPdfFromExistingPdf(
8183 * @param pageNumbers Lit of page numbers to merge together.
8284 */
8385 public static byte [] mergePdfPages (File file , List <Integer > pageNumbers ) throws IOException {
84- PDDocument document = PDDocument . load (file );
86+ PDDocument document = Loader . loadPDF (file );
8587 return createPdfFromExistingPdf (document , pageNumbers , true );
8688 }
8789
@@ -100,7 +102,7 @@ public static byte[] mergePdfPages(
100102
101103
102104 public static boolean isPdfEmpty (File file ) throws IOException {
103- return checkIfPdfIsEmpty (PDDocument . load (file ));
105+ return checkIfPdfIsEmpty (Loader . loadPDF (file ));
104106 }
105107
106108 private static boolean checkIfPdfIsEmpty (PDDocument document ) throws IOException {
@@ -143,7 +145,7 @@ public static List<PdfPageImage> pdfToImages(String filePath) throws IOException
143145 * @return List of all pages as images.
144146 */
145147 public static List <PdfPageImage > pdfToImages (LocalInputSource source ) throws IOException {
146- PDDocument document = PDDocument . load (source .getFile ());
148+ PDDocument document = Loader . loadPDF (source .getFile ());
147149 PDFRenderer pdfRenderer = new PDFRenderer (document );
148150 List <PdfPageImage > pdfPageImages = new ArrayList <>();
149151 for (int i = 0 ; i < document .getNumberOfPages (); i ++) {
@@ -182,7 +184,7 @@ public static PdfPageImage pdfPageToImage(
182184 int pageNumber
183185 ) throws IOException {
184186 int index = pageNumber - 1 ;
185- PDDocument document = PDDocument . load (source .getFile ());
187+ PDDocument document = Loader . loadPDF (source .getFile ());
186188 PDFRenderer pdfRenderer = new PDFRenderer (document );
187189 BufferedImage imageBuffer = pdfPageToImageBuffer (index , document , pdfRenderer );
188190 document .close ();
@@ -242,7 +244,7 @@ protected void writeString(String text, List<TextPosition> textPositions) throws
242244 try {
243245 contentStream .showText (text );
244246 } catch (IllegalArgumentException | UnsupportedOperationException e ) {
245- contentStream .setFont (PDType1Font . HELVETICA , fontSize );
247+ contentStream .setFont (new PDType1Font ( Standard14Fonts . FontName . HELVETICA ) , fontSize );
246248 contentStream .showText (text );
247249 }
248250 contentStream .endText ();
0 commit comments