Why not just use an LLM?
When someone hands me a 40-page report, I want to know what it says before deciding whether to read it. The usual answer today is to paste it into a chatbot. That has two problems. The document goes to someone else's server, which is a bad idea for a contract or an internal report. And the summary is rewritten, so you can't tell whether a number was in the original or was made up.
Extractive summarization is older and much less clever, but it has a property I care about: every sentence in the summary is in the document, word for word. You can point at it. So the tool highlights each chosen sentence in the original text, can show the score of every sentence, and explains below each summary how it was made, using your document's numbers.
Everything below runs in plain JavaScript in the browser. The only libraries are pdf.js to read PDFs and pdf-lib to write the downloadable summary.
1. Getting clean text out of a PDF
This is the unglamorous half of the work. pdf.js gives you positioned text fragments, not paragraphs. Lines are rebuilt from their positions, then grouped into blocks: headings (by font size and weight), list items, paragraphs and, when the columns line up, tables.
Then comes the cleanup that makes or breaks the result:
- Headers and footers. A short line that repeats on at least 3 pages and on 30 % of them is removed. Digits are normalized before comparing, so "Page 3 of 40" and "Page 4 of 40" count as the same line.
- Paragraphs split across pages are joined when the first part doesn't end in a full stop and the next one starts in lowercase. Hyphenated words at the end of a line are glued back together.
- Scanned PDFs have no text layer. If no page has text, the tool says so and points to OCR, instead of producing an empty summary.
Word, ODT, RTF and EPUB files go through a reader that turns them into HTML. Headings, lists, tables and images come from the markup, which is much easier than a PDF.
2. Splitting into sentences
A naive split on ". " breaks constantly in Spanish legal and administrative text: "Sr. García", "art. 37.2", "EE. UU.", "J. Pérez". The splitter only cuts after ., !, ? or … followed by a space and an uppercase letter or a digit. Then it rejects the cut if the word before the dot is a known abbreviation, a single capital letter (an initial), a dotted group like "EE.UU", or a short number in a short fragment (a numbered list). The abbreviation list covers Spanish, Catalan, Galician, Basque, Aranese and English.
3. From words to vectors
Each sentence becomes a sparse vector:
- Stop words ("the", "of", "que", "de"…) are dropped, using a list for each of the six languages. The language is detected from marker words, and you can override it.
- Light stemming, deliberately crude: strip plurals, then truncate (7 characters for the Romance languages, 6 for Basque, 8 for English). It's enough to make "workers" and "worker" the same term.
- TF-ISF weights, the sentence-level cousin of TF-IDF:
(1 + log tf) × log((N + 1) / sf), wheresfis the number of sentences containing the term. Vectors are normalized to unit length.
4. The similarity graph
Two sentences are similar when their vectors point the same way (cosine similarity). Comparing every pair is O(N²), so the graph is built from an inverted index: for each term, the sentences that contain it. Only pairs that share at least one term are compared. Terms that appear in too many sentences (more than 40, or 20 % of the document) are skipped, since they connect everything to everything and mean little. Edges weaker than 0.04 are dropped.
5. TextRank
TextRank is PageRank applied to sentences. Each sentence passes its score to the sentences it resembles, in proportion to how similar they are. A sentence ends up important if it is similar to many sentences that are themselves important, which usually means it states a central idea. The core loop is short:
let rank = new Float64Array(N).fill(1 / N);
for (let it = 0; it < 40; it++) {
const next = new Float64Array(N).fill(0.15 / N);
for (let i = 0; i < N; i++) {
if (!out[i]) continue; // sum of i's edge weights
const r = 0.85 * rank[i] / out[i];
for (const [j, w] of adj[i]) next[j] += r * w;
}
rank = next;
}
The damping factor is the classic 0.85. Forty iterations is more than enough to converge on documents of any size I've tried.
6. Everything that isn't TextRank
TextRank alone picks some odd sentences, so the final score mixes four signals, each scaled from 0 to 1:
score = f × (0.45·TextRank + 0.20·topic + 0.20·position + 0.15·headings)
- Topic: similarity to the centroid of all sentences, which favours sentences about what the whole document is about.
- Position: the first sentence of a paragraph and the early part of the document tend to introduce ideas, and the last few percent often holds the conclusions.
- Headings: sharing terms with the title counts double compared with sharing terms with a section heading.
- f, the penalties: very short sentences (under 5 or 8 words), very long ones (over 70), questions, sentences that start with a connector ("This", "Also", "However", which read badly without the previous one), lines without final punctuation, all-caps lines, lines that are mostly numbers, table and index rows (dotted leaders), and exact duplicates, which score zero.
These weights were tuned by hand on real documents: official gazettes, reports, contracts and guides. They are not learned. That is a limitation, but it also means anyone can read them, and the tool shows them.
7. Choosing sentences without repeating ideas
Taking the top-scoring sentences gives you the same idea three times. Selection uses Maximal Marginal Relevance: at each step it takes the sentence with the best 0.75 × score − 0.25 × redundancy, where redundancy is the highest similarity to anything already chosen. A sentence more than 0.65 similar to a chosen one is skipped outright. It stops at 10, 20 or 30 % of the words. Once there are 3 sentences, nothing below 12 % of the best score is added, so a document that is mostly tables gets a shorter summary instead of a padded one.
The chosen sentences are then shown in their original order. The "key points" list is the same procedure with a fixed count, clamp(round(log2 N) − 1, 3, 7), shown in order of importance.
8. Keeping tables and images
A summary of a report that drops the one table everybody cares about is not much use. Tables and images are kept as separate blocks: their text never competes with sentences. A figure goes into the summary when:
- it sits within two blocks of a chosen sentence, without a heading in between, or
- a chosen sentence mentions it by number ("see table 2", "figure 3") and the caption next to the figure has that number.
Getting images out of a PDF means walking the page's operator list and tracking the transformation matrix, to know where each image is drawn and how big. Tiny images (icons, bullets) and page-sized ones (backgrounds, scans) are ignored. An image that appears on 3 or more pages is treated as a logo and skipped. Each image is placed before the first text block below it.
There is one trap I hit in testing. A Spanish official gazette that is essentially a 766-row table of local holidays left almost no prose once tables were set aside, so it was rejected as "too short". The fix: when that happens, the tables are read as text again, as before.
9. Performance
The inverted index keeps the graph sparse. A synthetic document of 123,840 words (5,220 sentences) is analyzed in about 2.9 seconds on my laptop, in the browser, with no server and no Web Worker. Ordinary documents take a fraction of a second; reading and rendering the PDF usually takes longer than summarizing it.
10. What it doesn't do
- It doesn't understand anything. A key fact in a sentence that shares few words with the rest of the text can be left out.
- It can't merge two half-ideas into one sentence, and it doesn't resolve "this" or "it". That's why connector sentences are penalized rather than fixed.
- Documents that are mostly tables, lists or slides give poor results.
- Stemming is crude, so some related words are missed and a few unrelated ones are merged.
Those limits are the reason for the highlighting and the scores. A summary you can't check is a summary you have to trust, and I'd rather not ask for that.
Try it
The summarizer is free, needs no account and never uploads your file. It works in English, Spanish, Catalan, Galician, Basque and Aranese. If you find a document where the summary is bad, I'd genuinely like to hear about it on the contact page.