我有這些代碼行,我試圖用來閱讀PDF文件與Apache的PDFBox。用Apache閱讀PDF 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);
}
}
我想要顯示像JPanel的Swing組件本PDF但這隻會與PDF文件的預期的內容顯示面板。但是,我能夠顯示PDF爲圖像使用
convertToImage = testPage.convertToImage();
請問,我該如何解決這個問題或我做錯了什麼。
不知道,如果你看到它,但我併發布一些代碼郵件列表與另一個類似的問題相關,也許這有助於:https://mail-archives.apache.org/mod_mbox/pdfbox-users/201512.mbox/%3C567F0B43.7040301%40t-online.de%3E –