Worked great on Firefox! I had a 300 page document so when I ran the script I didn't think it was working but it took about 5-6 mins for it to download. I think for a large document it takes time and attempts. First couple attempts, it only downloaded a portion of the document. I scrolled to the bottom of the document each time. By the 5th attempt, it downloaded all the pages. Thanks for making this instructional!
let jspdf = document.createElement("script"); jspdf.onload = function () { let pdf = new jsPDF("p", "pt", "a4"); // Using "pt" (points) for precise A4 dimensions let elements = document.getElementsByTagName("img"); const scaleFactor = 2; // Increase for higher quality if necessary // A4 page dimensions in points (default units for jsPDF) const pageWidth = 595; const pageHeight = 842; for (let i = 0; i < elements.length; i++) { let img = elements[i]; if (!/^blob:/.test(img.src)) { continue; } // Create a high-resolution canvas let canvasElement = document.createElement("canvas"); let con = canvasElement.getContext("2d"); canvasElement.width = img.width * scaleFactor; canvasElement.height = img.height * scaleFactor; con.scale(scaleFactor, scaleFactor); con.drawImage(img, 0, 0, img.width, img.height); // Convert canvas to high-quality image data let imgData = canvasElement.toDataURL("image/jpeg", 1.0); // Calculate aspect-ratio-preserving dimensions to fit within A4 let widthRatio = pageWidth / (img.width * scaleFactor); let heightRatio = pageHeight / (img.height * scaleFactor); let fitRatio = Math.min(widthRatio, heightRatio); // Scaled dimensions based on fitRatio let displayWidth = img.width * scaleFactor * fitRatio; let displayHeight = img.height * scaleFactor * fitRatio; // Centering the image on the A4 page let xOffset = (pageWidth - displayWidth) / 2; let yOffset = (pageHeight - displayHeight) / 2; // Add the image to the PDF page pdf.addImage(imgData, 'JPEG', xOffset, yOffset, displayWidth, displayHeight); if (i < elements.length - 1) { // Only add a new page if more images remain pdf.addPage(); } } pdf.save("download.pdf"); }; jspdf.src = 'cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js'; document.body.appendChild(jspdf);
It says: VM1229:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11
the pdf pages im trying to download are a little bit wider and shorter, what is the attributes i should change\play with in order to get it resemble the actual PDF, since im getting it cut on the sides and longer i.e white placeholder at the bottom of each page.
Hi, tried this, it works well but the downloaded file somewhat looks like its been zoom out, like 1/8 of the page. Can't zoom it in since it appear to be blur.
Its not work, please help me Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11
if (window.trustedTypes && window.trustedTypes.createPolicy) { window.trustedTypes.createPolicy('default', { createScriptURL: (input) => input }); } try this then paste the code for pdf
I am getting error- VM278:21 This document requires 'TrustedScriptURL' assignment. VM278:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11
VM568:21 This document requires 'TrustedScriptURL' assignment. VM568:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11 help
If i go for this process the admin who share the file have download protect would be knowing that i am or that emails try to bypassing through java script. I mean the admin knowing or not know about what we are going to do with file download. If i do this process does my admin will know about this through any notification or security privacy .
No they won't. It's all running locally on your PC. The script basically just scans each page and converts them into image, it's all running right at your PC.
If your having trouble downloading the entire PDF make sure your scrolling through the PDF from page 1 to page X so all the pages load up.! Hope This Helps.!
it dosen't work: when I press enter: VM436:21 This document requires 'TrustedScriptURL' assignment. VM436:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11 error not working bro.....
With how i used to do it, press the f12 and just search for "videoplayback" on the search bar on the bottom half, then an mp4 file would pop-up. Then that's what you download. Not sure if it still works since I haven't had the need to download a View Only video from gdrives.
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11 error not working bro.....
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11 error not working bro.....
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment. at :21:11 error not working bro.....
// Create a trusted types policy to handle the script URL safely let policy = window.trustedTypes ? trustedTypes.createPolicy('default', { createScriptURL: (input) => input }) : { createScriptURL: (input) => input }; // Create a script element for jsPDF let jspdf = document.createElement("script"); jspdf.onload = function () { let pdf = new jsPDF(); let elements = document.getElementsByTagName("img"); for (let i = 0; i < elements.length; i++) { 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; // Draw image onto canvas con.drawImage(img, 0, 0, img.width, img.height); // Convert canvas to image data let imgData = canvasElement.toDataURL("image/jpeg", 1.0);
// Add the image data to the PDF pdf.addImage(imgData, 'JPEG', 0, 0);
// Add a new page if there are more images if (i < elements.length - 1) { pdf.addPage(); } } // Save the PDF pdf.save("download.pdf"); }; // Set the src of the script element using the trusted types policy jspdf.src = policy.createScriptURL('cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js'); // Append the script to the body to load it document.body.appendChild(jspdf);
I can't thank you enough Max for this video! It worked.
Worked great on Firefox! I had a 300 page document so when I ran the script I didn't think it was working but it took about 5-6 mins for it to download. I think for a large document it takes time and attempts. First couple attempts, it only downloaded a portion of the document. I scrolled to the bottom of the document each time. By the 5th attempt, it downloaded all the pages. Thanks for making this instructional!
worked on mac/safari. thank you lots. i am preparing for an exam
For some reason it doesn't work on Chrome but it does work on Firefox. Image quality is somewhat low, can this be improved? Thanks.
let jspdf = document.createElement("script");
jspdf.onload = function () {
let pdf = new jsPDF("p", "pt", "a4"); // Using "pt" (points) for precise A4 dimensions
let elements = document.getElementsByTagName("img");
const scaleFactor = 2; // Increase for higher quality if necessary
// A4 page dimensions in points (default units for jsPDF)
const pageWidth = 595;
const pageHeight = 842;
for (let i = 0; i < elements.length; i++) {
let img = elements[i];
if (!/^blob:/.test(img.src)) {
continue;
}
// Create a high-resolution canvas
let canvasElement = document.createElement("canvas");
let con = canvasElement.getContext("2d");
canvasElement.width = img.width * scaleFactor;
canvasElement.height = img.height * scaleFactor;
con.scale(scaleFactor, scaleFactor);
con.drawImage(img, 0, 0, img.width, img.height);
// Convert canvas to high-quality image data
let imgData = canvasElement.toDataURL("image/jpeg", 1.0);
// Calculate aspect-ratio-preserving dimensions to fit within A4
let widthRatio = pageWidth / (img.width * scaleFactor);
let heightRatio = pageHeight / (img.height * scaleFactor);
let fitRatio = Math.min(widthRatio, heightRatio);
// Scaled dimensions based on fitRatio
let displayWidth = img.width * scaleFactor * fitRatio;
let displayHeight = img.height * scaleFactor * fitRatio;
// Centering the image on the A4 page
let xOffset = (pageWidth - displayWidth) / 2;
let yOffset = (pageHeight - displayHeight) / 2;
// Add the image to the PDF page
pdf.addImage(imgData, 'JPEG', xOffset, yOffset, displayWidth, displayHeight);
if (i < elements.length - 1) { // Only add a new page if more images remain
pdf.addPage();
}
}
pdf.save("download.pdf");
};
jspdf.src = 'cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js';
document.body.appendChild(jspdf);
Thanks!
It worked for me in firefox...
Worked like a charm on Firefox, thank you!
Great man straight to the point thanks
Agreed with some others, for Firefox, works like a charm. Thanks dude
Thank you so much!!!!!!!!!!!!!! I really wanted to download a music sheet and this saved me!
Thank you bro. it works 👍
It says: VM1229:21 Uncaught
TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
did you got any solution ??? I am also getting the same error.
@@dashMusic-06 no i didn't😢
use firefox instead of chrome
if (window.trustedTypes && window.trustedTypes.createPolicy) { window.trustedTypes.createPolicy('default', { createScriptURL: (url) => url }); } let jspdf = document.createElement("script"); jspdf.onload = function () { let pdf = new jsPDF(); let elements = document.getElementsByTagName("img"); for (let i = 0; i < elements.length; i++) { let img = elements[i]; if (!img.src || !/^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, img.width, img.height); if (i < elements.length - 1) { pdf.addPage(); } } pdf.save("download.pdf"); }; jspdf.src = 'cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js'; document.body.appendChild(jspdf);
try safari, mine doesn't work for chrome but works for safari
this is first time when the first video is enough for something thanks bro you are super cool 😍😍😍😍
thank you brother. your video helped a lot. our teacher is greedy and wont let us download this pdf so its hard to read out side. thank you again
doesn't work on Firefox,
On MS EDGE - The script is allowed but at last I got an error saying "TruescriptURL" needed
something like that
Please Help
try in safari or in firefox
I tried it on Firefox and it worked
Its working on Firefox thanks dude🔥🔥
the pdf pages im trying to download are a little bit wider and shorter, what is the attributes i should change\play with in order to get it resemble the actual PDF, since im getting it cut on the sides and longer i.e white placeholder at the bottom of each page.
omg , thank you, it is working, thank you, it worked with chrome ❤❤❤
Bro the file is downloaded but the quality of pdf decrease can give any suggestions of tp fix this
Thank you! worked wonders
thank you. it works.
Exceleeeeeent! It worked on google!!
Hi, tried this, it works well but the downloaded file somewhat looks like its been zoom out, like 1/8 of the page. Can't zoom it in since it appear to be blur.
found the solution?
@@OutOfTheCommon-nx2ff Use above code to get quality output!
@@OutOfTheCommon-nx2ff I have got the solution for that but can't paste in the comment box, text your email
Its not work, please help me
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
i have this this problem too
if (window.trustedTypes && window.trustedTypes.createPolicy) { window.trustedTypes.createPolicy('default', { createScriptURL: (input) => input }); } try this then paste the code for pdf
I am getting error-
VM278:21 This document requires 'TrustedScriptURL' assignment.
VM278:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
VM568:21 This document requires 'TrustedScriptURL' assignment.
VM568:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
help
same lol
work perfect on firefox, firt you need typing allow pasting on console :)
for me does not work on opera and chrome.
work well thank you very much!
I hope it's not a virus i'm not sure if tohse files' worth having my every password stolen
btw worked like a charm on firefox it keeps givin error on chrome for sm reason
VERY USE FULL , tHANKS
Thanks, it saved me 50 buks
If i go for this process the admin who share the file have download protect would be knowing that i am or that emails try to bypassing through java script. I mean the admin knowing or not know about what we are going to do with file download. If i do this process does my admin will know about this through any notification or security privacy .
Will the file owner know if I do the hack?
No they won't. It's all running locally on your PC. The script basically just scans each page and converts them into image, it's all running right at your PC.
@Yosuru thank uuu ✨
If your having trouble downloading the entire PDF make sure your scrolling through the PDF from page 1 to page X so all the pages load up.! Hope This Helps.!
IT WORKED! THANK YOU SO MUCH
Which browser?
great, thanks and to disable it again?
THANK U SO MUCH
worked but got only first 3 pages out of 16, any suggestions ?
Try scrolling through the entire PDF first to make sure it is all loaded. If not, here is another way: th-cam.com/video/4vHsnltJdA8/w-d-xo.html
Thanksssssss it worked!!!
it dosen't work: when I press enter:
VM436:21 This document requires 'TrustedScriptURL' assignment.
VM436:21 Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
same problem here
You used edge?
@@mahmudtalkssyou used edge?
I use brave. doenst work have the same issue
Try opening in your Google drive account. Login to your gdrive acc and then open the file. Fully load it and hit F12, paste the codes and enter.
Uncaught syntax error: redeclaration of let jspdf
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
error not working bro.....
did you get a solution
works perfect on firefox
How to download vides like this ?
THANKS BROOOO!!!
awesome thanks
its only downloading the blank page
Thanks a lot it work
what browser do you use?
it will not download Orginal quality
Doesn't work on Chrome. Worked on Safari. Thanks!
Works with Brave browser too
it worked but many pages were missing
first you have to scroll down till the last so that every page is loaded
THANKSSSSS
It works on Safari. (not with Chrome)
how to download videos
With how i used to do it, press the f12 and just search for "videoplayback" on the search bar on the bottom half, then an mp4 file would pop-up. Then that's what you download. Not sure if it still works since I haven't had the need to download a View Only video from gdrives.
I have the same error
it works on firefox
thks brow
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
error not working bro.....
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
error not working bro.....
Uncaught TypeError: Failed to set the 'src' property on 'HTMLScriptElement': This document requires 'TrustedScriptURL' assignment.
at :21:11
error not working bro.....
use safaari browser
// Create a trusted types policy to handle the script URL safely
let policy = window.trustedTypes ? trustedTypes.createPolicy('default', {
createScriptURL: (input) => input
}) : { createScriptURL: (input) => input };
// Create a script element for jsPDF
let jspdf = document.createElement("script");
jspdf.onload = function () {
let pdf = new jsPDF();
let elements = document.getElementsByTagName("img");
for (let i = 0; i < elements.length; i++) {
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;
// Draw image onto canvas
con.drawImage(img, 0, 0, img.width, img.height);
// Convert canvas to image data
let imgData = canvasElement.toDataURL("image/jpeg", 1.0);
// Add the image data to the PDF
pdf.addImage(imgData, 'JPEG', 0, 0);
// Add a new page if there are more images
if (i < elements.length - 1) {
pdf.addPage();
}
}
// Save the PDF
pdf.save("download.pdf");
};
// Set the src of the script element using the trusted types policy
jspdf.src = policy.createScriptURL('cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js');
// Append the script to the body to load it
document.body.appendChild(jspdf);
doesn't work with google slides. same error