html - 使用对象标签在 html 中嵌入 PDF 文件

标签 html pdf embed

我正在将 pdf 文档嵌入到我的 html 代码中。为此,我编写了这段代码。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org

/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title></title>
</head>
<body>
<object height="100%" width="100%" type="application/pdf" data="yii.pdf#toolbar=1&amp;navpanes=0&amp;scrollbar=1&amp;page=1&amp;view=FitH">

<p>It appears you don't have a PDF plugin for this browser. No biggie... you can <a href="/pdf/sample.pdf">click here to download the PDF file.</a></p>

</object>

</body>
</html>

但在 FF4 和 IE9 上嵌入 pdf 文件的结果是空页面,但它的容器非常小,几乎占页面的 30%。如果我删除第一行,即 DOCTYPE,两个浏览器都会按应有的方式呈现 pdf 文件。 以下代码工作正常。

<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title></title>
</head>
<body>
<object height="100%" width="100%" type="application/pdf" data="yii.pdf#toolbar=1&amp;navpanes=0&amp;scrollbar=1&amp;page=1&amp;view=FitH">

<p>It appears you don't have a PDF plugin for this browser. No biggie... you can <a href="/pdf/sample.pdf">click here to download the PDF file.</a></p>

</object>

</body>
</html>

我想在我的页面中使用 doctype,以便其他页面正常工作。有没有办法修复第一个包含文档类型的代码?

最佳答案

这基本上是@tXK 的答案(+1),但是有工作(经过实战测试)的代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Preview</title>
<style type="text/css">
html, body {
    margin: 0;
    padding: 0;
    border: 0;

    height: 100%;
    overflow: hidden;
}
iframe {
    width: 100%;
    height: 100%;
    border: 0
}
</style>
</head>

<body>

<iframe src=""></iframe>

</body>
</html>

关于html - 使用对象标签在 html 中嵌入 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6185774/

相关文章:

css youtube 水平和垂直嵌入流体

html - 在我的浏览器中只打开一侧的特定 div

html - 应用溢出隐藏时删除小边框

jquery - html2canvas - 安全错误 : The operation is insecure

php - 我如何使用 php 从 pdf 中读取超链接?

c# - iTextSharp - 如何获取单词在页面上的位置

javascript - 按 HTML SELECT 对象过滤 Json 功能

html - typescript ,在html中设置元素的样式

java - 如何使用 PDFbox 将元数据添加到 PDF 文档?

javascript - 使用 array.length 创建新的不和谐嵌入字段