1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
public static List<byte[]> transferPdfToPictures(InputStream inputStream) {
try (PDDocument document = PDDocument.load(inputStream)) {
List<byte[]> result = new ArrayList<>();
PDFRenderer renderer = new PDFRenderer(document);
for (int i = 0; i < document.getNumberOfPages(); ++i) {
BufferedImage bufferedImage = renderer.renderImageWithDPI(i, DPI);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, IMG_TYPE, out);
result.add(out.toByteArray());
}
return result;
} catch (Exception e) {
e.printStackTrace();
throw new BusinessException(PDF_TRANSFER_WRONG);
}
}
|