使用itext在浏览器中显示pdf [英] display pdf in browser using itext

查看:392
本文介绍了使用itext在浏览器中显示pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pdfstamper修改了一个带有itext的pdf。我的应用程序现在创建并保存一个新的pdf文件。我想直接在浏览器中播放pdf。这里是我的实际代码

i have modify a pdf with itext using pdfstamper. my application now create and save a new pdf file. i want to dipslay the pdf directly in the browser. Here my actual code

public static void test07(){
    try{
    PdfReader reader = new PdfReader("c:\\temp\\file.pdf");
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("c:\\temp\\new.pdf"));
        AcroFields form = stamper.getAcroFields();

        //fill the fields

        stamper.close();
        reader.close();
    } catch (Exception e){
        e.printStackTrace();
    }

}

问题是:我应该如何修改此代码和servlet以在浏览器中显示pdf文件?
我已经尝试过ByteArrayOutputStream和response.getOutputStream但没有尝试。

The question is: How should I modify this code and the servlet to display the pdf file in the browser? I have already tried with ByteArrayOutputStream and response.getOutputStream but nothing.

推荐答案

你很幸运!书中的 iText in Action 包含一章,介绍如何完全按照您的需要做。它非常简单:在响应上设置正确的标题,然后流到servlet的输出流。

You're in luck! The book iText in Action contains a chapter that describes how to do exactly what you need. It's fairly straightforward: set the right headers on your response, and stream to the servlet's output stream.

这是链接: http://itextpdf.com/examples/iia.php?id=173

这篇关于使用itext在浏览器中显示pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆