Quickly Search Strings inside PDF files
이전 댓글 표시
I have ~25,000 PDF files that I want to classify based on the presence of keywords in their text. I know there's a PDF Toolbox that provides MATLAB with an interface for reading PDF text, but the fact that it comes from Sourceforge makes it difficult to obtain (this is for work) and the reliance on java seems to me like it would make the process very slow -especially for searching so many files. Is there a simpler, faster way to parse these documents if all I want to do is basically strfind on the text to check for keywords?
댓글 수: 7
Stephen23
2016년 4월 11일
Parsing PDFs is not at all trivial. Search this forum for the discussions on parsing PDFs to get an idea of why. In a nutshell PDFs are really a layout standard rather than a text document standard, which is why it is possible to do things like this:
that LaTeX package displays text (e.g. email address) in the correct order, but the characters are stored in the PDF in a random order. Think about that for a minute. And now try think how a PDF parser should be able to "know" the correct character order that you see on the page: any naive file parser will only read random text.
Summary: parsing PDFs is not trivial, and not fast.
The best solution is to avoid using PDFs to store text data, and use a more suitable format (TXT, XML, ODF, etc).
Michael B
2016년 4월 11일
Kirby Fears
2016년 4월 11일
I haven't used this open source PDF Toolbox, but there's nothing wrong with using java libraries in Matlab. It's not generally slower than other approaches unless you find a .mex library for parsing PDFs.
What Stephen is saying is that without a great deal of detailed information about the underlying structure of the PDF files you're not likely to have any success. Ben Litchfield's PDFBox Java library is the only really robust way to do this at present, and even that might not work. I don't think anyone else has a library that can even attempt the task you're looking at doing, let alone doing it quickly.
Stephen's suggestion is that you would probably have better success trying to get your data in a more amenable format than trying to apply another method to the PDF document. Apparently, some people have had success converting to Excel then reading in those values.
Walter Roberson
2016년 4월 11일
편집: Walter Roberson
2018년 4월 13일
"Is there a simpler, faster way"
"if parsing PDFs was trivial I wouldn't be asking the question"
Dear Acme: There are a lot of ways in your catalog to avoid hurting myself when I walk off of cliffs, but they are cumbersome and take a lot of preparation. Is there a simpler faster way I can avoid hurting myself when I do that?
Dear Coyote: Don't look down.
Walter Roberson
2023년 1월 4일
For batch extracting I see the commercial product https://www.qoppa.com/files/pdfstudio/guide/batch-extract-text-from-pdf.htm (which I have never used.)
I also see instructions at https://kenbenoit.net/how-to-batch-convert-pdf-files-to-text/ for a free convertor. As those instructions basically involve preparing a file of names and then running a shell script, then building the file name list inside MATLAB would not be difficult. Running the converter would be simple in MacOS or Linux; in Windows it would take more work.
채택된 답변
추가 답변 (1개)
Sarah Palfreyman
2018년 4월 30일
0 개 추천
댓글 수: 1
Benjamin Ehrlich
2023년 1월 4일
Is there ANY way to effectively speed up textanalytics.internal.pdfparser.extractText?
A single page can take up to 20 seconds... I just want to extract a small section of text.
-Ben
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!