【发布时间】:2015-12-14 20:54:39
【问题描述】:
我有这几行代码,我试图用 Apache pdfBox 来读取 pdf 文件。
private void readPdf(){
try {
File PDF_Path = new File("/home/olyjosh/Downloads/my project.pdf");
PDDocument inputPDF = PDDocument.load(PDF_Path);
List<PDPage> allPages = inputPDF.getDocumentCatalog().getAllPages();
PDPage testPage = (PDPage) allPages.get(5);
System.out.println("Number of pages "+allPages.size());
PDFPagePanel pdfPanel = new PDFPagePanel();
jPanel1.add(pdfPanel);
pdfPanel.setPage(testPage);
// this.revalidate();
inputPDF.close();
} catch (IOException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
我希望这个 pdf 显示在 jPanel 之类的 swing 组件上,但这只会显示具有 pdf 文件预期内容的面板。但是,我能够使用
将 pdf 显示为图像convertToImage = testPage.convertToImage();
请问,我该如何解决这个问题,或者我做错了什么。
【问题讨论】: