2017-07-27 80 views
0

我正在使用ColdFusion cfdocument标记创建PDF文档。工作正常,但不是在浏览器标题中显示文档名称 - 它显示我创建PDF时调用的.cfc文件。ColdFusion - URL中的CFDOCUMENT标题

下面是我如何打电话给它。

<cfdocument format="pdf" marginbottom=".5" margintop=".25" marginright=".5" marginleft=".5" saveAsName="#filename#.pdf"> 
    <cfdocumentitem type="footer"> 
      <p style="font-size:11px; text-align:right; font-style:italic;">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</p> 
    </cfdocumentitem> 
    <html> 
      <head><title>#filename#.pdf</title></head> 
      <body><img src="file:///#application.tempFolder#\#thisFilename#" /></body> 
    </html> 
</cfdocument> 

我错过了什么?为什么它仍然显示我在浏览器标题中调用的filename.cfc文件,而不是我给PDF的文件名?

回答

1

想通了。必须使用CFDOCUMENT创建文档,然后使用CFPDF标签为其添加“标题”属性。然后将其输出到浏览器。

<!--- Create the PDF ---> 
<cfdocument format="pdf" marginbottom=".5" margintop=".25" marginright=".5" marginleft=".5" filename="#application.tempFolder#\#thisSaveAsFilename#" overwrite="yes"> 
    <cfdocumentitem type="footer"> 
     <p style="font-size:11px; text-align:right; font-style:italic;">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</p> 
    </cfdocumentitem> 
    <html> 
     <head><title>#thisSaveAsFilename#</title></head> 
     <body><img src="file:///#application.tempFolder#\#thisFilename#" /></body> 
    </html> 
</cfdocument> 
<!--- Use CFPDF to add attributes to it ---> 
<cfset thisInfo = StructNew()> 
<cfset thisInfo.Title = "pdf title goes here..."> 
<cfpdf action="setinfo" info="#thisInfo#" source="#application.tempFolder#\#thisSaveAsFilename#" /> 
<!--- Send it to the browser ---> 
<cfcontent file="#application.tempFolder#\#thisSaveAsFilename#" type="application/pdf" />A