Dusty,
Sorry I would have been better off asking for some code first...
There are at least two ways to use cfdocument... One is to create a pdf
and save it as a file on your website. You then link to this file in
order for a user to access it. Another way is to replace the content of
the current page with a dynamic pdf. In this case you go to a (*.cfm)
page, and instead of html code, there is a <cfdocument> tag which
replaces the all the content with a pdf. (I was assuming you were doing
this when you mentioned safari opening it as a cfm file.)
If you want to store the data as a separate file (which is you then link
to , this is how I do it...) This will create pdf content only for the
current user and not store the pdf on the server. (It *may* create a
temp file, but I really am not sure) The following is essentially the
entire cfm page... In this case, you go to the cfm page, Coldfusion
creates the content, notifies the browser that it is content type "pdf"
and gives it a filename ending in pdf.
<cfcontent type="application/pdf" reset="true">
<cfheader name="Content-Disposition" value="attachment;
filename=1099report.pdf">
<cfinvoke component="#Request.CFCLocation#.report"
method="Inspector1099Report" returnvariable="ReportHTML">
<cfinvokeargument name="StartDate" value="#form.StartDate#">
<cfinvokeargument name="EndDate" value="#form.EndDate#">
<cfinvokeargument name="MinEarnings" value="#form.Earned#">
<cfinvokeargument name="SortCol" value="#form.SortColumn#">
</cfinvoke>
<cfdocument format="PDF" pagetype="letter" margintop="1.5"
marginbottom="1.1" marginright=".35" marginleft=".35"
orientation="landscape" unit="in" backgroundvisible="yes"
overwrite="no" fontembed="no"
permissions="AllowPrinting,AllowCopy,AllowScreenReaders">
<cfdocumentitem type="header">
<cfoutput>#HeaderContent#</cfoutput>
</cfdocumentitem>
<cfoutput>#ReportHTML#</cfoutput>
</cfdocument>
As for the second way, I use this example... (The footer document item
is not required, but it was in my code so I figured I would include it.)
In this case #PDFFileName# is a full system path. (e.g.
C:\asdsa\asda\name.pdf in windows; /var/www/html/somedir/filename.pdf in
Unix.) On a different page, I would then link or redirect the user to
the new file. (I suppose it can be done at the end of the same page
assuming that processing is completed before the user starts downloading
the content.
<cfdocument filename="#PdfFileName#" format="PDF" localUrl="yes"
orientation="portrait" margintop="0.25" marginbottom="0.6"
overwrite="yes" fontembed="no">
<cfdocumentitem type="footer">
<style><cfinclude
template="../style/InspectionForm.css"></style>
<p class="legaleze">Some Footer Text</p>
</cfdocumentitem>
<cfoutput>#HTMLOutput#</cfoutput>
</cfdocument>
Essentially, if I am creating a one time dynamic pdf then I use the
first method. (There is nothing to clean up later.) The second way is
useful for creating files which can then be emailed as attachments or
accessed by multiple people. (monthly reports, etc...) Just remember
that you will need to delete these files when they are no longer needed.
I hope this helps, if not feel free to ask other questions and I will
attempt to help as best as I can...
--Frank
On 01/29/2013 02:19 PM, Dusty Hale wrote:
Thanks Frank. I tried that but got some unexpected results in Safari
and other browsers. I'm sure it's me haha. What is happening now is
that yes it downloads the PDF (even in Safari) but the PDF now
produces an error message that it can't be opened because it's empty.
If you have time feel free to let me know what I'm doing wrong here
:-) .... and I greatly greatly appreciate it. You can see where I
commented out my old code that works everywhere except Safari and
replaced code you suggested. Thanks again.
---------------------------------------------------
Here's my code adjustments:
<cfset tmpFileName =
"downloads\xyProfile-#url.donorid#-for-#variables.user_accountid#.pdf">
<cfdocument format="PDF" filename="#tmpFileName#" overwrite="Yes" >
#myOutput#
</cfdocument>
<!--- <cfheader name="Content-Disposition"
value="attachment;filename=#tmpFileName#">
<cfcontent type="application/octet-stream"
file="#expandPath('.')#\#tmpFileName#" deletefile="Yes"> --->
<cfcontent type="application/pdf" reset="true">
<cfheader name="Content-Disposition"
value="attachment;filename=#tmpFileName#">
On Tue, Jan 29, 2013 at 12:48 PM, Frank Moorman
<stretch...@franksdomain.net <mailto:stretch...@franksdomain.net>> wrote:
Dusty,
Try this on your page (at the top of page where you would have
headers...)
<cfcontent type="application/pdf" reset="true">
<cfheader name="Content-Disposition" value="attachment;
filename=newfilename#ordynamicfilename#.pdf">
I think that those two lines solve your issues.
--Frank
On 01/29/2013 12:54 PM, Dusty Hale wrote:
I'm having a strange issue with cfdocument in the Safari
browser only. Everywhere else it works just as expected. I've
used cfdocument to create a PDF download from an HTML
document. It works perfect except in Safari it downloads the
actual cfm document and file name instead of the created PDF.
I'm googling and researching this issue now but if anyone has
any helpful info they could pass along it would be greatly
appreciated.
As always thanks for listening :-)
Dusty
-------------------------------------------------------------
To unsubscribe from this list, manage your profile @
http://www.acfug.org?fa=login.edituserform
For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------