So, I had the same problem, I wanted to add the image to pdf, but through a relative path, so when I created the executable program, it would work on any computer, even if it was or not. / p>
I found a way to add an image as a resource of your application. You need to put the image in the src directory or in the directory where you call it, and then you can use the following code:
Image image = Image.getInstance(yourClassName.class.getResource("/yourImageName")));
If you place the image inside a folder, then obviously you will need to add the path through the folder name ("folderName / yourImageName"). Hope this helps!
source share