Google Drive PDF Download
This page explains how to download images from Google Drive as a PDF using JavaScript and jsPDF.
Open your Google Drive and select the pdf you want to download
Open the browser console (F12
)
Paste the following code and hit enter:
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);
Wait for the PDF to be generated and downloaded
FAQ
Q: Why do I need to use the browser console?
A: The script interacts with the page’s DOM to find images and generate the PDF.
Q: Can I use this for other file types?
A: This script is designed for images. For other file types, you may need a different approach.
Q: Is this safe?
A: The script uses jsPDF from a trusted CDN and only processes images on the page.
Q: My PDF is blank or missing images!
A: Make sure the images are loaded and visible on the page before running the script.
Q: Can I customize the PDF output?
A: Yes! jsPDF has many options for layout, image placement, and more. See the jsPDF documentation for details.
Last updated on