在浏览器中打开PDF

Gir*_*vil 1 pdf coldfusion cfdocument

我想在浏览器中打开PDF,以便我可以使用以下代码,但我发生了错误:"文件不以%PDF开头".

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>

    <div style="width:358px;height:206px;">
        <img src="http://www.pcsamerica.net/mp/images/reloimages/upload/home_home_image_117713.jpg"  border="2" width="358" height="206" />
        <img src="http://www.pcsamerica.net/mp/images/reloimages/upload/home_mug_image_117713.jpg" border="1" width="68" height="68" style="position:absolute; top:190px; left:25px; z-index:2"/>
        <font style="position:absolute; top:15px; left:15px; z-index:2; border:1px; color:FFFFFF;font-family:impact;font-size:14px;">

        </font>
    </div>
    <div style="width:425px;height:206px;padding-top:5px; padding-left:75px; text-align:center; border:1px;font-family:Arial;font-size:9px;">

    </div>
</body>
</html>

<cfheader name="Content-Disposition" value="inline; filename=Test.pdf">
<cfcontent type="application/pdf">
Run Code Online (Sandbox Code Playgroud)

Ste*_*o D 8

<!--- TAKES YOUR HTML AND SAVES IT TO A LOCAL VARIABLE --->
<cfsavecontent variable="PDFhtml">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
</head>
<body>
  <div style="width:358px;height:206px;">
    <img src="http://www.pcsamerica.net/mp/images/reloimages/upload/home_home_image_117713.jpg"  border="2" width="358" height="206" />
    <img src="http://www.pcsamerica.net/mp/images/reloimages/upload/home_mug_image_117713.jpg" border="1" width="68" height="68" style="position:absolute; top:190px; left:25px; z-index:2"/>
    <font style="position:absolute; top:15px; left:15px; z-index:2; border:1px; color:FFFFFF;font-family:impact;font-size:14px;">
    </font>
  </div>
  <div style="width:425px;height:206px;padding-top:5px; padding-left:75px; text-align:center; border:1px;font-family:Arial;font-size:9px;">
  </div>
</body>
</html>
</cfsavecontent>

<!--- USES THE VARIABLE DEFINED ABOVE TO CREATE THE PDF USING CF TAGS --->
<cfheader name="Content-Disposition" value="inline; filename=Test.pdf">
<cfdocument format="pdf">
  <cfoutput>
    #variables.PDFhtml#
  </cfoutput>
</cfdocument>
Run Code Online (Sandbox Code Playgroud)

只是一点不是,你不能在Coldfusion的浏览器中进行PDF显示; 你只是用Colfusion生成PDF.PDF打开的位置是默认阅读器的选项,最常见的是Adobe Reader.如果PDF未在浏览器中打开,则可能会关闭"在浏览器中显示PDF".要修复打开的Adobe Reader并转到编辑 - >首选项,请在"类别:"下单击"Internet".在右侧,您会看到一个复选框,对于"在浏览器中显示PDF"标签,请确保单击它.


der*_*ert 6

<cfheader name="Content-Disposition" value="inline; filename=Test.pdf">
<cfcontent type="application/pdf">
Run Code Online (Sandbox Code Playgroud)

不知道coldfusion,但这看起来好像你正在向浏览器发送HTML并假装其PDF.那不行.

  • 那是对的.ColdFusion具有将HTML转换为PDF以使其正常工作的特殊标记. (2认同)