Salve a tutti, sto cercando di leggere un file pdf usando la libreria di pdfbox, ho aggiunto al mio progetto il file jar: pdfbox-1.6.0.jar
Il codice del mio progetto è il seguente:
b[table.getSelectedRow()].Percorso = percorso del pdf da aprirecodice:public void readerPdf(Book[] b, int selectedRow) { File PDF_Path = new File(b[table.getSelectedRow()].Percorso); PDDocument inputPDF = null; try { inputPDF = PDDocument.load(PDF_Path); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<PDPage> allPages = inputPDF.getDocumentCatalog().getAllPages(); PDPage testPage = (PDPage)allPages.get(0); JFrame testFrame = new JFrame(); testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); PDFPagePanel pdfPanel; try { pdfPanel = new PDFPagePanel(); pdfPanel.setPage(testPage); testFrame.add(pdfPanel); testFrame.setBounds(40, 40, pdfPanel.getWidth(), pdfPanel.getHeight()); testFrame.setVisible(true); inputPDF.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Non ho errori in compilazione, ma in esecuzione mi da questo tipo di errore:
"Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.pdfbox.pdfparser.BaseParser.<clinit>(Ba seParser.java:58)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocume nt.java:1068)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocume nt.java:1036)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocume nt.java:1007)
at BookReader.readerPdf(BookReader.java:102)
at lettura_Panel$1.mouseClicked(lettura_Panel.java:57 )"
Aiutooooo![]()


Rispondi quotando