PDFファイルを作成するプロジェクト-Itextもあります。
PDFBOXの下には2つのサブプロジェクトがあります。Fontboxは、PDFフォントを処理するJavaクラスライブラリです。
簡単な例:
PDFBOX-APP-1.6.0.JARパッケージを紹介します。
コードコピーは次のとおりです。
パッケージPDF;
java.io.fileをインポートします。
java.net.malformedurlexceptionをインポートします。
Import org.apache.pdfbox.pdmodel.pddocument;
import org.apache.pdfbox.util.pdftextStripper;
パブリッククラスstrippdfcontent {
public static string getText(ファイルファイル)スロー例外{
boolean sort = false;
int startpage = 1;
int endpage = 10;
pddocument document = null;
試す{
試す{
document = pddocument.load(file);
} catch(malformedurlexception e){
}
pdftextStripper stripper = new pdftextStripper();
stripper.setSortByposition(sort);
stripper.setStartPage(startPage);
stripper.setEndpage(endpage);
return stripper.getText(document);
} catch(例外e){
e.printstacktrace();
戻る "";
} ついに{
if(document!= null){
document.close();
}
}
}
public static void main(string [] args){
file file = new file( "/home/orisun/123.pdf");
試す{
文字列cont = getText(file);
System.out.println(cont);
} catch(例外e){
System.out.println( "ストリップFailed。");
e.printstacktrace();
}
}
}