come Theodore detto che si può estrarre il testo da un PDF e come Chris rilevare
fintanto che è in realtà il testo (senza contorni o bitmap)
miglior cosa da fare è acquistare Il libro di Bruno Lowagie Itext in action. Nella seconda edizione il capitolo 15 tratta l'estrazione del testo.
Ma si può guardare il suo sito per gli esempi. http://itextpdf.com/examples/iia.php?id=279
E puoi analizzarlo per creare un semplice file txt. Ecco un esempio di codice:
/*
* This class is part of the book "iText in Action - 2nd Edition"
* written by Bruno Lowagie (ISBN: 9781935182610)
* For more info, go to: http://itextpdf.com/examples/
* This example only works with the AGPL version of iText.
*/
package part4.chapter15;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy;
import com.itextpdf.text.pdf.parser.TextExtractionStrategy;
public class ExtractPageContent {
/** The original PDF that will be parsed. */
public static final String PREFACE = "resources/pdfs/preface.pdf";
/** The resulting text file. */
public static final String RESULT = "results/part4/chapter15/preface.txt";
/**
* Parses a PDF to a plain text file.
* @param pdf the original PDF
* @param txt the resulting text
* @throws IOException
*/
public void parsePdf(String pdf, String txt) throws IOException {
PdfReader reader = new PdfReader(pdf);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
PrintWriter out = new PrintWriter(new FileOutputStream(txt));
TextExtractionStrategy strategy;
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
strategy = parser.processContent(i, new SimpleTextExtractionStrategy());
out.println(strategy.getResultantText());
}
reader.close();
out.flush();
out.close();
}
/**
* Main method.
* @param args no arguments needed
* @throws IOException
*/
public static void main(String[] args) throws IOException {
new ExtractPageContent().parsePdf(PREFACE, RESULT);
}
}
Avviso della licenza
Questo esempio funziona solo con la versione AGPL di iText.
Se guardi gli altri esempi mostrerà come tralasciare parti del testo o come estrarre parti del pdf.
Spero che aiuti.
fonte
2012-07-03 19:00:59
Non sono completamente chiaro su quello che stai facendo. Leggere il testo ed estrarre il testo sono generalmente la stessa cosa. iText non salverà il testo in un file, ma una volta che avrai il testo dovresti riuscire a farlo abbastanza facilmente. iText fa un ottimo lavoro di estrazione del testo purché sia effettivamente testo (non contorni o bitmap). Durante la ricerca di questo sito cerca anche 'iTextSharp', che è la porta .Net di iText. Ha più domande/risposte e il codice è quasi completamente lo stesso per C#. –