Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cfdocument Question

Status
Not open for further replies.

yoshismokey

Programmer
Sep 17, 2005
25
US
Hi,
I would like to display a web page from my cold fusion application in a PDF file to be viewed by the user when they click on a button. I have the following code which partially works:

<cfif IsDefined("form.Preview")>
<!--- You can pass a URL in the URL string --->
<cfparam name="url.target_url" default="<cfoutput>
<cfhttp url="#url.target_url#" resolveurl="yes">
<cfdocument format="pdf">
<cfdocumentitem type="header">
<cfoutput>#url.target_url#</cfoutput>
</cfdocumentitem>
<!--- Display the page --->
#cfhttp.filecontent#
</cfdocument>
</cfoutput>
</cfif>

This application has security in it so that the user has to log in before viewing any of the pages. The user is actually logged in at the time that he pushed this Preview button.
The problem arises when the url is called in the above code though. The PDF file is shown but not with the correct page(UPRSummary). Instead, the login page is shown. This I believe is because of the application.cfm file which checks the value of the session.LoggedIn variable and if it is "False", it sends the user to the login page. For some reason, when calling the url from this cfdocument code, the session.LoggedIN variable must be set back to "False" and the user login page is displayed, thus messing up my PDF file.
I know this is the case because I disabled the application.cfm file (renamed it application1.cfm) and ran the above code and it worked!! I also tried setting Session.LoggedIn to "TRUE" in the UPRSummary code, which didn't work either.
Do you have any idea how I could disable the application.cfm code within my code temporarily so this cfdocument procedure would work?
Thanks in advance.[bigglasses]
 
It's because using CFHTTP is accessing the page as a separate session, and therefore isn't logged in. It's just like opening a different browser as a different user.

Depending on your security setup, you may be able to pass form fields or login criteria along with the CFHTTP call.

 
Just a thought - Could I somehow save that web page as an html document outside of the session and then have it generate the PDF file so I could attach it to an email? I don't actually have to let them preview the pdf online.
Thanks again.

 
If the user is actually saving the page they are already "sitting on" then you can generate the page content you want to save in a CFSAVECONTENT variable.

Then you can use all the content in that variable for multiple things - output to user, save to file, convert to PDF, whatever. Doing it this way would eliminate the requirement for CFHTTP to have to try and login, since it uses the same page they are already logged into.
 
I was able to view cfsavecontent tag to display the page and also to send it as html via email. Is there a way I can save it to a pdf file?
Here's the code I have for the html:
<cfsavecontent variable="savesummary">
<html>
code for page here...
</html>
</cfsavecontent>
<cfoutput>Your summary has been sent successfully</cfoutput>
<cfoutput>#savesummary#
<cfmail
from="rbeers@chrysaliscreative.com"
server="smtp.patmedia.net"
subject="UPR Final Submit"
to="rbeers@chrysaliscreative.com"
>
#savesummary#
</cfmail>
</cfoutput>


Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top