在HTML中嵌入PDF的推荐方法是什么?

iFrame吗? 对象? 嵌入?

Adobe是怎么说的呢?

在我的例子中,PDF是动态生成的,因此不能在刷新之前将其上传到第三方解决方案。


当前回答

PdfToImageServlet使用ImageMagick的convert命令。

使用的例子: < img src = " / webAppDirectory / PdfToImageServlet ? pdfFile = / usr /共享/杯/数据/ default-testpage.pdf ' >

其他回答

值得注意的PDF是您应该考虑的选项之一 它有一个免费的计划,除非你打算在pdf文件上进行实时在线协作

将以下iframe嵌入到任何html并享受结果:

<iframe width='1000' height='800' src='http://bit.ly/1JxrtjR' frameborder='0' allowfullscreen></iframe>

您可以通过在查询字符串中传递一些选项来控制PDF在浏览器中的显示方式。我很高兴能这样工作,直到我意识到它不能在IE8中工作。:(

它适用于Chrome 9和Firefox 3.6,但在IE8中,它会显示“如果PDF文件无法显示,请在此处插入错误消息”的消息。

不过,我还没有测试上述任何浏览器的旧版本。但这是我的代码,希望能帮到大家。这将缩放设置为85%,删除滚动条,工具栏和导航窗格。如果我发现IE中也能运行的东西,我会更新我的帖子。

<object width="400" height="500" type="application/pdf" data="/my_pdf.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0">
    <p>Insert your error message here, if the PDF cannot be displayed.</p>
</object>

我发现这工作得很好,浏览器处理它在firefox。我没有检查IE…

<script>window.location='url'</script>

同时使用<object>和<embed>将为您提供更广泛的浏览器兼容性。

<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>

这是我对AXIOS和Vue.js所做的:

        axios({
            url: `urltoPDFfile.pdf`,
            method: 'GET',
            headers: headers,
            responseType: 'blob'
        })
        .then((response) => {
            this.urlPdf = URL.createObjectURL(response.data)
        })
        .catch((error) => {
            console.log('ERROR   ', error)
        })

将urlPDF动态添加到HTML:

<object width='100%' height='600px' :data='urlPdf' type='application/pdf'></object>