Prevent PDF auto download by idm using pdf.js

It is possible to prevent download automatically from idm (PdfJs). IDM find extention pdf file so we need to convert pdf file to base-64 and then read base64 of pdf into node DOM src:

1. Convert your file pdf to base64

document.getElementById('myfiles').addEventListener('change', function(event){

		var input = document.getElementById("myfiles"); 

		var fReader = new FileReader();
		fReader.readAsDataURL(input.files[0]);
		fReader.onloadend = function(event){ 
    document.getElementById("base64").innerHTML = event.target.result;
		 console.log(event.target.result); 
     
		}
	});
<input type="file" name="files" id="myfiles" value=""><br>
<textarea id="base64" cols="50"></textarea>

2. get all string base64 put to txt file

filename.txt

3. read base64 from file txt and past into iframe or with viewer.js (PDF JS)

-iframe should

<iframe scr="data:application/pdf,base64.....">prevent download from idm</iframe>

-with PDF viewer

 var xhr = new XMLHttpRequest();
     console.log(file);
     xhr.open('GET', folderFiles+filename+".txt", true);
     xhr.responseType = 'text';
     xhr.onload = function(e) {
     
        if (this.status == 200) {
     
           PDFViewerApplication.open(this.response);     
        
        }
      };

So, IDM won't force download pdf file automatically because it cannot find specific file. link : https://github.com/sokhasen/ViewerPDF.git


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.


try with this

<embed src="'.$baseurl.'/assets/pdf/web/viewer.html?file='.urlencode($pdf_url).'" type="text/html" >

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.