我从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>
您不能强制浏览器显示PDF,但可以告诉它可以(如果已经设置为可以显示PDF)。
您需要做的是使用您提到的标题提供文件。这告诉浏览器它正在加载的内容实际上是PDF,如果它设置为打开PDF,则它将。否则,可能会启动下载。
更具体地说,您需要在Web服务器获取文件时将标头附加到Web服务器给出的响应上。实际的应用程序可能会有所不同,具体取决于您的Web服务器以及如何提供文件。
例如,如果文件是通过servlet提供的,则可以在servlet(java)内部设置content-type :
response.setContentType("application/pdf");
如果直接提供文件(例如,您只是使用<a>链接到文件),则需要在服务器规模上进行设置。例如,在tomcat中,您可以像下面这样在web.xml文件中进行设置:
<mime-mapping>
<extension>pdf</extension>
<mime-type>application/pdf</mime-type>
</mime-mapping>
这将以某种方式设置服务器,以使任何带有.pdf扩展名的文件都自动接收正确的内容类型。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句