Copy link to clipboard
Copied
Is it possible to have a PDF generated by cfpdf save to the desktop of the user's machine? I can't really have users generating PDF's and filling up space on the server.
I have read through the documentation and haven't been able to find anything.
I'm using CF8.
Thanks,
Michelle
Copy link to clipboard
Copied
ColdFusion code runs on the CF server, not the client PC, and indeed CF never interacts with the client PC (or even knows the client PC exists): it solely communicates with the web server, of which the client has made a request of some description (which could be a request that invokes your PDF-creating code).
So: no. CF cannot write the file directly to the client. However it can create the file, return it as the response to the request, and then delete the file.
Have a look at the CFCONTENT tag which will set the MIME type of the response to suit PDF data being returned, and can also delete the file after it is sent (strange combination of functionality, but there you have it).
All the CF docs are online, and here's the link to CFCONTENT:
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_c_11.html#2850760
--
Adam
Copy link to clipboard
Copied
You can either generate the pdf entirely in server memory. Then use cfcontent's "variable" attribute to return it to the user's browser. Or you could save the pdf to disk, but use cfcontent's "deleteFile" attribute to instruct CF to delete the file, when finished so they will not accumulate.
save to the desktop of the user's machine
You can only serve up the pdf for downloading. You cannot specify where it is saved on the client computer. That is up to the user.
-Leigh
Copy link to clipboard
Copied
Ok between your two posts, I have a PDF opening up in the window. YAY!
Now, here's the next problem - I need it to either open up in a different window or in Acrobat directly. There are times when multiple files will be generated, each will have to open up to be saved by the user. Acrobat can have multiple documents open, but the browser window is creating some difficulty...
Copy link to clipboard
Copied
The only way that you could really do something like that is to modify your process flow to something like this:
1) User requests CFM page or submits Form to CFM page
2) Generate PDF Files on server and save as unique file names
3) Build HTML on the that includes links to the various PDF fiels you just created
or
2a) In addition to the HTML links on the CFM page, build a JS script that fires on page load that pops open a new window for linking to each of the PDFs you just created
Either way, if you need multiple browser windows you wont be able to "push" the PDF directly to the users in the same way using the cfcontent "variable" method. You'll have to actually write the PDF files to your server and then reference them in your action page (either as an HTML link that the user clicks on or as a URL source for your pop-up windows).
Copy link to clipboard
Copied
Another weird thing...
When I open the PDF and then hit save, it does not show the name that I made, it shows the name of the cfm file instead. That is a major problem. Assuming the "create one at a time" workflow, how do I get it to put the right name in the dialog box? The names are dynamically generated, and have file information and dates in them.
Insuractive - I may have to do the page with links, cumbersome, but probably necessary. Thanks for the idea.
Copy link to clipboard
Copied
You can use <cfheader> to create an arbitrary file name for the generated file if you are pushing the file directly to the user's browser. Check out the docs for <cfcontent> that Leigh linked to above for details.