I have this kind of solution in my Spring application:
http://www.java2s.com/Code/Java/PDF-RTF/AddingPNGimagetoPdfdocument.htm
Anyhow my problem is that my picture is in different folder like WEB-INF/layout/开发者_StackOverflowpicture.gif. I don't get it to work. Is there any disrictions, maybe?
Move your picture to the classpath as a resource, so then you can load it to iText easily. In order to do that you should copy the image file to the directory where the classes are, so the image is packed into the JAR or alternatively is in /WEB-INF/classes directory if this is JAva webapp (war).
Factory method of com.lowagie.itext.Image
takes java.net.URL
as argument, so you do this:
URL imageUrl = getClass().getResource("/your/image/package/image.png");
Image image = Image.getInstance(imageUrl);
This answer assumes that you try to access the images from a web browser directly.
Images that can directly accessed by an browser have to be located outside of the WEB-INF directory.
For example in a maven project
-project/main/src
-webapp
-images <- in the same parent directory like META-INF and WEB-INF
-META-INF
-WEB-INF
精彩评论