This is a hack procedure for Google Drive. Please refrain from using this for those who know computer coding. It involves using internet-codes.
When to use this procedure?
When a friends or teacher gives you the link of PDF in Google Drive and they can only be viewed but can not print, download or copy, these are normally view-only files that can not be downloaded. But, there is a small hack that was working when I prepared this procedure. It doesn’t hack into the system, but takes screenshots and compile into files. So, this procedure is just an automated process of doing it manually.
Only use this procedure when the “download” or “print” options are missing for the documents.
Steps by step procedure to download protected/view-only pdf files from google drive:
1. Open the view-only or protected files in google drive. Let all the pages load. Press PgDn till the last page to download all the pages in the browser.
2. Open your Browser’s Developer Console.
Google Chrome, Firefox or Microsoft Edge – Press Shift + Ctrl + I (on Windows) or Option + ⌘ + I (on Mac)
Apple Safari – Press Shift + Ctrl + I (Windows) Option + ⌘ + C (Mac)
3 Open the “Console” tab.
4 Paste the following code and press Enter (Return)
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];
if (!/^blob:/.test(img.src)) {
continue ;
}
let canvasElement = document.createElement( 'canvas' );
let con = canvasElement.getContext( "2d" );
canvasElement.width = img.width;
canvasElement.height = img.height;
con.drawImage(img, 0, 0,img.width, img.height);
let imgData = canvasElement.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.3.2/jspdf.min.js' ;
document.body.appendChild(jspdf);
5. The document should download.
If you haven’t gone to the last page, only the pages that were opened will download (full document might not download). Sometimes, the quality of the pages might not be adequate if the document is displayed in low resolution. So, you might try zooming the pages to display the high quality version of the document.
What does the command do?
The command converts the image seen on the page into pdf and saves. So, the code searches the image that corresponds to the pages displayed on screen. If the quality of the page being displayed is of low quality, it will save the low quality page.
The command drawImage() creates images in JPEG format and these images are added to pdf by addImage() function. The addPage() creates new page and the process is repeated till the end of the page. This is the reason all the pages should be displayed and should be in required resolution before the command is executed.