Filter löschen
Filter löschen

Why are certain pdfbox functions not working in MATLAB?

13 Ansichten (letzte 30 Tage)
Ginny
Ginny am 20 Dez. 2023
Kommentiert: Paul Kujawa am 27 Jan. 2024
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 Kommentare
Yudi Yan
Yudi Yan am 22 Dez. 2023
I also have the same question
Paul Kujawa
Paul Kujawa am 27 Jan. 2024
Have you verified that MATLAB is really using the latest version of pdfbox?
javaMethod('getVersion','org.apache.pdfbox.util.Version')

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Data Import and Export finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by