필터 지우기
필터 지우기

Why are certain pdfbox functions not working in MATLAB?

조회 수: 13 (최근 30일)
Ginny
Ginny 2023년 12월 20일
댓글: Paul Kujawa 2024년 1월 27일
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
Yudi Yan
Yudi Yan 2023년 12월 22일
I also have the same question
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