2012-02-14 128 views
1

我試圖使用從jpedal的PDF庫,用在這裏找到的代碼片段:http://www.jpedal.org/simple_image_example.phpjavax.swing中缺少

/**instance of PdfDecoder to convert PDF into image*/ 
PdfDecoder decode_pdf = new PdfDecoder(true); 

/**set mappings for non-embedded fonts to use*/ 
FontMappings.setFontReplacements(); 

/**open the PDF file - can also be a URL or a byte array*/ 
try { 
     decode_pdf.openPdfFile("C:/myPDF.pdf"); //file 
     //decode_pdf.openPdfFile("C:/myPDF.pdf", "password"); //encrypted file 
     //decode_pdf.openPdfArray(bytes); //bytes is byte[] array with PDF 
     //decode_pdf.openPdfFileFromURL("http://www.mysite.com/myPDF.pdf",false); 

     /**get page 1 as an image*/ 
     //page range if you want to extract all pages with a loop 
     //int start = 1, end = decode_pdf.getPageCount(); 
     BufferedImage img=decode_pdf.getPageAsImage(1); 

    /**close the pdf file*/ 
    decode_pdf.closePdfFile(); 

} catch (PdfException e) { 
    e.printStackTrace(); 
} 

但在這條線:

decode_pdf.openPdfFile("C:/myPDF.pdf"); //file 

的Eclipse trows錯誤:

The type javax.swing.JPanel cannot be resolved. It is indirectly referenced from required .class files

看來,如果我錯過的javax.swing *

Intellisence確實爲我提供了其他的javax。*選項,但不支持swing類。

我已經在谷歌搜索了這個,但我沒有找到解決方案的運氣。

任何想法?

+0

通常這是核心Java安裝的一部分。你確定你安裝正確嗎? – npinti 2012-02-14 09:30:37

+0

Java的哪個版本/類型實際使用? – 2012-02-14 09:32:31

+0

在cmd中使用「java -version」命令我得到:Java版本「1.7.0_02」 Java™SE運行時環境(內部版本1.7.0_02-b13) Java HotSpot™64位服務器虛擬機22.0-b10,混合模式) – Pieter888 2012-02-14 09:39:07

回答

-1

我懷疑路徑不解決,試試這個

decode_pdf.openPdfFile("C:\\myPDF.pdf"); 
+0

這並沒有解決問題,但無論如何感謝。 – Pieter888 2012-02-14 09:36:30

+0

請參閱我在使用代碼片段中註釋的其他方法時也會遇到錯誤(OpenPdfArray,OpenPdfFileFromUrl) – Pieter888 2012-02-14 09:41:53