Auto-Link URLs in PDF
Operator: Abdulla Al Fahad. How tools are built and checked
A PDF printed from a web page or rebuilt from a scan can show https://example.com/docs in blue and still do nothing when clicked, because the link annotation that makes text clickable was lost and only the characters remain. This tool reads those characters, works out where each address sits on the page, and lays a link over it.
Key features
- Web addresses and email addresses found in the text layer, each with its page
- Text that already has a link annotation is skipped and counted
- A tick box per address, so wrong ones are left out before saving
- Links drawn invisible, or with a thin blue box that shows what was covered
- A CSV list of what was added, skipped or already linked
How addresses are found and where the links go
A web address starts with http://, https:// or www., needs a dotted host whose last part has two or more letters (or is localhost), and runs to the next space. Sentence punctuation at the end, . , ; : ! ? quotes and closing brackets, is trimmed, and a closing parenthesis is kept only when the address holds a matching opening one, as Wikipedia addresses do. An address starting www. opens as https://www. followed by the rest. An email address is local@domain.tld; one that sits inside a web address is left to the web link, and a trailing dot, hyphen or underscore is dropped. Plain domains with no scheme and no www., such as example.com, and other schemes such as ftp://, are not detected. A link is skipped as already linked when the middle of its first rectangle falls inside any link annotation on the page, whether that link points to a site, an email or another page.
How it works
pdf.js supplies each page's text pieces with their positions. They are joined into one string per page, with a line break where the baseline changes and a space where two pieces have a visible gap, and the patterns run over that string. Each match is mapped back to the pieces it covers; where a match takes only part of a piece, the cut is placed by weighing each character's typical width, since narrow letters such as i and l take less room than m and w.
Each chosen address becomes a Link annotation with a URI action, flagged to print, with its web address written as 7-bit text and any other character percent-encoded. The page content is not touched, and the links already in the file are left as they were.
Common use cases
- An 85-entry reference list printed from a browser to PDF, where every address is plain blue text: all 85 are found, and unticking the three that wrapped at the margin leaves 82 good links.
- A conference booklet with 12 speaker email addresses and 40 institution sites: untick the web box when only the emails should become mailto links.
- A scanned report put through OCR, whose text layer holds the addresses but no links, becomes clickable in one pass; the Opens column is the place to catch misread characters.
- A chat transcript exported to PDF with links as bare text: the blue box option makes it easy to confirm that each link sits over its address.
How to use this tool
- Drop the PDF and wait for the scan of its text.
- Untick web or email addresses you do not want, and untick any single entry that looks wrong, such as an address cut short at a line end.
- Choose invisible links or the blue box, then press Add links to save the new file.
Example
Two lines of page text; the first address already has a link annotation
Visit https://example.com/docs, or mail sales@example.com. Also (www.test.org) now.
Already linked: https://linked.example/page and plain mailto me@x.ioWhat the tool reports
5 addresses found, 1 already linked (https://linked.example/page), 4 to add:
https://example.com/docs opens https://example.com/docs (trailing comma dropped)
sales@example.com opens mailto:sales@example.com (full stop dropped)
www.test.org opens https://www.test.org (brackets dropped)
me@x.io opens mailto:me@x.io
Scanning the saved file again reports all 5 as already linked, so a second run adds nothing.Common pitfalls
An address broken across two lines is not rejoined. The part on the first line, such as https://example.com/reports/2025-, is found and would link to that shortened address, while the rest on the next line is not found. Untick that row and fix the address by hand.
Where an address shares a text run with other words, the rectangle edges are estimated from typical character widths. In the test file they landed within about 2.3 points of the true edges; an unusual font can be further out.
Only the characters in the text layer are read. Addresses that are part of a picture, or that the PDF draws as shapes, cannot be found.
- On a first pass choose the thin blue box: it shows exactly the area each link covers, so a rectangle sitting a little off a proportional-font address is visible before you commit to invisible links.
Common errors and how to fix them
- No addresses found in the text layer
- The PDF may be a scan with no text, or the addresses may be drawn as outlines. Run Make PDF Searchable (OCR) for a scan; for outlined text there is nothing to read.
- A link opens the wrong address after OCR
- OCR often reads rn as m or l as 1 inside an address. Untick the entry, correct the spelling in the source, or check the Opens column against the page before saving.
Frequently asked questions
Why was an address I can see not found?
It is probably a bare domain without www. or a scheme, wrapped over two lines, or part of an image rather than text. Try selecting it with the text cursor in a viewer: if it cannot be selected as one piece, there is no text for the tool to read.
Does it change the pages themselves?
No. It adds link annotations on top and leaves the page content as it was, so the layout and the text are unchanged. To list the links a file already has, Extract Links from PDF here does that.