PDF 파일 -Itext를 작성하기위한 프로젝트도 있습니다.
pdfbox 아래에는 두 개의 하위 프로젝트가 있습니다. Fontbox는 PDF 글꼴을 처리하는 Java 클래스 라이브러리입니다.
간단한 예 :
PDFbox-App-1.6.0.jar 패키지를 소개합니다.
코드 사본은 다음과 같습니다.
패키지 PDF;
import java.io.file;
java.net.malformedurlexception import;
import org.apache.pdfbox.pdmodel.pddocument;
import org.apache.pdfbox.util.pdftextStripper;
공개 클래스 StrippdfContent {
public static string getText (파일 파일) 예외 {
부울 정렬 = 거짓;
int startpage = 1;
int endpage = 10;
pddocument document = null;
노력하다{
노력하다{
document = pddocument.load (파일);
} catch (marformedurlexception e) {
}
pdftextStripper 스트리퍼 = 새로운 pdftextStripper ();
스트리퍼 .setsortbyposition (정렬);
stripper.setstartpage (startpage);
스트리퍼 .SetEndPage (엔드 페이지);
Return Stripper.getText (문서);
} catch (예외 e) {
e.printstacktrace ();
반품 "";
} 마지막으로{
if (document! = null) {
document.close ();
}
}
}
public static void main (String [] args) {
파일 파일 = 새 파일 ( "/home/orisun/123.pdf");
노력하다{
문자열 cont = getText (파일);
System.out.println (계속);
} catch (예외 e) {
System.out.println ( "스트립 실패.");
e.printstacktrace ();
}
}
}