cfdocument: open download prompt to ask user where to save pdf - pdf

I'm using cfdocument to create a pdf. Displaying the pdf in the browser works fine, but I would like to just open a download prompt when the user opens that url.
<cfdocument format="PDF" localUrl="yes" margintop="0.25" orientation="landscape">
What I tried:
I followed this and added a filename: https://community.adobe.com/t5/coldfusion-discussions/how-to-use-cfdocument-create-a-pdf-file-and-save-the-file-in-server/td-p/966276
But it just saves that file in a lucee temp folder.
What I want is that it opens a prompt and asks the user, where he wants to save that file.

I'm pretty sure you can't prompt the "save as" directly. The cause is that nowadays most browsers save the file immediately/directly to the "download" folder by default. For example in Chrome the user can deactivate this behaviour in "Settings -> Downloads -> Ask where to save each file before downloading". A similar setting exists in Firefox.
However, if you don't want to display the PDF in the browser but start a direct download, just add the http headers used for that. This is an example how to achieve it (
I've tested this on Lucee only but should work for ACF the same way):
<cfheader name="Content-Transfer-Encoding" value="binary">
<cfheader name="Content-Disposition" value="attachment; filename=""somefilename.pdf""">
<cfheader name="Content-Type" value="application/pdf">
<cfdocument format = "PDF" pagetype="A4" orientation="portrait">
Just a test for download!
</cfdocument>
If you omit the attribute filename="somefilename.pdf" of the Content-Disposition response header, the name of the url will be taken. Alternatively you could ask the user to specify a name in a form input field and populate that variable. But it still will be downloaded to the "download" directory as specified in the users browser setting.

Related

Open PDF in MediaWiki

In my mediawiki, I can link to internal PDFs using:
[[File:test.pdf]]
But if the user clicks the link, a single page for this file is opened like:
http://localhost/mediawiki/index.php/File:test.pdf
How can I achieve, that the PDF file is opened directly with no other pages in between needed?
You can use the Media: pseudonamespace to link directly to the file:
[[Media:Test.pdf]]
This will link to:
http://localhost/wikimedia/images/d/d3/Test.pdf
The (slight) documentation about this is at: https://www.mediawiki.org/wiki/Help:Links#file-links

Can't display a pdf file in my jsf2 application

I try to display a pdf file on my jsf2 application and the problem is in the path file.
My pdf file is inside a folder named FichesPratiques which is inside another folder named resources (folder resources is inside WebContent) and I use this to display it :
<p:media value="/resources/FichesPratiques/file.pdf" width="100%" height="300px">
but anything is displayed.
and more strange, when I use link below to download it, it doesn't work.
<h:outputLink value="/resources/FichesPratiques/file.pdf">click</h:outputLink> to download pdf instead.
Can someone help me ?
Look closer at the URL generated in the HTML output of those components (rightclick, View Source in webbrowser). In contrary to among others the <h:graphicImage value>, the <p:media value> and <h:outputLink value> do not prepend the web application context path in the URL. The leading / in the URL makes it relative to the domain root of the request URL (the one as you see in browser's address bar).
Imagine that the JSF page is been opened by
http://localhost:8080/somecontext/page.xhtml
Then those value="/resources/FichesPratiques/file.pdf" paths would expect the resource to be present in
http://localhost:8080/resources/FichesPratiques/file.pdf
However, you actually have it in
http://localhost:8080/somecontext/resources/FichesPratiques/file.pdf
You should either be using a valid URL relative to the current request URL,
<p:media value="resources/FichesPratiques/file.pdf" ... />
or explicitly specify the context path in the URL,
<p:media value="#{request.contextPath}/resources/FichesPratiques/file.pdf" ... />

force browser to download a file instead viewing it

On my web I want to have two buttons - first Download that should download a pdf to the user's computer and another View that opens pdf in a new tab. The thing is, I don't know how to make the Download button. You might say that it is useless as you can save pdf after "viewing" it but I have already made graphics like that and don't really want to change it. Is it possible to prevent browser from opening the pdf file and make it download the file instead?
You need to force file download in your server-side script:
Here is a PHP example:
$file = "path/to/my-file.pdf";
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: application/pdf");
header("Content-Transfer-Encoding: binary");
In the end, as I use nginx, I decided to solve this at http-server level:
location /media {
alias /srv/www/novacek/media/;
}
location /download/media {
alias /srv/www/novacek/media/;
add_header Content-Disposition "attachment";
}

While opening file upload dialogue from website, "Folder not accessible, Access denied" error message comes

I am trying to upload files to my website.
Every time when upload dialog opens, it tries to open a default path "C:\Windows\system32\config\systemprofile".
This path is not accessible by every user on all the machines except Admin user.
I even tried to set this default path to "My Documents" but i am not able to get this path runtime.
Thanks in advance !
Don't use the My Documents folder, try using Default User's Documents folder instead.
Also check here for more information:
Exceptions in Yesod

Problem with opening pdf file in site

I have pdf file in serwer and link to it. In local host when i click on link pdf file display in site. On server I've got popup with asking to download file. How to change type from application/octet-stream to application/pdf to display pdf normal on site?
Here is screen after clicking on link:
The reason that the listed solutions are reported not to work half the time, is because using the default MIME association or setting the Content-Type header in <Files> or <FilesMatch> (for the PDF file extension) will have no effect on PDF files that are dynamically transferred via PHP code (i.e., readfile())...
To force a PDF to open in the browser rather than downloading, you should use LocationMatch instead:
<LocationMatch "\.(?i:pdf)$">
ForceType application/pdf
Header set Content-Disposition inline
</LocationMatch>
This way it picks up on transfers that are not direct from the file-system.
If it a unix server add an entry for pdfs in /etc/mime.types, if it's a Windows server, add a mime type in IIS.
Problem solved with using solution from this site:
http://www.thingy-ma-jig.co.uk/blog/06-08-2007/force-a-pdf-to-download
Thanks Joost Evertse