将ASP.NET生成的pdf byte []显示到网页而不保存文件 [英] Display ASP.NET generated pdf byte[] to web page without saving the file

查看:159
本文介绍了将ASP.NET生成的pdf byte []显示到网页而不保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iTextSharp生成pdf。我可以从PDF字节[]中保存PDF文件。

I'm using iTextSharp for generating a pdf. I can save the PDF file from the PDF byte[].

byte[] outputPDF = cnt.CreateBreakPDF();
File.WriteAllBytes(pdfOutPutPath, outputPDF);

显示输出的最佳方式是什么 byte [] 到网页?

What is the best way to display the output byte[] to a web page?

我想在页面中的div中显示PDF。不是PDF作为完整的回复。

I want to show the PDF inside a div in my page. Not the PDF as a full response.

我见过MVC的答案,但我正在使用ASP.NET Web Application。

I've seen answers for MVC, but I'm using ASP.NET Web Application.

有没有比使用HTTP处理程序更好的方法呢?我不想发送创建PDF作为查询字符串的所有细节。

Is there a better way than using HTTP handlers to do so? I don't want to send all the details for creating PDF as query string.

推荐答案

我试过这个在jsFiddle 中,它在Chrome& FF,还需要检查其他浏览器。

I tried this in jsFiddle, and it works well in Chrome & FF, need to check on other browsers as well.

byte [] 转换为 Base64 使用,

string base64PDF = System.Convert.ToBase64String(outputPDF, 0, outputPDF.Length);

我所要做的就是指定 MIME类型作为数据:application / pdf; base64,在源代码中并提供 Base64 版本的 PDF

All I had to do is specify the MIME type as data:application/pdf;base64, in the source and give the Base64 version of the PDF.

<object data="data:application/pdf;base64, JVBERi0xLjQKJeLjz9MKMyA..." type="application/pdf" width="160px">
    <embed src="data:application/pdf;base64, JVBERi0xLjQKJeLjz9MKMyA..." type="application/pdf" />
</object>

我无法通过附加<$ c $隐藏出现在FF中的顶部工具栏C>#工具栏= 0&安培; navpanes = 0&安培;状态栏= 0 。

IE8需要显示保存的pdf文件。

IE8 needs a saved pdf file to be displayed.

这篇关于将ASP.NET生成的pdf byte []显示到网页而不保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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