Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以PDF格式显示图像,使用JSP和iText从MySql数据库检索图像_Mysql_Jsp_Pdf_Itext - Fatal编程技术网

如何以PDF格式显示图像,使用JSP和iText从MySql数据库检索图像

如何以PDF格式显示图像,使用JSP和iText从MySql数据库检索图像,mysql,jsp,pdf,itext,Mysql,Jsp,Pdf,Itext,我想用iText和Servlet injsp生成一个PDF,它将显示存储在mysql数据库中Blob(Image)类型的记录。但是它不会被显示。如果您想从mysql将图像插入pdf 这给了你一个想法 public void createPDF(){ Document d = new Document (PageSize.A4); try { PdfWriter.getInstance(d, new FileOutputStream("sample.pdf")); d.open (); d.ad

我想用iTextServlet injsp生成一个PDF,它将显示存储在mysql数据库中Blob(Image)类型的记录。但是它不会被显示。

如果您想从mysql将图像插入pdf

这给了你一个想法

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 ***************");

}

Sundar,你给我发的链接很好,但是它没有显示从mysql数据库检索图像的方法,它只是图像类Sundar的一个例子,非常感谢你,你帮了我很多。。事实上,问题出在数据类型上,数据库包含longblob,但我使用的是blob,我认为这是一个很大的问题。当我更改具有blob类型的表的数据库时,它工作了。你能给我另一个建议吗,如何使用longblob或mediumblob??请……:)Sundar,请帮助我回答我的另一个问题,即,此代码适用于Blob类型,但如果我们使用了mediumblob或longblob,该怎么办。这段代码在那种情况下不起作用。查看这条线索,它的作用就像一个符咒。在导入“图像”时,我们需要小心。必须与com.itextpdf.text.Image关联。不要从sql或任何其他类导入图像。