Skip to content

Instantly share code, notes, and snippets.

@ftnext
Created May 28, 2024 02:24
Show Gist options
  • Save ftnext/d9a2094ca2a54e84d3677217e607c783 to your computer and use it in GitHub Desktop.
Save ftnext/d9a2094ca2a54e84d3677217e607c783 to your computer and use it in GitHub Desktop.
# /// script
# dependencies = ["pikepdf"]
# ///
# Usage: pipx run unlock_pdf.py path/to/locked.pdf
# ref: https://methane.hatenablog.jp/entry/2024/01/11/PDF%E3%82%92%E3%82%BF%E3%83%96%E3%83%AC%E3%83%83%E3%83%88%E3%81%A7%E8%AA%AD%E3%82%80
import sys
from pathlib import Path
from pikepdf import Pdf
src = Path(sys.argv[1])
dest = Path(src.with_stem(src.stem + "-unlocked"))
with Pdf.open(src) as pdf:
pdf.save(dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment