There is also a project for creating a PDF file----iText.
PDFBox has two subprojects below: Fontbox is a Java class library that handles PDF fonts; Jempbox is a Java class library that handles XMP metadata.
A simple example:
To introduce Pdfbox-app-1.6.0.jar this package.
Copy Code code as follows:
Package PDF;
Import Java.io.File;
Import java.net.MalformedURLException;
Import org.apache.pdfbox.pdmodel.PDDocument;
Import Org.apache.pdfbox.util.PDFTextStripper;
public class Strippdfcontent {
public static String getText (file file) throws exception{
Boolean sort=false;
int startpage=1;
int endpage=10;
PDDocument Document=null;
try{
try{
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 (Exception e) {
E.printstacktrace ();
Return "";
}finally{
if (document!=null) {
Document.close ();
}
}
}
public static void Main (string[] args) {
File File=new file ("/home/orisun/123.pdf");
try{
String cont=gettext (file);
SYSTEM.OUT.PRINTLN (cont);
}catch (Exception e) {
System.out.println ("Strip failed.");
E.printstacktrace ();
}
}
}