# Extract Hyperlinks from PDF to Excel as Real Links

- Author: FastBankConvert (https://fastbankconvert.com)
- Published: 2026-10-17
- Category: Tables and data from PDFs
- Canonical: https://fastbankconvert.com/blog/extract-hyperlinks-from-pdf-to-excel

> Extract hyperlinks from a PDF to Excel: why copied text loses the link targets, how to pull the URLs out, and turning them back into live links.
To extract hyperlinks from a PDF to Excel, read the link annotations rather than the page text, since copied text keeps the visible words but not the addresses behind them. A short script lists each link's page, its clickable area and its target URL, and Excel's HYPERLINK function turns each URL back into a live link.

## Why copied PDF text drops the hyperlink targets

A PDF keeps a hyperlink in two separate places: the words you see are page text, and the target is a link annotation, an invisible clickable rectangle laid over those words. Copying selects only the text, so "Download the price list" arrives in Excel without the address it pointed to.

### Text and links are separate objects

The rectangle and the words line up on the page, but nothing in the file ties them together beyond their position. A link may cover one word, half a line, or an image with no text under it at all. Several links can sit over one paragraph. That is why no reader can copy a link with its text in one step: the reader would have to guess which words each rectangle covers.

### When the URL is printed on the page

Some PDFs print the full address as text, such as `https://example.com/terms`. In that case copying does keep the URL, because it is ordinary text, and a pattern can pull it out of the pasted lines. The trap is wrapping. A long address split over two printed lines arrives as two rows, and only half of it works. Join the rows before using the URL. The same pattern work applies to email addresses, and [extracting email addresses from a PDF into a column](/blog/extract-email-addresses-from-pdf-to-excel) shows how.

## How do you pull hyperlink annotations out of a PDF?

A script can list every hyperlink annotation in a PDF, with its page number, its clickable rectangle and its target, in a few lines. Python's PyMuPDF library does this through a page method that returns each link as a dictionary, and the words under the rectangle can be read with a second call.

### What the library returns

[PyMuPDF's Page documentation](https://pymupdf.readthedocs.io/en/latest/page.html) says `get_links()` returns a list of dictionaries, one per link. Each has a `kind` that says what sort of link it is, with `LINK_URI` for web addresses and `LINK_GOTO` for jumps inside the document, a `from` rectangle marking the clickable area, and a `uri` string for web links. The same page describes `get_textbox(rect)`, which returns the text inside a rectangle.

### The script

```python
import csv, sys
import pymupdf

doc = pymupdf.open(sys.argv[1])
with open("links.csv", "w", newline="", encoding="utf-8-sig") as f:
    out = csv.writer(f)
    out.writerow(["page", "link_text", "url"])
    for page in doc:
        for link in page.get_links():
            if link["kind"] == pymupdf.LINK_URI:
                text = page.get_textbox(link["from"]).strip()
                out.writerow([page.number + 1, text, link["uri"]])
```

Run it as `python links.py report.pdf`. It writes one row per web link, with the page number counted from 1 as a reader shows it.

### Example output

The rows below are examples of what the script writes, with the HYPERLINK formula you would add in column D:

| A: page | B: link_text | C: url | D: live link |
| --- | --- | --- | --- |
| 2 | price list | `https://example.com/prices.pdf` | `=HYPERLINK(C2,B2)` |
| 2 | terms of sale | `https://example.com/terms` | `=HYPERLINK(C3,B3)` |
| 7 | (empty) | `https://example.com/contact` | `=HYPERLINK(C4,C4)` |

Row 4 shows a link with no text under it, usually a logo or button image. Use the URL itself as the display text for those.

### Internal links

Links of the `LINK_GOTO` kind jump to another page of the same PDF, such as entries in a contents list. They have no web address. If you need them, record the destination page, which the same dictionary holds, rather than a URL.

## Turning extracted URLs into live Excel hyperlinks

Excel's HYPERLINK function makes a clickable cell from a URL and a display name. Point the first argument at the cell holding the extracted URL and the second at the link text, fill the formula down, and every row becomes a working link you can click.

[Microsoft's HYPERLINK function reference](https://support.microsoft.com/en-us/office/hyperlink-function-333c7ce6-c5ae-4164-9c47-7de9b76f577f) gives the syntax as `HYPERLINK(link_location, [friendly_name])`. It says the friendly name is the text shown in the cell, and that if you leave it out the cell shows the link location instead. It also notes that Excel for the web supports only web addresses with this function.

Three practical points:

- Keep the plain URL in its own column. A formula cell is hard to filter or deduplicate by address, and the plain text is what you search on.
- To make the links permanent without formulas, copy column D and paste it as values. The display text stays, but the link goes with the formula, so keep the formula version if you want clickable cells.
- Check a few links before sharing the sheet. A target that pointed to a page years ago may now redirect or fail.

## Are PDF hyperlinks on scanned pages recoverable?

Hyperlinks on scanned pages are not recoverable as links, because a scan is a picture of a page and holds no link annotations. An address printed on the page can be read back only by text recognition, and then it is text that has to be checked character by character before you trust it.

### Why scanned URLs need checking

Text recognition misreads characters, and a URL has no spare letters. One wrong character, such as a lowercase l read as the digit 1, sends the link somewhere else entirely or nowhere at all. The same confusions that turn up in recognised bank figures, covered in [the digits OCR confuses on bank statements](/blog/bank-statement-ocr-digit-errors), apply to the letters and numbers of an address. Open each recovered URL once before you rely on it.

### Mixed documents

Some PDFs mix both kinds of page: a digital report with a scanned appendix, or a scanned letter with a typed cover page. The script above finds links only on the digital pages. Run text recognition on the scanned ones separately, and mark the rows that came from recognition so a reader knows which links were rebuilt by hand.

If links are one of several kinds of data you need from a document, [an overview of pulling fields out of a PDF into Excel](/blog/extract-data-from-pdf-to-excel) lays out the other routes, and highlights are another case where the data sits in annotations rather than text, as [exporting highlighted PDF text into rows](/blog/extract-highlighted-text-from-pdf-to-excel) explains. FastBankConvert does not collect links; it is a statement converter, built to read transactions into Excel, CSV or JSON, and it is [taking sign-ups before launch](/get-started).
