我試圖使用從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類。
我已經在谷歌搜索了這個,但我沒有找到解決方案的運氣。
任何想法?
通常這是核心Java安裝的一部分。你確定你安裝正確嗎? – npinti 2012-02-14 09:30:37
Java的哪個版本/類型實際使用? – 2012-02-14 09:32:31
在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