sexta-feira, 7 de agosto de 2009

PDFBOX



maven central repo
http://repo1.maven.org/maven2/


pdf incubator
http://repo1.maven.org/maven2/org/apache/pdfbox/jempbox/0.8.0-incubating/


apache svn
http://svn.apache.org/viewvc/incubator/pdfbox/trunk/



Exemplo de código:
==================

public static void main(String[] args) throws IOException {

boolean sort = false;
int startPage = 1;
int endPage = Integer.MAX_VALUE;

String nomeArquivo = "/arquivo.pdf";

File arquivo = new File(nomeArquivo);

URL url = arquivo.toURI().toURL();

PDDocument document = PDDocument.load(url);
String fileName = url.getFile();
String textFile = null;
if (textFile == null && fileName.length() > 4)

{
File outputFile = new File(fileName.substring(0,
fileName.length() - 4)
+ ".txt");
textFile = outputFile.getAbsolutePath();
}

OutputStreamWriter output = new OutputStreamWriter(
new FileOutputStream(textFile));

PDFTextStripper stripper = new PDFTextStripper();

stripper.setSortByPosition(sort);
stripper.setStartPage(startPage);
stripper.setEndPage(endPage);
stripper.writeText(document, output);

{
if (output != null) {
output.close();
}
if (document != null) {
document.close();
}
}

}

1 comentários:

Antônio Carlos disse...

Lembrando que se deve colocar no buildPath o .jar do fontbox e pdfbox