【发布时间】:2021-09-19 12:41:16
【问题描述】:
我尝试使用我的 JavaFX (v16) 应用程序将 PDF 文件转换为 PNG 图像。
关注代码
import net.sourceforge.tess4j.util.PdfBoxUtilities;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.ImageType;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.apache.pdfbox.tools.imageio.ImageIOUtil;
public static void convertPdf2Png(File inputPdfFile) throws IOException {
Path path = Files.createTempDirectory("tessimages-");
File imageDir = path.toFile();
PDDocument document = null;
try {
document = PDDocument.load(inputPdfFile);
PDFRenderer pdfRenderer = new PDFRenderer(document);
for (int page = 0; page < document.getNumberOfPages(); ++page) {
BufferedImage bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.GRAY);
// suffix in filename will be used as the file format
String filename = String.format("workingimage%04d.png", page + 1);
BufferedImage bi = ImageIO.read(new File(filename));
ImageIOUtil.writeImage(bim, new File(imageDir, filename).getAbsolutePath(), 300);
}
} catch (IOException ioe) {
System.err.println("Error:" + ioe);
} finally {
if (imageDir.list().length == 0) {
imageDir.delete();
}
if (document != null) {
try {
document.close();
} catch (Exception e) {
}
}
}
}
我收到跟随错误
Caused by: java.lang.IllegalAccessError: Class de/office/mysoftware/KostenrechnungController(de.mysoftware.software) cannot be based on class org/apache/pdfbox/pdmodel/PDDocument(unnamed module 0x0000000600D391F0) because module unnamed module 0x0000000600D391F0 von Modul de.mysoftware.software cannot be read
我该如何纠正这个问题?
【问题讨论】:
标签: java javafx pdfbox pdfrenderer