使用 CFHtmlToPdf 将 CFML 转换为 CFScript

Convert CFML to CFScript using CFHtmlToPdf

我正在尝试将我的 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="support@mydomain.com" 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("support@mydomain.com"); 
mailerService.setSubject("Form Test"); 
mailerService.setType("html");
mailerService.addParam(file="Test.pdf",type="application/pdf",content=pdfPath);
mailerService.send(body="Test");

我遇到错误:

Either the src is not a proper URL or the file specified by absolute path does not exist.

错误发生在行:

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

我在 cfscript 中使用 CFHtmlToPdf 不正确吗?

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

检查此 link

variables.pdfFile='';
cfhtmltopdf(name='variables.pdfFile'){
  writeOutput(arguments.data.HTMLData);
};