Created
November 9, 2025 12:29
-
-
Save tovrstra/a760c916a646c6e1dc44c5b5b5f0d79d to your computer and use it in GitHub Desktop.
Remove all links from a PDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """Remove all links from a PDF.""" | |
| import argparse | |
| import fitz | |
| def main(): | |
| args = parse_args() | |
| doc = fitz.open(args.pdf_in) | |
| for page in doc.pages(): | |
| for link in page.get_links(): | |
| link_target = link.get("file") or link.get("uri") | |
| if link_target is not None: | |
| page.delete_link(link) | |
| doc.save(args.pdf_out) | |
| def parse_args(): | |
| parser = argparse.ArgumentParser(description="Remove all links from a PDF") | |
| parser.add_argument("pdf_in", help="The input PDF file") | |
| parser.add_argument("pdf_out", help="The link-free output PDF file") | |
| return parser.parse_args() | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment