how to convert pdf files to text files to search easily in matlab ?

26 ビュー (過去 30 日間)
mohammad
mohammad 2014 年 7 月 28 日
コメント済み: luis Armando Solis 2022 年 8 月 17 日
i want to search about text easily in pdf files , any way to search easily in pdf files using matlab ?

回答 (1 件)

Arun Mathew Iype
Arun Mathew Iype 2014 年 7 月 29 日
You may be able to do this using the following article from File Exchange by Dimitri Shvorob http://www.mathworks.com/matlabcentral/fileexchange/19798-extract-text-from-a-pdf-document
The following are the steps mentioned in the submission.
  1. Download PDFBox library from http://sourceforge.net/projects/pdfbox/
  2. Download FontBox library from http://sourceforge.net/projects/fontbox/
  3. Modify the file paths in pdfParseDemo.m
  4. Enable cell mode and step through pdfParseDemo.m.Please note that the code does not handle files that have 'Content Copying' permission protected by a password.
The following is a modified version of the code from the submission containing just the parts relevant for you. Please change the file paths as required and download the jars from the link above.
clear java
javaaddpath('L:\NewJars\PDFBox-0.7.3\lib\PDFBox-0.7.3.jar')
pdfdoc = org.pdfbox.pdmodel.PDDocument;
reader = org.pdfbox.util.PDFTextStripper;
pdfdoc = pdfdoc.load('L:\NewJars\Sample 1.pdf');
pdfdoc.isEncrypted
%%text, with planty of padding
pdfstr = reader.getText(pdfdoc) %#ok
class(pdfstr)
pdfstr = char(pdfstr) %#ok
class(pdfstr)
%%text 'unpadded'
pdfstr = deblank(pdfstr) %#ok
%%will get an error here..
pdfdoc = pdfdoc.load('L:\NewJars\Sample 1.pdf');
pdfdoc.isEncrypted
pdfstr = reader.getText(pdfdoc) %#ok
%%but press forward..
pdfdoc.getDocument().close;
The variable “pdfstr” stores the text in the PDF document as a “java.lang.string. “ object. You can search for words in this string using the below code. You can check for other functionality available fo string using the “tab” auto completion.
>> pdfstr.indexOf('MathWorks')
ans =
11
You can also convert to a char array and use as needed
>> result = pdfstr.toCharArray();
  2 件のコメント
mohammad
mohammad 2014 年 7 月 31 日
編集済み: mohammad 2014 年 7 月 31 日
what about the pdf files converted from .dwg by autocad to .pdf ? is treated as image or not ?
luis Armando Solis
luis Armando Solis 2022 年 8 月 17 日
Well done man,Thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by