This content has been marked as final. Show 14 replies
Could we have a look at the code?
Sure, here it is:
<cfif IsDefined("form.execute") and drplantemplateDetails.recordCount GT 0>
<cfdocument marginbottom="2" marginleft="2" marginright="2" margintop="2" fontembed="yes" format="pdf" name="drplandoc" backgroundvisible="yes" orientation="portrait" pagetype="a4" filename="C:\UserResources\#checkuser.userid#\#drplantemplateDetails.drplan_name#.pdf" overwrite="yes" unit="cm">
This is a shortened version of code, that also doesn't work. Full version also contains images INLINE, i.e.
<img src="viewresource.cfm?resource_id=blablabla>, which output image using cfheader + cfcontent. I once tried this inside cfdocument, but got only image placeholders... WHether there is no way to build-in inline images into PDF documents, using cfdocument tag?
Place <cfoutput query="drplantemplatestepDetails"> before <cfdocumentsection>, and </cfoutput> after </cfdocumentsection>.
Ensure that this path exists and that it is unique: C:\UserResources\#checkuser.userid#\#drplantemplateDetails.drplan_name#.pdf. For example, I would be careful when assigning the filename dynamically from a resultset. The query might bring up two or more names. In any case, test the code first with filename="C:\UserResources\user123\drplan_name123.pdf".
BKBK, thanks, I've tried exactly like you had proposed: no luck.
But i forgot to mention, that sometime my initial (and '123', that you offered also) code produces the following error:
timeout when listing directory content - this code follows cfdocument code to determine generated pdf file size, if it exists:
<cfdirectory action="list" filter="drplan_name123.pdf" name="getFileInfo" directory="C:\UserResources\123">
I.e. sometimes I get cfdocument timeout error, sometimes - timeout for listing directory error. In last case pdf file IS created, but
1) anyway, it takes unallowable looong time for such short output (several strings)
2) full code leaves empty image placeholder, where images are generated by cfheader + cfcontent, like i described in my first post.
Did you manually create the folder C:\UserResources\123? Another suggestion:
At last seems like I've found the problem. The problem is #content# field. It contains inline images, like this:
Here is the resource image <img src="showresource.cfm?resource_id=blablabla">
And showresource.cfm gets image path from database by resource_id and then uses this path +
cfheader and cfcontent tag with 'Content-Disposition: inline' to show image right away. HTML displays properly. But cfdocument hangs...
Any ideas how to handle this situation?
BTW, when instead of #content# I just put 'blabla' - this word is displayed with distortion on every page: visible is only about 25% of text from below. The rest part looks like erased to background (white) in graphic editor... :(
<img> should display an image directly within cfdocument, without any need for <cfheader and <cfcontent>.
But these are 'secure' images (screen dumps of 'secret pages') - i can't store them in www folder, so like other types of secure resources (these could be pdfs, docs, xls, etc) I store them ABOVE www root and use cfheader + cfcontent to access them.. The only difference is that other types of resources are offered for downloading (content-disposition: attachment) and images are generated inline... How can I get without this in my situation? Do I need to save them temporary on 'backstage' to some wwwfolder for cfdocument and delete later? Uhhm... it's getting clumsy and complicated...
<cfheader> and <cfcontent> appear to be the problem. If you save any one of the following 3 code combinations as the file testPage1.cfm, then the page will display the image.
1) <cfheader name="Content-Disposition" value="inline; photo1.jpg">
<cfcontent type="image/pjpeg" file="c:\photos\photo1.jpg" deletefile="no">
2) <cfcontent type="image/pjpeg" file="c:\photos\photo1.jpg" deletefile="no">
3) <img src="photo1.jpg">
For a second image, you could also change from photo1.jpg to photo2.jpg and save the code as testPage2.cfm. When I tested the various combinations, I discovered that the only one that works with the code below is:
Thanks for information. Ok, I've created parser (i will anyway need parser for content field - i will be evaluating variable by names there, etc...) So - parser temporary copies all resources into current www folder, especially for cfdocument. Then replace command replaces corresponding links. Again - html shows ok. But damned cfdocument doesn't work, anyway!
And now i even can't name all the reasons it doesn't work! It works only when i remove almost everything from my output!
Seems it even doesn't like my css style! I don't have idea what to do...
Here is the code
<cfdocument filename="C:\UserResources\#checkuser.userid#\#drplantemplateDetails.drplan_name#.pdf" format="pdf" overwrite="yes">
<link rel="stylesheet" title="#client.theme##client.fontSize#" type="text/css" href="/#client.theme##client.fontSize#.css" title="Default"/>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<p>#parseDRPlan(content, "pdf", GetDirectoryFromPath(GetCurrentTemplatePath()), "/members/Planning/resources", "create")#</p>
<cfloop index="i" from="1" to="3">
<cfset step_id = Evaluate("step_" & i & "_id")>
<cfset step_header = Evaluate("step_" & i & "_header")>
<cfset step_description = Evaluate("step_" & i & "_description")>
<cfif step_id is not "" and (not IsDefined("form.drstep_id") or IsDefined("form.drstep_id") and ListFind(form.drstep_id, step_id) is not false)>
<p><a href="#ListGetAt(CGI.SCRIPT_NAME, ListLen(CGI.SCRIPT_NAME, "//"), "//")#?#CGI.QUERY_STRING####step_id#"><cfif step_header is "">Unnamed<cfelse>#step_header#</cfif></a></p>
<cfif step_description is not ""><p>#step_description#</p></cfif>
You forgot to add a few cfoutput tags.
I don't see one cfoutput tag...you need them inside the cfdocument tag.
Also I would get rid of the pagebreak every loop, I think it's implied
with the closing cfdocumentsection tag.
Thanks for your replies!
About cfoutput - I used one, but the only one in whole cfm document - at the top and bottom. But ok, thinking that output may preferably be used inside cfdocument, I copied the code of BKBK instead of mine - no luck again! :(
Again timeout error and, sometimes, other error:
"The request has exceeded the allowable time limit Tag: CFLOOP".
It's also a lie, because without cfdocument this loops works several seconds!
P.S. BTW: right now i've ensured, that I don't need to copy images into current www folder! Instead, i can use "file:///" prefix and it works with local folders as is. Since I direct output to file, all local folder names are stayed insivible in page source! I've successfully generated pdf file with shortened piece of code. However, I still have a problem with some other parts - it keeps hanging and timeouting: weird, but the reason is <html>...<head>...<body> starting and ending tags and/or style... Dunno why.
I have removed these enclosing tags, left only viscera and it works ok.