javaObject and javax.imageio.ImageIO in rt.jar NoSuchMethodException

I need help to export pdf java image to file.

I am following java examples to use pdfbox to extract text and image in pdf. There are many java code examples available. For example:
% How to read and write Images in java using ImageIO Utility
% Convert PDF files to images with PDFBox - Stack Overflow

There is a 2021 matlab central communication basically did the same as the examples above in matlab. So, I assume that the image output task is possible to do in matlab.

In Octave 6.2.0 and 6.3.0, I have no issue in reading the text from pdf with pdfbox.2.0.21 and 2.0.24. The text to file output also went smoothly. But I have an issue in writing any image. Most of the java examples use javax.imageio.ImageIO to export image to file. For example, ImageIO.write(image, “JPEG”, new File(“C:/PdfBox_Examples/myimage.jpg”));

javax.imageio.ImageIO resides in jre or jdk rt.jar, which I verified with 7z. The rt.jar version I have is statically available. (same outcome as below when dynamically)

javaclasspath
STATIC JAVA PATH

  C:\Program Files\Java\jre1.8.0_281\lib\rt.jar

When I invoked javax.imageio.ImageIO class with javaObject, I got into this error state that I cannot resolve:

ImageIO=javaObject(“javax.imageio.ImageIO”);
error: [java] java.lang.NoSuchMethodException: javax.imageio.ImageIO

If this works, I can use the syntax ImageIO.write to export. The code to create above error is two-line:

javaaddpath(‘C:\Program Files\Java\jre1.8.0_281\lib\rt.jar’);
ImageIO=javaObject(“javax.imageio.ImageIO”);

I need help to export pdf java image to file. Thanks.

OS: windows 10 Pro Version 21H1 Build 19043.1320
Octave: 6.2.0 and 6.3.0
Octave Installer: exe
jre: pls see above. (
pdfbox: Apache PDFBox | Download
javax.imageio.ImageIO src: maybe is Source for javax.imageio.ImageIO (GNU Classpath 0.95 Documentation)


Thank you for writing us about your problem with using :octave: GNU Octave. To help us help you, please answer the following questions, if applicable.

Problem description

  • Choose a meaningful title.
  • How can I replicate the Octave problem?
  • I there any code that causes the error? Please give a good example.
  • What did I expect to happen and what did happen?

My system

  • OS: e.g. Windows 10 (version 2004) or Ubuntu 20.04
  • Octave version: e.g. Version 6.1.0
  • Installation method: e.g. Downloaded and installed “octave-6.1.0-w64-installer.exe” from Download

I am replying to myself. With this item open for more than 4-5 days and no reply, I have to enter java domain to find out more. I am not good in java at all.

Specific to the issue I had, there are many valid java packages with three features in a class:

public class
private constructor
public static method

public class declaration makes the class visible outside of package. So the class can be imported, like import xxx.yyy.zzz Octave does not have this functionality,

private constructor prevents the creation of an object outside of the package. This makes A=zzz not possible to do outside the package. Octave javaObject(‘xxx.yyy.zzz’) should fail accordingly. This is my original post.

public static method facilitates the direct reference to a method even a class object is not available, i.e., import xxx.yyy.zzz; A=zzz.mmm. Octave javaMethod is defined as javaMethod(‘method’, ‘Object’), i.e., javaMethod(mmm’,‘xxx.yyy.zzz’). This should fail due to the java object is unavailable when the xxx.yyy.zzz constructor is private.

Therefore the bottom line is that Octave is not supporting the public static method feature with a private constructor.

For a small project, a change of the constructor from private to public serves as a workaround. For any projects with many dependencies (libraries), there is no feasible solution at present.

In general, it appears to me the creation of a java object is always needed in Octave to interact with java. However, there are java classes, by definition, do not have associated object. Those classes cannot be used in Octave. enum is one of them and widely used.

Your comments are always welcomed.

I am replying to myself again. I found a code error of mine in javaMethod call, which leaded me to the above false conclusion. A properly constructed javaMethod can bypass the private class constructor. This is a significantly better situation than I originally thought. Sorry for the mistake.

1 Like