Why are certain pdfbox functions not working in MATLAB?

13 次查看(过去 30 天)
I want to get the captions for those images so that I can save the images with relevant names. Someone on stack exchange said this could be done by getting the text and image positions/coordinates on the page and comparing them.
I am able to use the text stripper to get text like this:
file = 'blah.pdf';
jFile = java.io.File(file);
document = org.apache.pdfbox.pdmodel.PDDocument.load(jFile);
reader = org.apache.pdfbox.text.PDFTextStripper();
reader.setStartPage(1);
reader.setEndPage(1);
reader.setSortByPosition(true);
reader.getText(document);
This works correctly and returns all the text in the page.
However, if I want to get the text position and then use the getX() and getY() methods described in the pdfbox documentation, MATLAB doesn't seem to recognize it. https://javadoc.io/doc/org.apache.pdfbox/pdfbox/latest/index.html (I'm using pdfbox 3.0.1)
position = org.apache.pdfbox.text.TextPosition();
This returns:
No constructor 'org.apache.pdfbox.text.TextPosition' with matching signature found.
I have tried all kinds of variations, and what I've found is that some pdfbox functions work just fine, while others seem to not exist.
I have also tried downloading the .jar files directly and importing them to the path, thinking that maybe the pdfbox shipped with MATLAB didn't have the right functions:
javaaddpath('path to pdfbox .jar files');
import org.apache.pdfbox.*
I've also tried the "clear java" beforehand, which did nothing.
What is so weird is that the PDFTextStripper and TextPosition classes are in the same pdfbox.text package, and one works, but the other doesn't.
Can someone please tell me why not all pdfbox functions work in MATLAB and how to fix it?
  2 个评论
Paul Kujawa
Paul Kujawa 2024-1-27
Have you verified that MATLAB is really using the latest version of pdfbox?
javaMethod('getVersion','org.apache.pdfbox.util.Version')

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by