我想使用 iText 和 Servlet injsp 生成PDF,这将显示存储在 mysql 数据库中的记录斑点(图像)即可。但它没有被展示。
答案 0 :(得分:2)
如果您想将图像从mysql插入pdf中View this View this
这给了你一个想法......
public void createPDF(){
Document d = new Document (PageSize.A4);
try {
PdfWriter.getInstance(d, new FileOutputStream("sample.pdf"));
d.open ();
d.addCreator("Sample Demo.java");
d.addAuthor("Sundar");
d.addTitle("First PDF By Sundar");
//this is where you have to do your query to fetch image as BLOB from DB
//Blob imageBlob = resultSet.getBlob(yourBlobColumnIndex);
//byte[] imageBytes = imageBlob.getBytes(1, (int) imageBlob.length());
Image image = Image.getInstance(imageBytes);
image.scaleAbsolute(300,300);
d.add(image);
d.close ();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("******** PDF Created ***************");
}