Skip to content

Instantly share code, notes, and snippets.

What would you like to do? Scanned Book Downloader Bookmarklet Scanned Book Downloader Bookmarklet

A simple "1-click" javascript approach to downloading a scanned book from to read at your leisure on the device of your choosing w/out having to manually screenshot every pages of the book by hand. In short it's a glorified "Save Image As..." approach but consolidated down to "1 click". BTW there may be a much better option than this out there - I just built this as an autistic project to see if it would work.

Demo Video SBDL Demo

Obligatory Legal/Disclaimer:

By using this script you agree to delete all book files/images after your 1 hour or 14 days is up! I don't support using this script for any other use cases. After all, none of us have ever kept a library book past it's return date, right?


  • Scanned Books Only: This only works on "scanned" books where each page is an image file. This means A) you won't be able search the text of the book and B) the book file size will be tens of megabytes not kilobytes like an EPUB/etc. Given the above always try to find the book in text format first (epub, etc) before using this method.
  • Compatibility: As of 11/2021 I've tested this on a few books w/no problems so it seems pretty stable but if someone finds a book that doesn't work w/it LMK in comments. It's very possible (likely?) at some point will change something that either requires some adjustments to this script and/or makes this approach no longer possible. Feel free to recommend tweaks or fixes if anyone has any suggestions btw.
  • Borrowed and?: I've only tested this for "Borrowed" books but I suppose you could use on Free books too - although normally those already offer a PDF download so not really a reason to do that.
  • Support: This is just a basic javascript thing so there's no real danger here but I can't/don't provide any support if this doesn't work for you and/or your browser crashes while trying it.


  1. Create a bookmarklet in your browser using the code below via
  2. Go to and "Borrow" the book for 1 hour or 14 days (only tested with the 1 hour)
  3. Once the borrowed book page reloads click zoom icon to zoom into the 1st page of book at least 2 times (otherwise you'll get low-res version of book images)
  4. Write down or make a mental note of how many pages the book has
  5. Use browser's "Inspect Element" on first page of book to find the page image URL and right-click to "open link" in a new tab.
  6. Once on the new tab looking at the book's 1st page image, click the bookmarklet button made in step 1 and type in the number of pages the book has that you noted in step 4. Tip: Add 5-10 more pages than the book has just in case the covers/final pages of the book actually add up to a higher number.
  7. As soon as you click 'OK' after entering the page count watch for the browser's "Allow Multiple Downloads from this Site" type message in your browser and click 'Accept' or whatever. Otherwise the process will fail. Some browsers may not do this - so disregard if this isn't an issue w/your browser.
  8. Wait for the process to finish - a 300 page book takes around 3-5 minutes. Note: You can minimize the browser tab/window while the pages are downloading.
  9. Once all pages have been downloaded an "alert" message will popup when the pages have all been downloaded.
  10. At this point you'll have a bunch of book page images in your Downloads folder like mybookwhatever_000.jpg, mybookwhatever_001.jpg etc.
  11. If you want to make a PDF of the pages go to and drag all these images into the upload area. When the images are uploading click the "A-Z sort" button at the bottom of the page to make sure the pages sort by filename.
  12. Click the "Create PDF" button when it's ready and download the PDF when it's done.
  13. Now you can enjoy reading the book at your leisure, wherever you want without having to wait for the annoying page load times of, etc!
function downloadFile(filePath){
    var link=document.createElement('a');
    link.href = filePath; = filePath.substr(filePath.lastIndexOf('/') + 1);;

function getNewURL(pageCount){
	if(pageCount == null) pageCount = 1;
	var url = document.location.href; 	
	var urlParts = url.split(".jp2");	
	var urlPrefixParts = urlParts[0].split("_");	
	var urlPageNumber = urlPrefixParts[urlPrefixParts.length-1];	
	var nextPageNumberString = String(parseInt(urlPageNumber)+pageCount).padStart(4,'0');  	
	var newURLPrefix = ''; 
	for(var p=0;p<urlPrefixParts.length-1;p++) newURLPrefix += urlPrefixParts[p] + '_';	
	var newURL = newURLPrefix + nextPageNumberString + '.jp2' + urlParts[1];	
	return newURL;

var confirm1 = confirm(' Scanned Book Downloader:\n\nReady Check: Are you on a window/tab viewing *just* the IMAGE of the 1st page of the book? If not cancel and run this when you are.');
if(!confirm1) return false;
var pageCount = prompt(' Scanned Book Downloader:\n\nHow many pages are in this book?');
var pageCounter = 0;
var pageInterval = null;
if(pageCount == null || pageCount == undefined || parseInt(pageCount) == NaN){
   console.log('no page count provided.. giving up.');
	pageInterval = window.setInterval(function(){	
		if(pageCounter > parseInt(pageCount)){
			pageInterval = null;			
			console.log('downloading done!..');			
			var pdfTime = confirm('All pages downloaded! (some files may still be downloading though)\n\nWould you like to go to a site to create a PDF with them now?');
			var nextFile = getNewURL(pageCounter);
			console.log('downloading next page! (' + nextFile + ')');
		pageCounter += 1;
Copy link

@cemerson, thanks so much for creating this script (and the instructions to go with it so twits like me can use it)!
As others have said, I'll be deleting the 'book' as soon as I've referenced the sections I need to. I'm just glad I don't need to wrangle with awful DRM to do this.

@nenabunena @agatakotecka - confirming that I've just successfully run the script on the latest version of Brave [Version 1.43.93 Chromium: 105.0.5195.127 (Official Build) (64-bit)].

I was getting the same error some people referred to further up the conversation ("0NaN.jp2undefined" appearing as the 'filename' for every empty file) and I discovered it was because I'd opened the thumbnail version of the first page of the book in a new tab. Of course, the script was expecting a different URL and it broke.

The key for me was looking at the video again and identifying exactly what class the line @cemerson selected was declared as (note - it's 'BRpageimage' with no quotation marks). This is unique to the correct image, so you can follow the below steps to ensure you also get it right :)

  1. Complete the 'inspect element' steps (you need to click on the header of the page to do this - right clicking on the book image you're looking at won't work)
  2. Click into the console i.e. the text you're looking at trying to locate the correct image link and press CTRL + F to search/filter
  3. Type (or copy/paste in) 'BRpageimage' with no quotation marks and you'll be taken to the correct line
  4. Right click on the image URL/link (preceded by src=, it will start with https:// as with any URL) and select 'Open in a new tab'
  5. You're in business! NOW, on the new tab you just opened (you should see a LARGE image of the first page of your new book), run the bookmarklet you created and added to your bookmarks bar and follow the prompts.

Hope this helps someone else. Enjoy and happy reading.

Copy link

Thank you @Alchemytr for sharing all those details w/people - hopefully that will help folks having issues. Very glad it worked for you too btw :)

Copy link

Thanks @Alchemytr & @cemerson I was able to get the book by following this, copy/paste the link which didn't work for some books before or perhaps I did it wrong before. I will try this new method, thank you so much for taking the time to figure it out for me! Because I am sure I will use this very soon & update everyone how it goes!

Copy link

miluoshi commented Dec 14, 2022

For me the original script didn't work, because page url didn't contain text .jp2. It was in this format:<id>/mode/1up?view=theater

the following getNewURL worked:

function getNewURL(pageCount) {
  if (pageCount == null) pageCount = 1;
  var firstImageURL = document.querySelector('.BRpageimage').src;
  var newURL = new URL(firstImageURL);
  var filePath = newURL.searchParams.get('file');
  var idLength = filePath.match(/_(\d+)\.jp2/)[1].length;
  var newFileParam = newURL.searchParams.get('file').replace(/_\d+\.jp2/, `_${String(pageCount).padStart(idLength, '0')}.jp2`);
  newURL.searchParams.set('file', newFileParam);
  return newURL.origin + newURL.pathname + decodeURIComponent(;

It reads url of the 1st image and generates url for following pages by replacing page number in the 1st image url.

Copy link

Yupoman commented Dec 29, 2022

For those who do not understand (like me) how to add the bookmark, just copy and paste the code that is at the end in the main box of that page "mrcoles", click on "convert" and simply drag where it says "this link" to the markers.

Copy link

Xekep commented Jan 6, 2023


function getNewURL(pageCount) {
  if (pageCount == null) pageCount = 1;
  var url = document.location.href;
  url = url.replace(/_(\d+)\.jp2/, "_" + ("0000" + pageCount).slice(-4) + '.jp2' );
  return url;

Copy link

Hey @agatakotecka - I just tested using Brave (basically Chrome) and it did work and also tried in Firefox which also worked for me. It's possible your browser version or something else is causing an error - maybe try a Chrome browser? It's also possible some books have something unique about them that causes the script to fail - if you have a book that isn't working let me know and I'm happy to try it for you. GL.

@cemerson, could you please help me with this 2 books? &
I am using Chrome Browser. I cannot find the correct inspect element

Copy link

Just tested with Firefox 109 on macOS Ventura 13.2 and it worked fine.

The suggestion by @mikkovedru to set a download file is vital, otherwise you'll be prompted to save each page.

BTW, on macOS you can assemble PDFs using Preview. Just select all files and open with Preview, check page order because sometimes a few are mixed up, and then export as PDF.

Copy link

why not create a browser extension for this?

Copy link

Hey, I've gotten as far as setting up the bookmarklet, I'm just stuck trying to find the 1st-page url while inspecting the element. I don't understand code, can anyone help a bit?


Book link:

Book title:
The Waffen SS : Hitler's elite guard at war 1939-1945

I'm using chrome, Ive pasted the code and I get the prompt asking me if I am on the page with JUST the first image. Any help would be greatly appreciated.

Copy link

cemerson commented Mar 22, 2023

@Rangerrick2018 Normally when just 1 image downloads it is because you didn't set the site to allow multiple downloads - sometimes this prompt can be easy to miss/dismiss.

Anyhow - it looks like someone else has already pulled that one here :)

Interesting book btw - may add that to my list to check out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment