2
votes

I'm trying to convert my CFML code to CFScript, but I am getting an error with 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>

My cfscript code:

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");

I'm getting the error:

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

The error occurs in the line:

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

Am I using CFHtmlToPdf incorrectly in cfscript?

1
When in doubt, look at your data. Do a writedump of arguments.data,HTMLData. - Dan Bracuk
Kind of hard to spot the issue when all we can see is variable names . What's the actual value of those two variables? - SOS
It is just HTML tags in the arguments.data,HTMLData varaible - myTest532 myTest532

1 Answers

5
votes

The problem is that you were using cfhtmltopdf in the wrong way. The HTML string should be passed not as the source attribute, but as a content of the function(like what you would do for a savecontent).

Check this link.

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