2017-07-27 79 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