Skip Navigation

[Resolved] Force PDF download

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Minesh 6 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#613046

I am trying to force all PDF links to download instead of open in a browser. I am able to easily accomplish this using the "download" attribute in an <a> tag, but that only works in Firefox & Chrome. I need to be able to have this work on iOS.

I've tried the followng .htaccess rule in the wp-content/uploads folder and that didn't work:

AddType application/octet-stream pdf

I've read a few places to use php to force the PDF download, I'm just not sure where to put it because the PDF link is dynamically generated since it's a custom post type field. Any suggestions?

#613119

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

What if you try to add following line to your .htaccess file:

AddType application/octet-stream .pdf
#613507

Hello Minesh,

As I stated in my initial statement, I have already tried to add that line to my .htaccess and it didn't work. I am thinking of using a different approach but not sure what steps to take. I would like to be able to click on the PDF Link and have it appear in a popup window PDF viewer. I have tried several different plugins but the issue that I'm coming across is the PDF url is the raw output of a custom field, which isn't registering from within other plugin shortcodes.

[pdfviewer width="600px" height="849px" beta="true/false"][types field='transcript-upload' link='true' output='raw'][/types][/pdfviewer]

Most of the other pdf viewer plugins I've tried have the shortcode with the url inside of the brackets like in the following example:

[tnc-pdf-viewer-iframe file="[types field='transcript-upload' link='true' output='raw'][/types]" width="" height="" download="true" print="false" fullscreen="true" share="false" zoom="true" open="true" pagenav="true" logo="false" find="false" current_view="true" rotate="true" handtool="true" doc_prop="true" toggle_menu="true" language="en-US" page="" default_zoom="auto" pagemode=""]

How can I use the information in this article: https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/ to apply to my situation?

#613607

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

As I stated in my initial statement, I have already tried to add that line to my .htaccess and it didn't work.
==> Well - the code you were using and I've asked to apply has little change - could you please copy paste the code I shared and check.

The code you are using is wrong - if you just want to output the URL - you should not use the "link" attribute. I do not see there is any link attribute available.

Following code should work:

[pdfviewer width="600px" height="849px" beta="true/false"][types field='transcript-upload' output='raw'][/types][/pdfviewer]

If you output the following shortcode and if it gives you the PDF URL then it depends on the plugin you used how it parse the shortcode, its not controllable by Toolset as its third party plugin.

[types field='transcript-upload' output='raw'][/types]

But - you should not have to use different plugin to force download the PDF, the code I shared should work.

#613914

Thank you for your help, I was so hopeful that it would work but unfortunately none of the fixes worked. I even tried to add that code to a new .htaccess file in the uploads directory but still no luck. And even with the shortcode change, the 3rd party plugin still wouldn't recognize it as a valid URL.

#614138

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please share problem URL where you've added the link to force download PDF.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.