ndm234234/scriptorium-epub
About
The best possible PDF to EPUB conversion, with no compromise on quality: every page recognised twice and checked against the text layer. Plus your own library server: catalog, reader and sync on every device.
Design & MediaWhat you can do
- Instant search across title, authors, series, description and file path (case-insensitive, ё = е, all words must match). / focuses search, Esc clears it.
- Click an author to see all their books.
- Sort by recently opened (the default, in the app and in a browser tab alike: the book read last comes first, then books not opened yet; with an account, on every device), author, title, recently added or size; optional grouping by author. A sort you choose is kept. Settings are remembered.
- One rule for every book: the cover (or the title) shows the book's page, the Read button under it starts reading straight away (one tap on a phone). The download icon next to Read saves the EPUB file: Chrome/Edge (via the launcher) show a dialog to choose the folder; other browsers download it as usual.
Measured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
OriginalScriptorium EPUB
A home scriptorium for e-books: small Python scripts that turn PDFs into EPUB and keep an EPUB collection in order.
The main goal is the best possible PDF → EPUB conversion, with no compromise on quality. Every page is read from its picture twice by a recognition engine and checked word by word against the PDF text layer. The book should come out as if a person who sees the page had carefully retyped it: real paragraphs, joined hyphenation, bold and italic, headings, lists, tables, formulas, footnotes and the book's own table of contents. Not a line is lost and no word is made up. Speed is not a goal: a long book may take a night, and a stopped run goes on from the same page.
Your own library server, in one double-click
make_server.py turns any folder of EPUBs into a personal online library: a catalog with
covers, search and a built-in reader. Next to it go the launchers: double-click
Open Library (network) and the library is up. It opens on your phone, tablet and laptop over home
Wi-Fi, and from anywhere in the world when your router forwards a port to it over https. It needs
nothing to install, no cloud and no subscription, and the books never leave your computer.
- Accounts and sync: each reader signs in once per device and finds their reading place, bookmarks, folders and recently opened books on every device.
- Folders: group books into folders (the folder button under every cover and on the book's page) and download a folder's books as one ZIP (from the library's server).
- Favorites: a star under every cover and on the book's page puts the book in Favorites, a folder that comes first.
- Share: a button on every book and on its page sends a link that opens that book's page in the library (on the https address; on a computer it copies the link).
- An app on the phone: install the library like an app and keep books on the device to read offline.
- Only for your people: devices that are not signed in see only the sign-in page, and the launcher's window shows who is reading what.
See Open Library launchers for the details.
The scripts
epub_rename.py— copies books fromIn/intoOut/Books/<Author>/<Author> - <Title>.epub, using the author and title stored inside each book, and verifies every copy.make_server.py— buildsindex.html, a catalog of a book folder with covers, search, sorting and a built-in reader, plus the launchers that serve it as your own library server (above). It runs automatically at the end ofepub_rename.pyand can also be used on its own for any folder.fix_cover.py— makes sure every book has a cover that readers and catalogs can find: marks the cover picture when the book doesn't, or draws one from the title and author, removes references to files the book doesn't contain, and repairs a first page that shows a missing picture instead of the cover and pages that strict readers can't open. Asks before changing each book.pdf2epub.py— turns PDF books fromPdf/into EPUB files inIn/, ready forepub_rename.py: real paragraphs instead of printed lines, headings and table of contents, lists, tables, pictures, the first page as the cover. Reads every page with a free offline recognition engine (installed by the script on first run), or just the PDF text layer in quick mode.epub_diff.py— compares two versions of a book (say, yesterday's and today'spdf2epub.pyresult) and lists what changed, sorted by kind — recognition garbage and loops, text missing or added, words read differently, formulas, pictures, punctuation, metadata — each with the PDF page it is on, so it can be checked by eye:python3 epub_diff.py old.epub new.epub [--html report.html] [--all]. The PDF is found inPdf/by the book's file name (or given with--pdf). It also shows both file sizes and, when the files differ but the book doesn't, why (pages written differently with the same words, the archive recompressed — whatfix_cover.pydoes).
No dependencies besides Python (pdf2epub.py also needs the free
Poppler tools). Pillow is optional
(used to shrink covers for the catalog, and by fix_cover.py to draw missing covers).
Quick start
git clone https://github.com/ndm234234/scriptorium-epub.git
cd scriptorium-epub
mkdir In # put your .epub files here
python3 epub_rename.py # sorts books into Out/ and builds Out/index.html
Then open Out/index.html in a browser.
Requirements
- Python 3.11 or newer
- Optional: Pillow —
pip install pillow(without it covers are copied at full size) - For
pdf2epub.pyonly: Poppler —sudo apt install poppler-utils(Linux),brew install poppler(macOS), or on Windows poppler-windows with itsLibrary/binfolder added toPATH - For the recognition in
pdf2epub.py(its default mode): Linux (x86-64) and Python'svenvmodule, and the OpenMP library — on Debian/Ubuntusudo apt install python3-venv libgomp1(a fresh WSL2 Ubuntu lacks both). Everything else (Marker, its own Python, the models) the script installs by itself on the first run.
Works on Linux, macOS and Windows; the recognition in pdf2epub.py is Linux-only for now
(on macOS and Windows it uses quick mode).
On a new Linux machine
sudo apt install python3 python3-venv libgomp1 poppler-utils
git clone https://github.com/ndm234234/scriptorium-epub.git
cd scriptorium-epub
mkdir Pdf # put your .pdf files here
python3 pdf2epub.py # first run: installs the engine (~3 GB, needs internet once)
epub_rename.py
python3 epub_rename.py
In/ and Out/ are taken from the current folder: run the script where your In/
folder is. Out/ is created automatically. Books go into Out/Books/; the catalog
(index.html, the "Open Library" launchers) sits in Out/ itself. Books left in Out/ outside
Books/ (the old layout) are listed with a warning: move their folders into Out/Books/.
In/ Out/
├── a8f3k2.epub ──► ├── Books/
├── x91bd0.epub │ ├── Clara Whitmore/
└── q7mm41.epub │ │ ├── Clara Whitmore - The Lantern Keeper.epub
│ │ └── Clara Whitmore - Paper Harbors.epub
│ └── Oskar Brandt, Mila Fenwick/
│ └── Oskar Brandt, Mila Fenwick - The Clockwork Orchard.epub
├── index.html
└── .index/covers/
What it does
- Reads metadata (
dc:creator,dc:title) from each EPUB. - Safe file names — characters forbidden on Windows/Linux (
< > : " / \ | ? *, control characters) are removed, as well as trailing dots/spaces and reserved names (CON,NUL, …). Long names are trimmed to fit file system limits. - Unifies author names:
Whitmore, Clara→Clara Whitmore(exactly one comma means "Last, First");WHITMORE CLARA→Whitmore Clara(all caps → normal case);- the same author written with a different word order, case or
ё/еgoes into one folder; an existing folder inOut/Books/wins.
- Co-authors — all authors are used, separated by commas; with more than two
authors the first two are kept followed by
и др.("et al."). - Source files are never modified — books in
In/are only read; their SHA-256 is checked before and after copying. The script refuses to run ifInandOutoverlap. - Every copy is verified byte for byte (SHA-256 and size); a bad copy is removed.
- Re-running is safe:
- identical file already in
Out/→ skipped, not rewritten; - different file with the same name → overwritten.
- identical file already in
Output
While working, a single progress line is shown. At the end the results are grouped:
📚 Found 5 epub file(s) in In/
✅ New (1)
[1/1] d.epub → Theo Lindqvist/Theo Lindqvist - Notes from the Quiet Hour.epub
🔄 Overwritten — existing file was different (1)
[1/1] b.epub → Clara Whitmore/Clara Whitmore - Paper Harbors.epub
🟰 Identical — already in Out, skipped (2)
[1/2] a.epub → Clara Whitmore/Clara Whitmore - The Lantern Keeper.epub
[2/2] c.epub → Ada Merriweather/Ada Merriweather - The Salt Road.epub
❌ Errors (1)
[1/1] zz.epub — can't read metadata: File is not a zip file
✨ Done: ✅ new 1 · 🔄 overwritten 1 · 🟰 identical 2 · ❌ errors 1
🔒 All copies verified by SHA-256, source files untouched
Exit code: 0 — no errors, 1 — bad folders, 2 — some books failed.
Settings
Constants at the top of epub_rename.py:
| Constant | Default | Meaning |
|---|---|---|
IN_DIR, OUT_DIR |
In, Out |
source and destination folders |
UNKNOWN_AUTHOR |
Unknown Author |
folder for books without an author |
AUTHOR_SEPARATOR |
", " |
between co-authors |
MAX_AUTHORS_SHOWN |
2 |
more authors than this → shortened |
ET_AL |
" и др." |
suffix for shortened author lists |
make_server.py
python3 make_server.py [FOLDER] [--title "My Library"]
Scans FOLDER (default: Out in the current folder) recursively and writes:
FOLDER/index.html— the catalog page;FOLDER/.index/covers/— small cover copies (reused on the next run; covers of removed books are cleaned up);FOLDER/.index/reader/— the reader (copied fromreader/next to the script);FOLDER/Open Library.bat,FOLDER/Open Library.shand their(network)versions — launchers (fromlaunchers/), withlibrary_sync.pyandlibrary-sync.ps1, the code behind accounts and sync (below), andsignin.html, the network library's sign-in page.
EPUB and PDF files are only read. Keep .index/ next to index.html when moving the catalog.
PDF beside EPUB. A PDF in the same folder and with the same name as an EPUB
(Jane Doe - A Quiet Harbour.epub + Jane Doe - A Quiet Harbour.pdf, case aside) is the same
book in another format: one card, read in EPUB, both files offered for download. A PDF with no
EPUB is a book of its own: its author and title come from an Author - Title file name, its cover
is its first page (drawn by pdftoppm from poppler, if installed), and it has no Read button,
only Open PDF (it and the cover open the PDF in a new tab, in the browser's own viewer). Folders starting with . are skipped.
Catalog features
- Cover grid; books without a cover get a generated placeholder.
The cover is found the way readers find it: the book's cover mark (EPUB 3
cover-image, EPUB 2<meta name="cover">), the guide's cover page, a picture named "cover", or the picture on the first page (many converted books have only that). Marks that point to files missing from the book are skipped. Transparent PNG covers are put on white. Many books mark a tiny cover (e.g. 126×200) and keep the same picture full size elsewhere (usually on the first page): then the big copy is used, so covers stay sharp on the book's page. - Title, authors, series, year, publisher, file size, and the book's formats: small EPUB and PDF labels on the card and on the book's page (a click on EPUB saves the file; a click on PDF opens it in a new tab, and the right button's Save link as… saves it). On the book's page a book in both formats has two buttons, EPUB (save) and PDF (open in a new tab); a folder's ZIP holds both files. The offline app keeps only EPUBs on the device.
- The app's theme, shared with the reader: Auto (the system's light or dark, following it as it changes) · light · sepia · dark. The button next to the library's name cycles them and shows the choice: an "A" in a circle, a sun, a warm sun, a moon (turning from one to the next, unless the system asks for less motion). The reader's theme button is the same setting.
- Instant search across title, authors, series, description and file path
(case-insensitive,
ё=е, all words must match)./focuses search,Escclears it. - Click an author to see all their books.
- Sort by recently opened (the default, in the app and in a browser tab alike: the book read last comes first, then books not opened yet; with an account, on every device), author, title, recently added or size; optional grouping by author. A sort you choose is kept. Settings are remembered.
- One rule for every book: the cover (or the title) shows the book's page, the Read button under it starts reading straight away (one tap on a phone). The download icon next to Read saves the EPUB file: Chrome/Edge (via the launcher) show a dialog to choose the folder; other browsers download it as usual.
- The book's page: the cover flies from the shelf to the left and the description slides in on
the right (or "This book has no description."), with Read and Save buttons. A click on
the title copies it.
Esc, the Catalog button or the browser's Back return to the shelf at once, without animation; leaving the reader brings you back to the book's page.Ctrl+click / middle click on a cover opens the reader in a new tab. With "reduce motion" turned on in the system there is no animation. - Folders: your own sets of books, e.g. "To read" or "Holiday" (each person has their own; they are names in the catalog only, nothing on disk moves or changes). The first one is made from a book's page: Folders next to Read lists your folders with a tick box each (tick to put the book in, untick to take it out, it takes effect at once) and + New folder. A book can be in several folders; its card shows their names under the author (two, then "+N"; inside a folder, the others), and its page shows them as chips: a tap opens that folder. Then a strip of chips appears under the search: your folders by name with their counts, + for a new folder, Unfiled (the books in none of them) and All (all books) at the right end. The chips wrap onto as many rows as they need; on a computer the strip stays at the top with the search bar, on a phone it scrolls away with the list while the bar stays. A tap on a folder (or on Unfiled) shows only its books (search, sort and grouping work inside it; Back returns to All books). The open folder's ⋯ renames it or deletes it (it asks first; the books stay in the library, and a deleted folder stays deleted). Names are up to 60 characters and two folders can't share a name (whatever the case). With an account (below) your folders are the same on all your devices; without one they stay on the device.
- Open file shows the file dialog at once and opens the EPUB chosen in the reader (the file goes over in the browser's own storage; nothing is uploaded).
- The catalog returns to where you were: after reading it shows the same place in the shelf, and after the browser or app is restarted on a book's page it opens that page again. This is kept on the device only, it is not synced.
Reader
A single offline page (reader/reader.html) built on epub.js
and JSZip (both bundled, no internet needed). Nothing is uploaded.
- Paging:
←/→,PageUp/PageDown,Space, side arrows, mouse wheel / touchpad (one page per notch or swipe). - Scroll text (Aa → Layout): instead of pages, the whole book scrolls up as one ribbon, each
chapter right after the one before (finger, wheel, scrollbar;
↓/↑a little,PageDown/Space/ the side arrows a screen,Home/Endthe chapter's start / end). The place is the line at the top; the status line shows the %. This device only: it is not synced to your other devices. - Bold word starts (Aa → Font): the first letters of every word in bold, to lead the eye along the line (the idea known as "bionic reading"), with any font. Bookmarks, notes and the reading place stay put: one made with it on opens on the same words with it off, on any device. This device only, like Scroll text.
- Phones and tablets read with the whole screen for the text: only a thin line at the bottom
stays, numbers only —
4/24(page in the chapter) on the left,120/560 21%(page in the book, % read) on the right — and the text has the same small margin above and below it. The phone's own status bar (clock, battery) stays: hiding it only while reading would take the browser's fullscreen mode, and Chrome then always shows a "swipe to exit" hint. A tap in the middle third of the page brings the toolbar and the slider over the text (the page doesn't move); another tap hides them. A tap in the left / right third or a swipe turns the page. The bars hide again after any move in the book (page turn, slider, contents, search, bookmark). Taps on links or while selecting text don't count. A short tap belongs to the reader alone, so Chrome's "Touch to Search" sheet doesn't pop up over a page turn; a long press still selects a word, with the browser's menu and search. With a mouse the bars are always there and taps in the lower half of the page turn pages. - Table of contents (
T), current chapter, page in chapter, page in the book and % of the book. Pages in the whole book are an estimate for this screen and text size (laying out every chapter would take long): the book's length over the text a page holds in the chapters read so far. It settles after the first chapters — within about 1% on a 500-page book. Esccloses an open panel (contents, search, bookmarks), then clears search highlights, then closes the book and returns to the catalog, scrolled to where you left it (the Catalog button does the same).- Progress slider at the bottom: shows how much is read; drag it to jump anywhere
(while dragging it shows the % and chapter you'll land on).
To place it, the reader first counts pages across the whole book: a big book (hundreds of
chapters) can take a minute or more the first time, shown as Preparing navigation… N%.
The result is cached in
localStorage(about 2 MB for all books, oldest dropped first), so the next time the book opens the slider is ready at once. - Remembers where you stopped in each book (in the browser's
localStorage), also when the same book is opened by picking the file by hand. - Search in the book (search icon,
Ctrl+For/): lists every match grouped by chapter, with the % of the book and the text around it; click a match to go there. All matches are highlighted on the page, the current one in orange.Enter/F3— next match,Shift+Enter/Shift+F3— previous; while the panel is closed a small‹ 3 / 42 ›bar stays at the bottom. Search ignores case, treats ё as е and finds phrases split by formatting (e.g. half in italics). - Bookmarks, separate for each book: the bookmark icon (or
M) bookmarks the page you are reading (filled — the page already has one; press again to remove it). The bookmarks icon next to it (orB, available once the book has a bookmark) lists the book's bookmarks in reading order with the %, chapter and first words of the page; rename (pencil), delete (bin) or click to go there. The up / down arrows in the list or[/]jump to the previous / next bookmark. Kept in the browser'slocalStorage, like the reading place. - Notes: any bookmark can have a note of your own — free text, several lines. Press the note icon
next to the bookmark (or Add note in the "Bookmark added" message right after bookmarking).
It is saved as you type;
Esc,Ctrl+Enteror Done finish, an empty note is removed. Notes are shown under their bookmarks; click one to edit it. On phones the list fills the screen, the buttons are finger-sized and the note being edited stays above the on-screen keyboard. - Finding your bookmarks and notes: the field at the top of the bookmarks list filters it as you
type (by name, the page's first words, chapter and note; all words must match, case and ё/е
don't matter;
Escclears it). The book search (Ctrl+F) also lists matching bookmarks and notes, in a separate group above the matches in the text. - Theme: Auto (the system's light or dark, also inside an open book) · light · sepia · dark, remembered; one setting with the catalog (changing it in one changes the other). Pictures of ink on paper (a page or title page put in as a picture, black-and-white drawings and diagrams) follow it: in sepia their white paper takes the sepia colour, in dark they turn light on dark. Colour pictures and photos are not recoloured; in dark they are only dimmed.
- Print (computer; also
Ctrl+Por the browser's Print menu) prints exactly what is on the screen, like a picture of it: the open pages, without the bars and buttons, scaled to fit an A4 sheet (landscape for a wide window, portrait for a tall one), black on white whatever the theme. - Aa — text settings, remembered for all books, on three tabs (Size, Font, Layout; it
opens on the tab used last). On a phone or tablet it slides down from under the toolbar and takes
at most half the screen, so the page below shows what a change does:
- size (also
+/−); - font: As in book (under it, the font the open chapter is set in: e.g. Times New Roman,
Liberation Serif · in the book for a font the book carries, or default serif), or one of
the reading fonts that come with the reader — Literata, PT Serif, Lora, Merriweather,
PT Sans, Inter, OpenDyslexic, and free twins of well-known fonts that can't be shipped:
Palatino (P052), Helvetica (Nimbus Sans), Futura (Jost), Caecilia (Bitter); the
real font is named when you hover the button. Books come with their own fonts (embedded,
or named like Times New Roman / Arial), and books that name none get the device's
default, so they all look different. A chosen font shows every book the same way, on
every device and without internet; bold, italics and monospaced code are kept.
The fonts are in
reader/fonts/(Cyrillic and Latin, 3.9 MB; SIL Open Font License, P052 and Nimbus Sans GNU AGPL 3 with a font exception — seereader/fonts/LICENSE.txt); a browser downloads only the font in use; - layout: Same in all books gives plain paragraphs the same line spacing, indent and justified text with hyphenation. Titles, epigraphs and other styled parts keep the book's look.
- size (also
- Drag an EPUB onto the page to open it.
Open Library launchers
Browsers don't let a page opened straight from disk (file://) read other files, so
index.html opened by double-click can only ask you to pick each book file.
For one-click reading, open the catalog with the launcher placed next to index.html:
- Windows: double-click
Open Library.bat(uses the built-in PowerShell, nothing to install). - Linux: run
Open Library.sh(needspython3; in a file manager: right-click → Run as a Program, orsh "Open Library.sh"in a terminal).
The launcher starts a tiny web server on this computer only (localhost:48765; if another
program uses that port, the next free one up to 48784) and opens the catalog in the browser. Close the window (or Ctrl+C) to stop it; the Linux one
also stops after 3 hours without use. Running it again while it works just opens the browser.
Reading places are stored per address, so keep using the launcher to keep them (or use an
account to have them on every device, below). The window shows the library code for accounts.
The Windows launchers share launchers/library-sync.ps1, the Linux ones launchers/library_sync.py;
both keep the same files in .sync/, so a .bat and a .sh can serve one library. To try the
sync store on its own: python3 launchers/library_sync.py --serve FOLDER --port 8000 (this
computer only, no browser; --gate adds the network launchers' sign-in, below). The manual check for Windows is tests/windows-sync-checklist.md.
Reading on a phone or tablet (home Wi-Fi)
Open Library (network).bat (Windows) and Open Library (network).sh (Linux) do the same, but
the library can also be opened from other devices in your home network. The window shows the
address to type on the phone, e.g. http://192.168.1.64:48865/.
Only for people signed in. Any device but this computer gets nothing of the library — no catalog, covers, books or list — only a sign-in page, until it signs in with an account (see Accounts, below; a new account needs the library code). This matters when the router forwards a port to the library and does the https itself: then every request from the internet arrives from the router's home address, and the home-network filter below lets it through. One sign-in per device, kept for 400 days; devices already signed in for sync get in without the password; "Sign out" closes the library to that device again (books it already downloaded for offline reading stay on it). The sign-in page asks for a password only on the https address (at home too); on a plain
http://one it says to open the https one. This computer itself (localhost) needs no sign-in.Only home-network addresses (
192.168.x.x,10.x.x.x,172.16–31.x.x, link-local) get an answer, so without a router that forwards the internet the library stays at home.Files are only read; folder listings and uploads are refused.
Changing the library code (edit
.sync/code.txt) only stops new accounts with the old code; accounts made before and devices signed in keep working.Windows asks once whether PowerShell may use the network: allow it for Private networks (and check the Wi-Fi is set as a Private network). No administrator rights needed. On Linux a firewall (
ufw,firewalld) may need to allow the port.The window also shows the library code (see Accounts, below).
It uses its own ports (48865–48884), so both launchers can run at the same time. Reading places and bookmarks are kept separately on each device, unless you use an account (below).
The window logs who uses the library: each device (address, computer name when the router knows it, system and browser), the account it is signed in to, the book it opens, and when it leaves, with the number of connected devices:
2026-11-24 15:57:09 + 192.168.1.64 (laptop) · Linux · Chrome — connected [devices: 1] 2026-11-24 15:57:10 👤 192.168.1.64 (laptop) · Linux · Chrome — [email protected] 2026-11-24 15:57:11 📖 192.168.1.64 (laptop) · Linux · Chrome · [email protected] — «Book title» 2026-11-24 15:57:17 − 192.168.1.64 (laptop) · Linux · Chrome · [email protected] — closed the page; was here 2 s, … [devices: 0]The account shows with the sign-in (
🔑 … — sign-in ok (200): [email protected], also the login of a refused one), or, for a device signed in earlier, with its first sync; a sign-out is logged as👤 … — signed out. Never a password or a device key. (The Windows window writes@for🔑and*for👤.)Open pages report in once a minute; a device that goes quiet for 3 minutes (screen off, browser in the background, out of Wi-Fi) is shown as gone, and comes back as connected when it reports in again. Refused outside addresses are logged once each.
Accounts: the same place on every device
Optional. Without an account everything works as before, each device on its own (folders too: they stay on the device they were made on). With one, your phone, tablet and computer share what you read. The account lives in the library itself, on the computer that runs the launcher; nothing goes to the internet.
- An account is an email and a password. The email only names the account (it is not case sensitive); the library never sends mail, so nothing is verified and there is no "reset by mail". How to add and remove accounts: below.
- What is synced: reading places, bookmarks (with their names and notes) and the recently opened books are the same on all devices, and so is the catalog's view: its sort and grouping (choose "Recently opened" on the phone and the computer shows it too), and your folders (made, renamed, deleted, books put in or taken out on one device: the others follow; a book taken out on one device while another puts a different one in keeps both changes). Which folder is open stays each device's own. The reader's settings (font, theme, layout) are shared only between devices of the same kind (phone, tablet, computer), since what suits one screen doesn't suit another.
- What is not synced: the books themselves, the offline copies on a device, Scroll text and Bold word starts: each device keeps its own (scroll on the phone, turn pages on the computer).
- Offline is fine: changes are kept on the device and sent when the library is reachable again. The reader syncs when a book is opened, when you come back to the page and when you leave it; while you read, changes go out at most once every 30 seconds. Changes made on two devices are merged, and a deleted bookmark stays deleted.
- Use the https address. On a plain
http://192.168.…address there is no account (the catalog's logo is just a title; the reader has no account button): browsers allow it only on https (or onlocalhost, the same computer). Put the library behind https as for installing the app, above. - Wrong codes and passwords are slowed down: after 5 wrong in a row the library answers "try later" for a minute, longer with each further mistake.
- Forgotten password: the owner deletes
.sync/accounts/<email>.jsonin the library folder (and keeps.sync/data/<email>.json). The person registers again with the same email and the library code, and gets their data back. - Shared devices: signing in merges the places and bookmarks already on that device into the account being signed in, and signing out leaves them on the device — so on a family tablet, after one person signs out, the next person's sign-in takes the previous person's places and bookmarks into their own account.
- Signing out while the library computer is unreachable signs the device out, but its token
stays valid on the library computer until the account file is reset (the owner deletes
.sync/accounts/<email>.json, as for a forgotten password). - Back up
.sync/with the library: it holds the code, the accounts and everyone's data. It is never served to the network,make_server.pynever touches it, and it is in.gitignore.
Add an account
The person whose account it is makes it, on their own device (the owner can't make one for someone else):
- Open the catalog or the reader on the library's https address and open the account panel: in the catalog tap the blue book logo and library name at the top left (a green check on it means you are signed in); in the reader, the account button in the toolbar.
- Create account: their email, a password twice, and the library code. The code (four
words and two digits, like
river-paper-cold-moon-47) is printed in the launcher window at every start and kept in.sync/code.txtin the library folder. - On their other devices: Sign in with the same email and password (no code needed).
Giving someone the code is how you let them in: it stops strangers who reach the address from
making accounts. To stop new accounts with a code you gave out, edit .sync/code.txt (or delete it,
and a new random code is made); it applies at once, existing accounts keep working, and the
launcher window shows the new code from its next start.
Remove an account
No need to stop the launcher: the servers read the account files on every request. In the
library folder, for the account [email protected]:
- delete
.sync/accounts/[email protected]: the password no longer works and all their devices are signed out (on their next sync). Their devices keep their own copy of the places and bookmarks; - also delete
.sync/data/[email protected]to delete what they synced. Keep it, and whoever registers again with that email (and the library code) gets the data back — that is how a forgotten password is reset.
Installing as an app
The library can be installed as an app on a phone, tablet or computer: its own icon, full screen, no address bar. The browser doesn't push it; it's in the browser's menu — Chrome: ⋮ → Install app (or Add to Home screen), Safari on iPhone: Share → Add to Home Screen.
- A full install needs the library on an https address (or
localhoston the same computer). On a plainhttp://192.168.…address Chrome only offers a home-screen shortcut that opens in the browser; Safari on iPhone opens it full screen either way. - The app opens the library at the address it was installed from: keep the computer's address (and port) the same, e.g. a fixed address for it in the router. The server is needed for the first start and for updates; after that the app also works without it (below).
make_server.pywrites the app description to.index/manifest.webmanifest, named after the library.
Offline: the library on the device
The installed app (only the app, on https or localhost) keeps the library in its own storage on the
device: the site's storage, not the browser's cache, so the browser doesn't clean it up by itself.
Without a connection to the library the catalog and the reader open as usual, and so do the books
that are on the device. The others are dimmed, and Read says the book isn't on the device.
Each cover shows where the book is: a green phone — on this device, a cloud with an arrow — only in the library (it pulses while the book is being downloaded). The mark is a button:
- tap the cloud to download the book (it is not opened);
- tap the phone to remove the book from the device (after asking; it stays in the library);
- tap the cover itself to open the book as usual. A book opened in the reader is kept on the device by itself.
The book's page has the same as a button: Keep on this device / Remove from this device.
The Offline button in the header (a cloud with an arrow and books here / all books; green when
the whole library is on the device, blue while downloading) opens the settings:
- All books (default): the whole library is downloaded, one book after another, with progress on the button and in the panel. The app can be used meanwhile. A book removed by hand is not downloaded again (until it is kept again, or All books is chosen anew).
- Only books I open or keep: only the books opened in the reader or downloaded by hand.
- Remove all books from this device removes them all and switches to the second mode, so they don't come back by themselves.
The app checks the library when it starts, when it comes back to the screen and when the connection
returns. make_server.py writes the list for this to .index/library.json, so run it after changing
the books, as always:
- a new book is downloaded (in All books mode);
- a changed book (another size or date) is deleted from the device and downloaded again;
- a book removed from the library is deleted from the device too;
- an updated reader, cover or catalog page is fetched again. If the catalog on screen is older than the library, a note offers to show the new one.
The storage is the browser's site data for the library's address. Clearing it (e.g. Clear data in
the site settings, or removing the app) removes the books too. The service worker sw.js next to
index.html is written by make_server.py.
fix_cover.py
python3 fix_cover.py [PATH ...] [--dry-run] [--yes] [--no-generate] # default PATH: Out
Some books have a cover but don't say so: it's only shown on the first page, the cover mark points to a file that is not in the book, or the mark uses the file name instead of the manifest id. Readers and libraries then show no cover. Some books also list files they don't contain, which makes readers show broken pictures or skip to empty pages. For each book the script:
- ✅ the cover is properly marked and every listed file is there — the file is not touched;
- 🔧 a cover picture is there but not marked — adds the mark (
<meta name="cover">, andproperties="cover-image"for EPUB 3); - 🎨 there is no cover picture at all — draws one (title and author on a coloured
background, like the catalog placeholders) and adds it to the book. Needs Pillow;
--no-generateskips these books; - 🧹 the book lists files it doesn't have — removes them from the manifest, the reading order and the guide. A missing page can't be brought back; the script says so;
- 🖼 the first page shows a picture the book doesn't have (often
file:///tmp/…, left by the tool that made the book), so readers open on a broken image — points it to the real picture: the one no page shows whose size (or proportions) the page gives, else the cover; - 📝 pages are plain HTML although the book lists them as XHTML (common in books exported
from online libraries:
<meta charset="UTF-8">without/>), so strict readers can't open them — rewrites them as XHTML; the words are checked to stay exactly the same. A line break after the text of themimetypefile is removed too.
The .epub files are changed in place, so the script asks before each book:
🧹 Oskar Brandt - The Salt Road.epub
• the book lists files it doesn't have: OEBPS/cover.jpg, OEBPS/UusgmGFo.html → remove them from the manifest and the reading order
⚠️ 1 page(s) are missing from the book itself: their text can't be restored
Fix it? The .epub file will be changed. [y]es / [a]ll (yes, don't ask again) / [n]o / [c]ancel:
y fixes the book, a fixes it and all the next books without asking again, n leaves it as it is, c (or Ctrl+C) stops and leaves the remaining
books untouched. --yes fixes all books without asking (needed when the input is not a
terminal), --dry-run only prints what would be done.
Only the package file (OPF), the first page and pages that are not valid XHTML are edited;
every other file keeps exactly the same content (the archive itself is recompressed, so the
.epub's size changes a little). The fixed file is checked (opens, nothing lost, every listed file present,
cover found) before it replaces the old one, and keeps the old file's date. Running it
again changes nothing. Run make_server.py afterwards to see the covers in the catalog.
pdf2epub.py
python3 pdf2epub.py # every Pdf/*.pdf -> In/*.epub
python3 epub_rename.py # then sort them into Out/ as usual
Its helper modules live in pdf2epub_parts/; run only pdf2epub.py.
Like epub_rename.py, it takes Pdf/ and In/ from the current folder. Other options:
python3 pdf2epub.py book.pdf --title "Title" --author "Author" # one file, set the names
python3 pdf2epub.py some/folder --out other/folder
python3 pdf2epub.py --force # convert again books that are already in In/
python3 pdf2epub.py --yes # never ask questions
python3 pdf2epub.py --lang uk # language of the book (normally guessed from the text)
python3 pdf2epub.py --quick # only the PDF text layer: seconds instead of hours
python3 pdf2epub.py --pages 10 # a trial: only the first 10 pages, into In/Preview/
python3 pdf2epub.py --page 23 # a trial of chosen pages: 23, or 20-25,40
python3 pdf2epub.py --keep-work # keep In/.pdf2epub-work (recognised pages, report.json)
A trial before the long run. A big book takes hours, so first look at how it comes out:
python3 pdf2epub.py "Pdf/Mila Fenwick - Quiet Rivers.pdf" --pages 10 # ~10 min
# open In/Preview/Mila Fenwick - Quiet Rivers.epub; if it looks right:
python3 pdf2epub.py "Pdf/Mila Fenwick - Quiet Rivers.pdf" # the whole book
To look into one page that came out wrong, take just that page: --page 23 (or several:
--page 20-25,40). A trial without page 1 has no cover.
The trial goes to In/Preview/ and is made again every time, so it never blocks the
whole book and epub_rename.py does not sort it into the library (it reads only In/
itself). The pages the trial recognised stay in In/.pdf2epub-work/: the whole book starts
from page 11. A printed table of contents that points past the trial pages is not linked
in the trial; its headings are used instead.
Recognition (the default)
Every page is read from its picture, the way a person reads it, by Marker with the Surya models — free, and offline once installed:
- First run installs the engine by itself (one time, about 3 GB, needs internet):
Python 3.12 and Marker go to
~/.local/share/pdf2epub/, the models to~/.cache/huggingface/. Nothing is installed system-wide. - Each book is read twice: a fast pass over the whole book (minutes), then a careful pass page by page (about a minute a page on a CPU — a 230-page book takes about 4 hours; about 1.4 times faster on a GTX 1050 Ti (a newer NVIDIA card with more memory should do better), see below). The careful reading is checked word by word against the fast one and the PDF's own text layer: foreign or misread words are outvoted, and lines, list items or paragraphs that the careful pass dropped are put back in place.
- All questions (author, title) are asked before the long part starts, so it can run
unattended. It can be stopped any time (Ctrl+C, power off): the next run goes on from
the same page, with the title and author given at the start, without asking them again
(
--title/--authorchange them). The work lives inIn/.pdf2epub-work/and is removed when the book is done. A power cut is the same as Ctrl+C, without the draft: every page is written whole or not at all, and carries a checksum, so a page that comes back damaged (a shared folder may not reach the disk as surely as the system's own) is made again rather than lost; at most the eight pages being read at the moment are read again. The book is on the disk before its work is removed. - Stopped with Ctrl+C during the careful pass, it first makes a draft of the whole book to look
at:
In/Drafts/<book> (draft).epub, titled<title> (draft: 120 of 228 pages checked). The pages checked so far are as they will be; the others are from the fast reading, with its mistakes. It takes a few seconds; a second Ctrl+C stops at once, without a draft. The draft is in a folder of its own soepub_rename.pyleaves it; the next stop replaces it, and the finished book removes it.
📚 Found 1 PDF file(s)
ℹ️ It can be stopped with Ctrl+C: a draft of the whole book is made, and it goes on from the same page next time
⏳ Mila Fenwick - Quiet Rivers.pdf ...
⚡ fast recognition of 228 page(s)…
📄 page 1/228 · ok · ⏱ 0:54 · 0:03:35 elapsed · ~4:05:30 left
📄 page 2/228 · 2 words fixed, 1 missing piece put back · ⏱ 0:54 · 0:03:35 elapsed · ~4:04:20 left
📄 page 3/228 · ⚠️ 79% read, check it · ⏱ 0:54 · 0:03:35 elapsed · ~4:03:10 left
...
🔍 reading pages 5–8 · 0:01:42…
Each page line says what the check did on it (ok, words fixed by the vote, missing pieces
put back from the fast reading, a page read twice, a recognition loop cut out, vector arrows put
back, the fast reading used instead). ⏱ is the time
the page took: Marker reads pages four at a time, so each gets its share of the batch, plus
any second reading of its own. The same time is in log.txt and in report.json. The last
line is live: it shows which pages Marker is reading and for how long.
How long the whole run took is said at the end (Done in 7 h 35 min 5 s: …), and when it is
stopped with Ctrl+C (Stopped after …): it depends too much on the computer and its graphics
card to be guessed at the start.
When the fast reading is used, the line says why: accurate failed (Marker stopped with an
error), accurate found nothing (it read the page as blank), accurate read too little (less
than half of what the fast reading found; typical for title pages with decorative lettering,
which the careful pass takes for a picture). Pages with nothing printed on them are not given
to Marker at all (it fails on them): they are empty page straight away.
Title pages set as a design (big letters of different sizes): Marker takes them for a picture
and the fast reading loses letters and the layout. A page like that among the first 12
(the careful pass read nothing or too little there, and it has at most 40 words) goes into
the book as a picture of the page; the first page is the cover already. Pages Marker failed
on keep their fast text. The summary's check: list leaves out such pages, blank pages and
the cover.
On an NVIDIA graphics card. When nvidia-smi sees a card, the engine also installs
llama.cpp built for it (~800 MB, once), and Surya's text recognition, the slowest part, runs on
the card. On cards from the RTX 20 series on, PyTorch (page layout) is moved to the card too;
older cards (GTX 900/10 series) keep it on the processor. It needs an NVIDIA driver 570 or newer
(the script says so when the driver is older). The same models read the pages in the same way and
the book is checked word by word as always; the card only counts faster (in rounding it may
differ from the processor in a rare word, either way). A virtual machine (VMware, VirtualBox) gets no card: there, use Linux on the computer itself
or WSL2 on Windows (wsl --install; the Windows NVIDIA driver gives WSL2 the card). When the card
can't be used, books are read on the processor, and the card is tried again after a driver update.
If the engine can't be installed (no internet on the first run, unsupported system), the script says so and uses quick mode. To remove the engine:
rm -rf ~/.local/share/pdf2epub ~/.cache/huggingface/hub/models--datalab-to--*
What it does
- Text of every page, including the hidden text layer of scanned books that were recognised (OCR). Printed lines are joined into paragraphs, words hyphenated at the end of a line are glued back, running headers, footers and page numbers are removed. Bold and italic are kept, and so are lines the book sets at the right (a signature under a quote, the title, subtitle and author of a title page set at the right).
- Formulas (recognition mode): Marker reads them as LaTeX, the book gets them as MathML,
which EPUB readers and browsers draw as formulas. The converter (
latex2mathml) is installed with the engine, also into an engine installed earlier; a formula it can't convert stays as LaTeX. Labels of a diagram kept as a picture don't come back as text. The small arrow over a vector (ω⃗) is often read as a bar or a tilde (ω̄, ω̃): where the scan shows an arrow there, it is put back. Each mark over a letter is looked at on the page (an arrow has a head on the right); a block is changed only when it has as many marks on the scan as its formulas have accents, and only bars and tildes become arrows, never the other way round. The page line says how many were put back. - Drawings that look like tables (recognition mode): a chart with its labels outside the grid, a form to fill in, the boxes of a diagram. Marker makes a table of them, and a different one in each pass. Such a table is cut out of the page as a picture, with its frame, its title and the rest of the drawing, so it looks as it does in the book. A table counts as a drawing when the two passes read it differently, when most of its cells are empty, or when a picture or a figure caption ("Fig. 3", "Рис. 3") is next to it. Figure captions stay text, and printed contents stay contents.
- Lines to write on: a page "for notes", room for an answer in a
workbook. They are drawn, not printed text, so the recognition drops them; they are found
on the page's picture (three or more thin lines of one length at even steps with nothing
between them, so a table or crossed-out text doesn't count) and come back as as many empty
lines at their place on the page. The log names the page;
epub_diff.pyshows them as "[N lines to write on]". - Table of contents is taken from the book's own printed contents, when it has one: the entries, their nesting (from the indent) and page numbers. Each entry is found in the text (printed page numbers are matched to PDF pages by the numbers in headers/footers), so the reader's table of contents looks like the printed one and leads to the right place. The printed contents pages become a list of clickable links with page numbers; chapters are split at its top-level entries; sections it lists are shown as headings.
- Index at the end of the book ("Index", "Предметный указатель", "Алфавитный указатель"): printed in two or three columns, with sub-entries indented or after a mark (◊, –). Recognition reads it as tables, headings and lists in a muddled order, so it is put together from where the PDF's text layer has each line instead: the columns one after the other, every entry with its depth, a line that goes on joined to its entry, the big letters between them. On a scanned page the words of an entry are taken from the recognition when they match the layer's (same page numbers, nearly the same letters), as its letters are better. A scan without a text layer keeps the recognised index as it is.
- Headings are also found by their larger font, or as short bold lines standing on their own. Without printed contents, the biggest headings start new chapters and the table of contents is made of them. A book without any headings is cut into parts of 20 pages.
- Pictures among the text are kept; the page scans under recognised text are not. A page without any text (a scan that wasn't recognised, a diagram) is added as a picture of the whole page.
- Cover — the first page as a picture. If that page is a picture itself, it is not repeated in the text.
- Title and author come from the PDF properties, or from a file name like
Author - Title.pdf, orTitle Author Name.pdf/Author Name Title.pdfwhen that name (2–4 capitalised words, initials count) stands as a line of its own on the first pages, as on a title page. A file name with nothing else found (Quiet_rivers_01.pdf) is not offered as the title. What is found is only a suggestion: the script always asks for the title and author, and each question says what to press:
Neither may be empty: an empty answer (or only spaces) is asked again.Title: not found — type the title and press Enter (Tab puts the file name in, to edit) Title › Author: «Mila Fenwick» found — Enter keeps it; or type another and press Enter (Tab puts it in, to edit) Author ›--title/--authorset them (empty is an error),--yesskips the questions; then a book whose title or author is not found is not converted until--title/--authorgives it. - Language is guessed from the text (Russian, Ukrainian or English);
--langsets it. - PDF files are only read. A book already in
In/is skipped unless--force; a new book is written to a temporary file and checked (every page is valid, every listed file is there) before it gets its name.
In quick mode (--quick, or when the engine is not available) the result depends on the
PDF's text layer: page layout is turned into flowing text by guessing, so
tables, multi-column pages and side notes can come out in the wrong order, and a badly
recognised scan gives badly recognised text. Formulas and drawings made of lines (not
pictures) are lost on pages that also have text.
Reader checks (tests/reader)
End-to-end checks of the reader in headless Chrome, a touch phone by default (Node 22+ and
google-chrome, no packages). They open real books from Out/ and look where the text really
is on the screen:
tests/reader/run.sh "Jane Doe/Jane Doe - A Quiet Harbour.epub" "John Roe/John Roe - Paper Lanterns.epub"
FULL=1 tests/reader/run.sh "Jane Doe/Jane Doe - A Quiet Harbour.epub" # every font at 80/100/150/200%
nav.mjs— every page forward, then back: no page skipped or shown twice, the status line matches the real page count, no clipped lines, the reading place on the page shown;place.mjs— the place kept through every font and size, quick changes, reopening, window resizes; bookmarks and search matches land on the page shown, also after a font change;hits.mjs— every search match (or an even spread of them) is on the page shown;touch.mjs,status.mjs,typo.mjs— taps and bars, the status line, the Aa panel;scroll.mjs— Scroll text: switching keeps the first visible word, chapters follow one another, the place saved on the reader's own scroll and kept on reopening, font changes and resizes; contents, search, bookmarks and taps in scroll mode, on a phone and a desktop;subpixel.mjs— a phone's scroll position a fraction of a pixel past the page still turns to a chapter's last page;openfile.mjs— the catalog's "Open file" opens the reader with its "Catalog" button, which stays after a file is chosen and leads back;openfile-catalog.mjs— the catalog's "Open file" shows the file dialog itself, and the file chosen opens without the reader's start screen; a reload then shows the start screen;bold-unit.mjs,bold.mjs— Bold word starts: which letters get bold, every address the same with it as without it (made and resolved), the switch on this device only, the place and bookmarks kept across switching;nav.mjsandscroll.mjsrun again with it on (BOLD=1);signin.mjs— the network library's sign-in page (a second server with--gate, reached aslibrary.test): no form on plain http, sign-in and a new account open the page asked for, a device signed in before gets in without the form, "Sign out" shows the sign-in page again.
Several books run side by side; the output keeps only failures and each check's verdict.
W/H set the screen, TOUCH=0 a desktop, SHOTS=dir saves screenshots.
Sync checks
python3 -m pytest -q tests # servers, merge, launchers
node --test 'tests/sync/*.test.mjs' # the browser side of sync
python3 tests/sync_contract.py http://host:port FOLDER/.sync/code.txt # a running server, any launcher
The reader checks above (tests/reader/run.sh "<book>") cover the reader itself.
Notes and limitations
- Only the metadata stored in the book is used. If a book says
Whitmore Clara(last name first, no comma), the script can't tell which part is the first name. - Genres are not used: many EPUBs don't contain them.
- Please respect copyright — this repository contains only the scripts; don't commit
your books (
In/,Out/,Pdf/,*.epuband*.pdfare in.gitignore).
License
Explore related projects
Loading…