JavaFX转换pdf文件到png文件与PDFBox



我尝试用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

我如何纠正这个?

module-info.java中添加以下内容后,我已经解决了我的问题:

requires lept4j;
requires org.apache.pdfbox;

相关内容

  • 没有找到相关文章

最新更新