Tagged: ,

Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #783991

    Hi !
    I’d like to add a button or an image to download a pdf file when I click on it (not open in a new tab, but download directly). Is there a way to do this ?
    Thanks,
    Franck

    #785046

    Hey SphereEvenements,

    Could you please give us a link to your website, we need more context to be able to help you.

    Best regards,
    Victoria

    #786252

    Hi Victoria,
    For sure : http://www.sphere-evenements.com/
    Thanks,
    Franck

    #786328

    here is something i found on this thematic:

    You can’t do this with HTML.
    It’s a server-based solution. You have to stream the file so that the browser than triggers the save dialog.

    I’d advise not doing this. How a user interacts with a PDF should be left up to the user.

    And i do agree to that on security reasons. (pdf bomb)

    PS: on html5 now it seems to be able to do that . But on the security reasons i stay on my oppinion that it is a “no go” –
    Link : https://developers.google.com/web/updates/2011/08/Downloading-resources-in-HTML5-a-download

    but you can do it with zip files – than the user has the opportunity to have a first look to the downloaded zip file (Antivirus etc.)

    • This reply was modified 7 years, 2 months ago by Guenni007.
    #786595

    Hi,

    thanks as always @Guenni007 :)


    @SphereEvenements

    Let us know if the link he provided is useful to you. In general it’s more about a WordPress question than a theme related one. So maybe there is a plugin out there for you. You could also ask this in general WP support forum, as they may know a solution for you.

    Best regards,
    Andy

    #787686

    Hi @guenni007 and @Andy,
    Thank you for your response. I’m not sure I understand why it is “dangerous” to do this with HTML ?
    Thanks,
    Franck

    #787719

    Is there a security problem if I add a htaccess in the folder of my pdf with this ?
    AddType application/octet-stream .pdf
    Thanks
    Franck

    #788115

    Hi,

    No, there shouldnt be any issue at all with that.

    Best regards,
    Basilis

    #788368

    try first to set a link with for example:
    you see in the link the download=””

    <a href="https://domain.de/xyz.pdf" download="Aufsatz_ueber_Nettiquette.pdf">Nettiquette</a>

    this will be the html5 method and it works now on Firefox, Safari, Opera, Chrome : https://webers-testseite.de/kokon/this-is-a-post-with-post-type-link/

    Or for a globaly solution: you use this in htaccess file:

    <FilesMatch "\.(?i:pdf)$">
        # Force File Download
        ForceType application/octet-stream
        Header set Content-Disposition attachment
    </FilesMatch>
    • This reply was modified 7 years, 2 months ago by Guenni007.
    #788380

    if you like to include other files to do the same:

    <FilesMatch "\.(?i:(pdf|xls))$">
        # Force File Download
        ForceType application/octet-stream
        Header set Content-Disposition attachment
    </FilesMatch>

    you know that from the rule concerning to cors :

    <FilesMatch "\.(ttf|otf|woff)$">
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule>
    </FilesMatch>
    • This reply was modified 7 years, 2 months ago by Guenni007.
    #790110

    Thank you Guenni, but what is the difference between my htaccess code and yours ?
    Thanks,
    Franck

    #790142

    you mean your one liner : AddType application/octet-stream .pdf
    if it works – ok.
    but some browsers have some trouble with .PDF or the IE does something else you are intend to do.
    I think the code will work browser independent:

    <FilesMatch "\.(?i:pdf)$">
        # Force File Download
        ForceType application/octet-stream
        Header set Content-Disposition attachment
    </FilesMatch>

    to be more precise it should be:

    <FilesMatch "\.(?i:pdf)$">
    <IfModule mod_headers.c>
        ForceType application/octet-stream
        Header set Content-Disposition attachment
    </IfModule>
    </FilesMatch>

    but test yourself
    btw: the ?i: is for beeing independent from upper/lowercase combinations.

    • This reply was modified 7 years, 2 months ago by Guenni007.
    #793429

    Ok thank you @Guenni007

    #793542

    Hi,

    Has that worked, do you need anything else from us?

    Best regards,
    Basilis

    #793795

    Hi,
    No thank you very much for your help !
    Franck

    #793862

    Hi Franck,

    Great, glad we could help :-)

    Best regards,
    Rikard

Viewing 16 posts - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.