编写HTML代码以在浏览器中打开PDF

时间:2015-03-09 15:39:51

标签: html browser

我从word文档生成一个html文件,其中包含一些指向pdf文件的链接。当我在某些浏览器中打开它时,会出现下载提示。我需要的是在同一个浏览器窗口中打开pdf文件。

我读到一个解决方案是在头文件中包含以下命令:

Content-Type: application/pdf
Content-Disposition: inline; "filename.pdf"

但是,我不知道我的pdf文件的哪一部分我必须把它们放进去。这是我的HTML代码的标题。

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 14 (filtered)">
<base href=x>
<title>Welcome to SELSE-1, which we anticipate will be the first of a series of
annual workshops to bring together experts from both industry and academia to
discuss current and future trends in Soft Error Upset (SEU) rates and the state
of the art and possible</title>
<style>
<!--
 /* Font Definitions */
 @font-face
    {font-family:Wingdings;
    panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
    {font-family:"MS Mincho";
    panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
    {font-family:"MS Mincho";
    panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
    {font-family:Tahoma;
    panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
    {font-family:"Lucida Grande";}
@font-face
    {font-family:"\@MS Mincho";
    panose-1:2 2 6 9 4 2 5 8 3 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0in;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Times New Roman","serif";}
h2
    {mso-style-link:"Heading 2 Char";
    margin-right:0in;
    margin-left:0in;
    font-size:18.0pt;
    font-family:"Times New Roman","serif";
    font-weight:bold;}
p.MsoCommentText, li.MsoCommentText, div.MsoCommentText
    {mso-style-link:"Comment Text Char";
    margin:0in;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Times New Roman","serif";}
p.MsoHeader, li.MsoHeader, div.MsoHeader
    {mso-style-link:"Header Char";
    margin:0in;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Times New Roman","serif";}
p.MsoFooter, li.MsoFooter, div.MsoFooter
    {mso-style-link:"Footer Char";
    margin:0in;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
    {color:blue;
    text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
    {color:purple;
    text-decoration:underline;}
p
    {margin-right:0in;
    margin-left:0in;
    font-size:12.0pt;
    font-family:"Times New Roman","serif";}
p.MsoCommentSubject, li.MsoCommentSubject, div.MsoCommentSubject
    {mso-style-link:"Comment Subject Char";
    margin:0in;
    margin-bottom:.0001pt;
    font-size:10.0pt;
    font-family:"Times New Roman","serif";
    font-weight:bold;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
    {margin:0in;
    margin-bottom:.0001pt;
    font-size:8.0pt;
    font-family:"Tahoma","sans-serif";}
p.MsoRMPane, li.MsoRMPane, div.MsoRMPane
    {margin:0in;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Times New Roman","serif";}
span.maroon
    {mso-style-name:maroon;}
span.HeaderChar
    {mso-style-name:"Header Char";
    mso-style-link:Header;
    font-family:"Times New Roman","serif";}
span.FooterChar
    {mso-style-name:"Footer Char";
    mso-style-link:Footer;
    font-family:"Times New Roman","serif";}
span.Title1
    {mso-style-name:Title1;}
span.authors
    {mso-style-name:authors;}
span.CommentTextChar
    {mso-style-name:"Comment Text Char";
    mso-style-link:"Comment Text";}
span.CommentSubjectChar
    {mso-style-name:"Comment Subject Char";
    mso-style-link:"Comment Subject";
    font-weight:bold;}
span.Heading2Char
    {mso-style-name:"Heading 2 Char";
    mso-style-link:"Heading 2";
    font-family:"Times New Roman","serif";
    font-weight:bold;}
p.p1, li.p1, div.p1
    {mso-style-name:p1;
    margin-right:0in;
    margin-left:0in;
    font-size:12.0pt;
    font-family:"Times New Roman","serif";}
p.Default, li.Default, div.Default
    {mso-style-name:Default;
    margin:0in;
    margin-bottom:.0001pt;
    text-autospace:none;
    font-size:12.0pt;
    font-family:"Arial","sans-serif";
    color:black;}
span.apple-converted-space
    {mso-style-name:apple-converted-space;}
.MsoChpDefault
    {font-size:10.0pt;}
 /* Page Definitions */
 @page WordSection1
    {size:8.5in 11.0in;
    margin:1.0in 89.85pt 64.9pt 89.85pt;}
div.WordSection1
    {page:WordSection1;}
 /* List Definitions */
 ol
    {margin-bottom:0in;}
ul
    {margin-bottom:0in;}
-->
</style>

</head>

1 个答案:

答案 0 :(得分:1)

您无法强制浏览器显示PDF,但您可以告诉它可以如果已经设置了这样做。

您需要做的是使用您提到的标题提供文件。这告诉浏览器它加载的内容实际上是PDF,如果它设置为打开PDF,它就会。否则,可能会启动下载。

更具体地说,您需要将标题附加到Web服务器提取文件时给出的响应。实际应用程序可能会有很大差异,具体取决于您的网络服务器以及您如何提供文件。

例如,如果文件是通过servlet提供的,则可以在servlet中设置content-type( java ):

response.setContentType("application/pdf");

如果直接提供(例如,您只是使用&lt; a&gt;链接到该文件),则需要在服务器规模上进行设置。例如,在 tomcat 中,您可以在 web.xml 文件中进行设置,如下所示:

<mime-mapping>
    <extension>pdf</extension>
    <mime-type>application/pdf</mime-type>
</mime-mapping>

这将设置服务器,使用.pdf扩展名提供的任何文件都会自动接收正确的内容类型。