使用CFHtmlToPdf将CFML转换为CFScript

问题描述 投票:2回答:1

我正在尝试将我的CFML代码转换为CFScript,但我收到了CFHtmlToPdf的错误。

CFML:

<cfoutput>
  <cfhtmltopdf orientation="portrait"  pagetype="A4" margintop="1" marginbottom="1" name=pdfFile>
    #arguments.data.HTMLData#
  </cfhtmltopdf>

  <cfmail type=HTML to="#arguments.data.Email#" from="[email protected]" subject="Form Test" server="localhost">
    TEST
    <cfmailparam file="#arguments.data.ReportName#.pdf" type="application/pdf" content="#pdfFile#"/>
  </cfmail>
</cfoutput>

我的cfscript代码:

cfhtmltopdf(source=arguments.data.HTMLData, destination=pdfPath);

mailerService = new mail();
mailerService.setTo("arguments.data.Email"); 
mailerService.setFrom("[email protected]"); 
mailerService.setSubject("Form Test"); 
mailerService.setType("html");
mailerService.addParam(file="Test.pdf",type="application/pdf",content=pdfPath);
mailerService.send(body="Test");

我收到错误:

src不是正确的URL,或者绝对路径指定的文件不存在。

行中出现错误:

cfhtmltopdf(source=arguments.data.HTMLData, destination=pdfPath);

我在cfscript中错误地使用CFHtmlToPdf吗?

coldfusion cfml
1个回答
5
投票

问题是你以错误的方式使用cfhtmltopdf。 HTML字符串不应该作为source属性传递,而是作为函数的内容传递(就像你对savecontent所做的那样)。

检查这个link

variables.pdfFile='';
cfhtmltopdf(name='variables.pdfFile'){
  writeOutput(arguments.data.HTMLData);
};
© www.soinside.com 2019 - 2024. All rights reserved.