0% found this document useful (0 votes)
2K views2 pages

View Only PDF File From Google Drive

Google has restricted the ability to download view-only PDF files from Google Drive, but a JavaScript code workaround is provided. By following specific steps, users can download shared view-only protected PDFs by rendering the images and saving them as a new PDF file. The resulting PDF will not be editable and may be large due to image content.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views2 pages

View Only PDF File From Google Drive

Google has restricted the ability to download view-only PDF files from Google Drive, but a JavaScript code workaround is provided. By following specific steps, users can download shared view-only protected PDFs by rendering the images and saving them as a new PDF file. The resulting PDF will not be editable and may be large due to image content.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Download view only PDF file from

Google drive
Recently Google made a changes to their policy so that now users can not download view only
pdf file from Google Drive. But now we bring you a simple JavaScript Code by using which,
you can download any view only protected pdf file from Google Drive. by using this code, you
will be able to download shared view only protected pdf from Google Drive
1. Open the view only pdf file in Google Drive in new window
2. Scroll to the bottom of the file so that every page will render
3. Open developer Tools on separate windows by pressing F12 and select Console Tab
4. Paste the following code in the console tab.

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);

Above code will start working and the all the pages present in the file will start rendering. After
some time, pdf should start downloading automatically or will ask to download.
Kindly note that download pdf file will not be editable and may be large in size as it contained
images.

You might also like