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:
Lembrando que se deve colocar no buildPath o .jar do fontbox e pdfbox
Postar um comentário