How to download view only PDF from Google Drive

Download_file
Download_file

When a user make a file to view only mode and do share with others then the recipient will not be able to download the same file. But there is a way which helps to download the file. There is a Javascript code which we add in the browser then the file gets downloaded automatically. Please make a Note, this will only help to download view only PDF file in google drive. Below are the steps to be followed:

  1. Open the view only PDF file present in google drive in new window.
  2. Make sure , post opening the file you scroll down to the Bottom of the page.
  3. Press F12 from keyboard or Developer tools in Browser and select Console Tab
  4. Paste the below code inside console
let jspdf = document.createElement( "script" );
jspdf.onload = function () {
let pdf = new jsPDF();
let elements = document.getElementsByTagName( "img" );
for ( let i in elements) {
let img = elements[i];
console.log( "add img " , img);
if (!/^blob:/.test(img.src)) {
console.log( "invalid src" );
continue ;
}
let can = document.createElement( 'canvas' );
let con = can.getContext( "2d" );
can.width = img.width;
can.height = img.height;
con.drawImage(img, 0, 0);
let imgData = can.toDataURL( "image/jpeg" , 1.0);
pdf.addImage(imgData, 'JPEG' , 0, 0);
pdf.addPage();
}
pdf.save( "download.pdf" );
};
jspdf.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js' ;
document.body.appendChild(jspdf);

Post adding the code, file gets starts generating and gets downloaded after sometime. Please note downloaded file may be large in size the file generated is in the form of images from each PDF page. We will not be able to edit the same, since it got converted to image.

Also, Note you will not get accurate result in case the file has large number of pages. I tried it and worked accurately for me upto 150 page.

Thanks. Credit to bwcreativepanipat for the article reference.

Daily Gyan
I am IT professional with more than 9 years of experience. I would try my best to share my experience and knowledge through this Blog. I am also an national level Table Tennis Player