Reputation: 1106
I have problem to get an image from another package of my Eclipse project! I saw this post here My code is this CreateTableOnPDF.java:
288 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
289 InputStream input = classLoader.getResourceAsStream("images/sun.png");
290 PDJpeg img = new PDJpeg(doc, input);
I getting this exception:
Exception in thread "main" java.lang.IllegalStateException:
at org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg.setPropertiesFromAWT(PDJpeg.java:132)
at org.apache.pdfbox.pdmodel.graphics.xobject.PDJpeg.<init>(PDJpeg.java:113)
at MainClasses.CreateTableOnPDF.main(CreateTableOnPDF.java:290)
I don't know what I am doing wrong? Maybe is the a lot hour a have spend already infront of my monitor.
Here is my project structure:
Thanks for your attention and time!
Upvotes: 2
Views: 932
Reputation: 677
Please check the API docs, you should put JPEG data, not PNG data.
public PDJpeg(PDDocument doc, InputStream is) throws IOException
Parameters:
doc
- The document to create the image as part of.is
- The stream that contains the JPEG data.Throws:
IOException
- If there is an error reading the JPEG data.Upvotes: 5
Reputation: 661
Are you getting input
as null
? If so try the path as "../images/sun.png"
Upvotes: 0