使用PDFBox 2.0.4将页面提取为图像,我的结果页面包含多个"黑洞",如下面的屏幕所示:
这种情况仅发生在这个PDF和其他几个:http://www.filedropper.com/selection_3
这是一个简单的代码(使用JavaFX)来重现问题(下载PDF后更改文件路径):
public class PDFExtractionTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FileInputStream inputStream = new FileInputStream(new File("C:\\Users\\John\\Desktop\\selection.pdf"));
PDDocument document = PDDocument.load(inputStream);
PDFRenderer pdfRenderer = new PDFRenderer(document);
BufferedImage bufferedImage = pdfRenderer.renderImage(1);
Image fxImage = SwingFXUtils.toFXImage(bufferedImage, null);
BorderPane borderPane = new BorderPane();
ImageView imageView = new ImageView(fxImage);
borderPane.setCenter(imageView);
primaryStage.setScene(new Scene(borderPane, 1024, 768));
primaryStage.show();
}
public static void main(String[] args) throws FileNotFoundException {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的依赖项: