Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent PDF auto download by idm using pdf.js

Tags:

I'm using PDF.Js to embed PDF file for preview, and I removed the script of download and open files from the viewer.js , but when I test the page and PDF file try to show, the Internet Download Manager download it and abort the preview .. after search I found that using object instead of iframe may solve the problem, but it didn't work the pdf viewer appeared white, what can I do to prevent auto download ? or using another way (Plugin) to show PDF file content.

<iframe    class="pdf"    webkitallowfullscreen=""    mozallowfullscreen=""    allowfullscreen=""    frameborder="no"    width="'.$width.'"    height="'.$height.'"    src="'.$baseurl.'/assets/pdf/web/viewer.html?file='.urlencode($pdf_url).'"    data-src="'.$pdf_url.'">   '.$pdf_url.' </iframe> 

enter image description here

like image 508
user3003810 Avatar asked Apr 29 '15 20:04

user3003810


People also ask

How do you prevent a PDF from being downloaded?

You can't disable the Download button in your PDF files, and you sure can't prevent the user from choosing Print... in the right-click menu for the entire screen. What you can do is password protect your PDF in Adobe Acrobat. Aside from password protection, their Protect tool also allows you to disable printing.

How do I stop IDM from downloading?

You need to open "Options->General" IDM dialog and press "Edit" near "Customize IDM download panels in browsers". Then enable "Don't start downloading from web-players automatically" option (arrow 1 on the image) and press "OK" (arrow 2 on the image).

How do I force a PDF to auto download?

Scroll to the Privacy & Security settings and click 'Site Settings'. What is this? On the Site Settings page, click 'PDF documents'. On the page that follows, turn on the 'Download PDF files instead of automatically opening them in Chrome' option.


2 Answers

This is not something related to developing issue , this is something related to user specific environement.

The Issue :

Using IDM ,any URL that ends with a media extension (e.g *.JPG , *.PNG , *.MP4 , *.WMV , *.PDF ..etc ) will be downloaded automatically , However on the other hand if the user doesnt have IDM installed , the file will be viewed immediately in browser window.

Possible Solutions :

  1. Remove PDF extension Handler from IDM , to prevent auto download, and i think the image explains it very well.

IDM prevent file types from being handled

  1. Modify response header for your PDF link to force your browser to view pdf inside its view , please consider that each browser may handle the response differently , more details about this method can be found here.

Final Note:

As a developer you shouldnt handle each user specific environment , we suppose that when user installs a specific app to handle generic files , then it is his/her role to handle that application , and not the developer role , cause if you follow this algorithm you jump inside infinite loop handling different users specific setup.

like image 85
ProllyGeek Avatar answered Sep 25 '22 02:09

ProllyGeek


Just remove .pdf Extension from the main file. IDM cannot detect what kind of file it is. but the browser will handle its native way.

like image 39
Arif Avatar answered Sep 23 '22 02:09

Arif