Skip to main content
Inspiring
June 2, 2014
Answered

Problems with CFHTMLTOPDF

  • June 2, 2014
  • 1 reply
  • 1788 views

Working with this tag for the first time in a trial version of CF 11. I'm unable to pass any URL vars with the source without error, for both .cfm and .html pages. For example, source="myPage.html" works as expected, but source="myPage.html?x=1" throws a 500 error.

When the urltoken is not passed with the source when the source is a .cfm page, the session (login) is not recognized and we get thrown to the login page.

This topic has been closed for replies.
Correct answer BKBK

Peter, I have tried using cfhttp, but am not able to get that to work either.  Here is my code:

<!DOCTYPE HTML>

<html>

<head>

<meta charset="UTF-8">

<title>LCAP TESTING</title>

<cfset vServer = 'http://127.0.0.1/lcapcaTesting/app/'>

<cfset vPage = '/reportsCF/reportsDocument.cfm?#SESSION.URLToken#'>

      

<cfhttp url="#vServer##vPage#" result="vResult">

<cfset vContent = vResult.fileContent>

</head>

<body>

<cfhtmltopdf

  source="#vServer##vPage#"

  pagetype="letter"

  orientation="landscape"

  marginTop="1" marginBottom="1" marginLeft="1" marginRight="1">

</cfhtmltopdf>

</body>

</html>

With the URL Token included, as in the code above, it errors, saying

Error occurred while generating PDF.

Reason: THE REFERENCE TO ENTITY "CFTOKEN" MUST END WITH THE ';' DELIMITER.

Never have seen that before in 15 years of working with CF.  Head scratcher.  So, tried adding ; after the Token as in #SESSION.URLToken#; but no go, same error message.

IF the URL Token is not passed with the page, we end up with a beautiful PDF our login page (session is dropped?).

Finally, passing the vContent as the source (after the cfhttp call) as in <cfhtmltopdf source="#vContent#"... per your advice, results in a CF error page, with no information.  Frustrating. 

Thanks for any help.  We have an extremely pressing need for a quality pdf of our content.


To start with, there is a typo. The string vServer ends with the character /, and the string vPage begins with the same character. When you concatenate the two, you get a URL that contains //.

In any case, my interpretation of Pete's suggestion is as follows:

<!--- Get contents of page --->

<cfset vServer = 'http://127.0.0.1/lcapcaTesting/app'>

<cfset vPage = '/reportsCF/reportsDocument.cfm?#SESSION.URLToken#'>

<cfhttp url="#vServer##vPage#" result="vResult">

<cfset vContent = vResult.fileContent>

<!--- Save page as HTML file --->

<cffile action="write" file="#expandPath('/lcapcaTesting/app/reportsCF/generatedContent.html')#" output="#vResult.fileContent#">

<!--- Convert HTML to PDF --->

<cfhtmltopdf

  source="#expandPath('/lcapcaTesting/app/reportsCF/generatedContent.html')#"

  pagetype="letter"

orientation="landscape"

  marginTop="1" marginBottom="1" marginLeft="1" marginRight="1">

</cfhtmltopdf>

1 reply

BKBK
Community Expert
Community Expert
June 3, 2014

Gtheobald wrote:

"myPage.html?x=1"

I can imagine why this fails. Why would you pass a URL variable to a static page?

gtheobaldAuthor
Inspiring
June 3, 2014

BKBK: Thanks for taking time to respond.  The reality is, it does fail, and the point being that it fails only when a URL var is included in the "source".  You are correct that it is not relevant to pass a URL var to a static page, that was only an example, but is also the way I discovered what the true problem is.  My actual code is below, and we must pass the SESSION.URLToken to maintain the user session.

<cfset vPage = 'reportsDocument.cfm?#SESSION.URLToken#&reportType=4'>

<cfhtmltopdf

  source="#vPage#"

  pagetype="letter"

  orientation="landscape"

  marginTop="1" marginBottom="1" marginLeft="1" marginRight="1">

</cfhtmltopdf>

pete_freitag
Participating Frequently
June 3, 2014

Sounds like they are stripping out the query string for whatever reason. You probably should file a bug report. As a workaround you can use cfhttp to get the HTML and then pass the html to cfhtmltopdf