oracle 如何将 blob 数据类型从数据库显示为 pdf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1673970/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:21:31  来源:igfitidea点击:

How to display blob datatype from database to pdf

oraclejspservletsblob

提问by anand

I am having with displaying an image file stored in a database as BLOB type.... now i want to call that image and display it in a pdf...i am using jsp and servlet for web client... i just need a central idea or crux of how to go about the problem.

我正在将存储在数据库中的图像文件显示为 BLOB 类型......现在我想调用该图像并将其显示在 pdf 中......我正在使用 jsp 和 servlet 作为 Web 客户端......我只需要如何解决问题的中心思想或症结。

Any help will be highly appreciated

任何帮助将不胜感激

Thank you

谢谢

Anand

阿南德

回答by Otávio Décio

You have to stream the bytes back to the browser along with a content-type of application/pdf and choose a method of rendering it (inline or attachment).

您必须将字节与应用程序/pdf 的内容类型一起流回浏览器,并选择一种呈现它的方法(内联或附件)。

For example:

例如:

byte[] content = getByteArray();

try {
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("application/pdf");
response.setHeader("Content-disposition","inline; filename=Example.pdf" );
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
BufferedOutputStream bos = new BufferedOutputStream(outputStream);
bos.write(content);
bos.close();
} catch (Exception e) {
e.printStackTrace();
}

回答by PhiLho

I wonder why you want to do such wrapping, it is just doing things more difficult for the user.

我想知道你为什么要做这样的包装,它只是为用户做更困难的事情。

But well, you want to look at the iText library, I think.

但是,我认为您想查看 iText 库。

回答by Rob

Anand-

阿南德-

The big picture is you need to:

大局是你需要:

  1. Create a PDF object
  2. Grab the image and drop it in to the PDF
  3. Send the PDF object out to the browser
  1. 创建 PDF 对象
  2. 抓取图像并将其放入 PDF
  3. 将 PDF 对象发送到浏览器

Ocdecio's answer tells you how to do the last part. Take the iText library from PhiLho's answer to create the PDF and drop the image in to it. Read up on jle's answer to learn some basics about how to deal with BLOBs in the database; that BLOB is where your image is. Take the blob, turn it in to an image object iText can handle, and roll like that.

Ocdecio 的回答告诉你如何做最后一部分。从 PhiLho 的答案中获取 iText 库以创建 PDF 并将图像放入其中。阅读 jle 的答案以了解有关如何处理数据库中的 BLOB 的一些基础知识;BLOB 是您的图像所在的位置。拿这个 blob,把它变成 iText 可以处理的图像对象,然后像这样滚动。

Good luck!

祝你好运!

回答by jle

Oracle Technology Net has a good article on this topic.

Oracle 技术网有一篇关于这个主题的好文章。

The article uses .Net, but using Java would be very similar.

文章使用 .Net,但使用 Java 会非常相似。