How to get image URL and used to write in a PDF document. ClassPathResource classPathResource = new ClassPathResource("Image.png");
Asked
Active
Viewed 573 times
0
-
possible duplicate of [Preferred way of loading resources in Java](http://stackoverflow.com/questions/3861989/preferred-way-of-loading-resources-in-java) – Bruno Lowagie Sep 23 '14 at 15:50
1 Answers
0
i have added the image logo like this in my pdf file
String imgPath = "/img/Kavi025.jpg";
String absoluteImgPath = getServletContext().getRealPath(imgPath);
System.out.println(absoluteImgPath);
Document document= new Document();
PdfWriter writer= PdfWriter.getInstance(document, new FileOutputStream("d:\\Kavi.pdf"));
document.open();
Image img = Image.getInstance(absoluteImgPath);
img.setAbsolutePosition(100, 200); // x-axis and y-axis position
writer.getDirectContent().addImage(img);
document.close();
System.out.println("end of method");

kavi temre
- 1,321
- 2
- 14
- 21