如何使用WEF-INF \ image文件夹中的URL加载图像以写入PDF文档

时间:2014-09-23 15:19:41

标签: spring-mvc itext

如何获取图像URL并用于在PDF文档中编写。 ClassPathResource classPathResource = new ClassPathResource(" Image.png");

1 个答案:

答案 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");
相关问题