如何获取图像URL并用于在PDF文档中编写。 ClassPathResource classPathResource = new ClassPathResource(" Image.png");
答案 0 :(得分:0)
我在我的pdf文件中添加了这样的图像标识
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");