これは私の初めてのMavenリポジトリです。次のようにPDFboxリポジトリを使用したコード内の未定義のコンストラクタ
私のコードは次のとおりです。基本的に
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.io.RandomAccessRead;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
public class application {
public static void main(String args[]) {
PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
File file = new File("/Users/Desktop/Corporate reports/previous 'fetch' items/ARM2009.pdf");
try {
PDFParser parser = new PDFParser(new FileInputStream(file));
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
pdfStripper.setStartPage(1);
pdfStripper.setEndPage(5);
String parsedText = pdfStripper.getText(pdDoc);
System.out.println(parsedText);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Failed to parse : " +file);
}
}
}
、それは言う19行目:
PDFParser parser = new PDFParser(new FileInputStream(file));
は、コンパイル時にエラーを与えています。言っている:
コンストラクタPDFParser(FileInputStreamのは)私はこれを処理する方法がわからないです 未定義
です。私のIDEは引数をRandomAccessReadにキャストすることを推奨していますが、これは実行時に別のエラーで終了します。
ありがとうございます。
ここにmavenが入っていますか?それは明確ではありません – borowis
"try"の後の5行の代わりに、この 'pdDoc = PDDocument.load(file)'を実行してから、textStripperを構築してください。 –