|
20 | 20 | import at.laborg.briss.model.ClusterCollection; |
21 | 21 | import at.laborg.briss.model.ClusterJob; |
22 | 22 | import at.laborg.briss.model.SingleCluster; |
| 23 | +import at.laborg.briss.utils.PDFImageExtractor; |
23 | 24 | import com.itextpdf.text.Rectangle; |
24 | 25 | import com.itextpdf.text.pdf.PdfReader; |
| 26 | + |
25 | 27 | import java.awt.image.BufferedImage; |
26 | 28 | import java.io.File; |
27 | 29 | import java.io.IOException; |
28 | | -import org.jpedal.PdfDecoder; |
29 | | -import org.jpedal.exception.PdfException; |
30 | 30 |
|
31 | 31 | public class ClusterManager { |
32 | 32 |
|
33 | | - public static ClusterJob createClusterJob(File origFile) throws IOException, PdfException { |
| 33 | + public static ClusterJob createClusterJob(File origFile) throws IOException { |
34 | 34 |
|
35 | 35 | PdfReader reader = new PdfReader(origFile.getAbsolutePath()); |
36 | 36 | ClusterJob clusterJob = new ClusterJob(origFile); |
@@ -83,27 +83,19 @@ public ClusterRenderWorker(ClusterJob clusterJob) { |
83 | 83 |
|
84 | 84 | @Override |
85 | 85 | public void run() { |
86 | | - PdfDecoder pdfDecoder = new PdfDecoder(true); |
87 | | - try { |
88 | | - pdfDecoder.openPdfFile(clusterJob.getSource().getAbsolutePath()); |
89 | | - } catch (PdfException e1) { |
90 | | - e1.printStackTrace(); |
91 | | - } |
92 | | - |
93 | | - for (SingleCluster cluster : clusterJob.getClusterCollection().getAsList()) { |
94 | | - for (Integer pageNumber : cluster.getPagesToMerge()) { |
95 | | - try { |
96 | | - BufferedImage renderedPage = pdfDecoder.getPageAsImage(pageNumber); |
97 | | - cluster.getImageData().addImageToPreview(renderedPage); |
98 | | - workerUnitCounter++; |
99 | | - } catch (PdfException e) { |
100 | | - // TODO Auto-generated catch block |
101 | | - e.printStackTrace(); |
102 | | - } |
103 | | - } |
104 | | - } |
105 | | - // now close the reader as it's not used anymore |
106 | | - pdfDecoder.closePdfFile(); |
| 86 | + File source = new File(clusterJob.getSource().getAbsolutePath()); |
| 87 | + |
| 88 | + try (PDFImageExtractor pdfImageExtractor = new PDFImageExtractor(source, null)) { |
| 89 | + for (SingleCluster cluster : clusterJob.getClusterCollection().getAsList()) { |
| 90 | + for (Integer pageNumber : cluster.getPagesToMerge()) { |
| 91 | + BufferedImage renderedPage = pdfImageExtractor.extractImage(pageNumber - 1); |
| 92 | + cluster.getImageData().addImageToPreview(renderedPage); |
| 93 | + workerUnitCounter++; |
| 94 | + } |
| 95 | + } |
| 96 | + } catch (Exception e) { |
| 97 | + e.printStackTrace(); |
| 98 | + } |
107 | 99 | } |
108 | 100 | } |
109 | 101 | } |
0 commit comments