问题描述
我们的Rails网络应用程序使用wkhtmltopdf生成PDF并将其发送到客户端。这适用于我们用Edge测试它的每个网页浏览器。
Our Rails web app generates PDFs using wkhtmltopdf and sends them to the client. This works in every web browser we've tested it with except Edge.
我们尝试用几种不同的方式渲染响应,这就是它最初的方式:
We've tried rendering the response in a couple of different ways, this is how it was originally:
kit = PDFKit.new(@html_content)
render text: kit.to_pdf, content_type: 'application/pdf'
这将打开PDF查看器,在我们测试的每个浏览器中正确显示PDF,但Edge除外浏览器显示的位置:某些内容使此PDF无法打开。
This opens the PDF viewer with the PDF displaying correctly in every browser that we tested with except Edge where the browser displays: Something's keeping this PDF from opening.
在我们的应用程序日志中,有一个POST请求,即表单提交和我可以看到我们的应用程序发送pdf文件响应,然后有对表单提交URL的后续GET请求哪个错误,因为它不期望对该URL的任何GET请求。我不知道这里发生了什么。
In our application logs, there is the POST request which is the form submission and I can see our app send the pdf file response, then there are subsequent GET requests to the form submission url which error because it's not expecting any GET request to that url. I've no idea what's going on here.
请求的响应标头是:
Cache-Control: max-age=0, private, must-revalidate
Connection: Keep-Alive
Content-Length: 34865
Content-Type: application/pdf; charset=utf-8
Date: Thu, 18 Jun 2015 14:35:30 GMT
Etag: "4baf297d1866339e60e8e893300909a0"
Server: WEBrick/1.3.1 (Ruby/2.0.0/2013-06-27)
Set-Cookie: _APP_session=<long cookie>; path=/; HttpOnly
X-Request-Id: 617580a8-4d7d-43c4-8e49-aeaeafba7b79
X-Runtime: 21.868098
X-XSS-Protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-ua-compatible: chrome=1
我也尝试过这样使用 send_data
:
send_data kit.to_pdf, type: 'application/pdf', disposition: 'inline'
这导致以下响应标题但最终出现同样的问题:
Which results in the following response headers but ultimately the same problem:
Cache-Control: private
Connection: Keep-Alive
Content-Disposition: inline
Content-Length: 34866
Content-Transfer-Encoding: binary
Content-Type: application/pdf
Date: Thu, 18 Jun 2015 14:39:42 GMT
Etag: "11db49f1a26444a38fa2b51f3c3336ed"
Server: WEBrick/1.3.1 (Ruby/2.0.0/2013-06-27)
Set-Cookie: _APP_session=<long cookie>; path=/; HttpOnly
X-Request-Id: 501d9832-b07e-4764-8ecc-f1c1e9a6421e
X-Runtime: 7.054236
X-XSS-Protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-ua-compatible: chrome=1
如果从上面删除 Content-Disposition:inline
标题,它会显示保存文件提示和下载文件工作正常。我们需要在浏览器窗口中加载它。
If I remove the Content-Disposition: inline
header from the above it brings up the save file prompt and downloading the file works fine. We need it to load in the browser window though.
我不相信它是,因为它适用于IE 9,10和11,只是Edge的一个问题。
I don't believe it to be a duplicate of this question because it works in IE 9, 10 and 11 and is only a problem with Edge.
推荐答案
这是一个错误,但微软已经在构建10158中修复了它! :)
It was a bug but Microsoft have fixed it in build 10158! :)
这篇关于Microsoft Edge PDF内联问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!