的window.open与PDF流,而不是PDF的位置 [英] Window.Open with PDF stream instead of PDF location

查看:2386
本文介绍了的window.open与PDF流,而不是PDF的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据问题 href="http://stackoverflow.com/q/20401006/1366033">打开PDF,它看起来像我可以使用JavaScript来打开一个新的用PDF文件有以下code窗口:

的window.open('MyPDF.pdf,_blank);

我想这样做,从服务器回程通过添加文件名的字节数组,而不是作为的 的window.open

目前,我回到PDF文件如这样

Response.Clear(); Response.ContentType =应用程序/ PDF格式; Response.BinaryWrite(pdfByteArray); Response.Flush();

有没有办法打开与在JavaScript中的PDF字节数组,一个新的窗口。

事情是这样的:

VAR脚本=的window.open('+ pdfByteArray +,_blank);; ScriptManager.RegisterClientScriptBlock(Parent.Page的typeof(页),PDF,脚本,真正的);

解决方案

看起来的window.open 将数据URI作为位置参数。

这是一个问题:打开PDF字符串在新窗口中的JavaScript

的window.open(数据:应用程序/ PDF格式; BASE64,+ base64En codedPDF);

在服务器上,您可以转换的字节数组base64编码是这样的:

变种base64En codedPDF = System.Convert.ToBase64String(pdfByteArray);

不过,这似乎很难在IE中实现,因为该URL的长度令人望而却步小,送一个完整的PDF。

Based on the question Open PDF in new browser full window, it looks like I can use JavaScript to open a new window with a PDF file with the following code:

window.open('MyPDF.pdf', '_blank');

I'd like to do so on a return trip from the server by adding a byte array instead of the file name to use as the URL location in window.open

I'm currently returning PDF files like this:

Response.Clear();
Response.ContentType = "application/pdf";
Response.BinaryWrite(pdfByteArray);
Response.Flush();

Is there a way to open a new window with a PDF byte array in javascript.

Something like this:

var script = "window.open('" + pdfByteArray + "', '_blank');";
ScriptManager.RegisterClientScriptBlock(Parent.Page, typeof(Page), "pdf", script, true);

解决方案

It looks like window.open will take a Data URI as the location parameter.

From the question: Opening PDF String in new window with javascript:

window.open("data:application/pdf;base64, " + base64EncodedPDF);

On the server, you can convert the byte array to base64 encoding like this:

var base64EncodedPDF = System.Convert.ToBase64String(pdfByteArray);

However, this seems difficult to implement in IE because the URL length is prohibitively small for sending an entire PDF.

这篇关于的window.open与PDF流,而不是PDF的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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