PDF格式为HTML中的空白页

时间:2018-01-22 06:54:07

标签: html css pdf laravel-5

我的问题是,一切都很好用我的浏览器打开PDF,直到我上传了一个带有表单的pdf。然后,如果我嵌入它,它将返回一个空白页面。但其他带有表单的pdf正常打开。请参阅下面的代码:

<object data="{{ asset($test->file_path) }}" type="application/pdf" width="100%" height="100%">
    <embed src="{{ asset($test->file_path) }}" type='application/pdf'>
    <center>
        <a href="{{ route('download.test', ['id' => $test->id]) }}" class="btn btn-primary">Please click here to view</a>
    </center>
</object>

注意:我还尝试使用<iframe>但仍返回空白页。

解决方案:

选项1:

重命名了#符号的文件。一切都应该工作正常。

选项2:

如果需要,请使用urlencode

4 个答案:

答案 0 :(得分:5)

<a href="{{ route('download.test', ['id' => $test->id] ,['target'=>'_blank']) }}" class="btn btn-primary">Please click here to view</a>

答案 1 :(得分:1)

已经很晚了,我很累,如果我误解了这个问题,请道歉。

我注意到PDF托管在不支持HTTPS的网站上。如果它使用HTTPS嵌入在网站上,则显示空白页面,但在使用HTTP时工作正常。

我认为您需要将PDF移至支持HTTPS的网站,或者使用HTTPS启动托管PDF的网站。

答案 2 :(得分:0)

考虑使用对象和iframe(而不是对象和嵌入)

这样的事情对你有用:

<object data="http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf" type="application/pdf" width="100%" height="100%">
    <iframe src="http://foersom.com/net/HowTo/data/OoPdfFormExample.pdf" width="100%" height="100%" style="border: none;">
        This browser does not support PDFs. Please download the PDF to view it: <a href="/pdf/example.pdf">Download PDF</a>
    </iframe>
</object>

当我在本地测试它时,这有效,但由于它使用HTTPS,我无法显示JSFiddle。 另外,请看一下这些示例:https://pdfobject.com/static.html

答案 3 :(得分:0)

不确定这是否有效,因为我无法测试你的情况。你可以尝试这个,它总是适合我。尝试使用正确的路径替换http://yoursite.com/the.pdf

<object data="http://yoursite.com/the.pdf" type="application/pdf" width="750px" height="750px">
    <embed src="http://yoursite.com/the.pdf" type="application/pdf">
        <p>This browser does not support PDFs. Please download the PDF to view it: <a href="http://yoursite.com/the.pdf">Download PDF</a>.</p>
    </embed>
</object>