Drive PDF Downloader

Enables downloading view-only PDF files from Google Drive.

  1. // ==UserScript==
  2. // @name Drive PDF Downloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Enables downloading view-only PDF files from Google Drive.
  6. // @author Irushia
  7. // @license MIT
  8. // @match *://drive.google.com/drive/*
  9. // @match *://drive.google.com/file/d/*/view
  10. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  11. // @grant GM_registerMenuCommand
  12. // @grant GM_unregisterMenuCommand
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Register a new menu command
  19. GM_registerMenuCommand('Download', function() {
  20. let jspdf = document.createElement("script");
  21. jspdf.onload = function () {
  22. let pdf = new jsPDF();
  23. let elements = document.getElementsByTagName("img");
  24. for ( let i in elements) {
  25. let img = elements[i];
  26. if (!/^blob:/.test(img.src)) {
  27. continue ;
  28. }
  29. let canvasElement = document.createElement('canvas');
  30. let con = canvasElement.getContext("2d");
  31. canvasElement.width = img.width;
  32. canvasElement.height = img.height;
  33. con.drawImage(img, 0, 0,img.width, img.height);
  34. let imgData = canvasElement.toDataURL("image/jpeg" , 1.0);
  35. pdf.addImage(imgData, 'JPEG' , 0, 0);
  36. pdf.addPage();
  37. }
  38. pdf.save( "download.pdf" );
  39. };
  40. jspdf.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js' ;
  41. document.body.appendChild(jspdf);
  42.  
  43. });
  44. })();