Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,42 @@ pyrightconfig.json
.history
.ionide

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,jupyternotebooks,pycharm

files/*.pdf
outputs/*.pdf
outputs/*.pdf

!files/simple.pdf
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ pip install -r requirements.txt
### Usage
```bash
jupyter lab

// run the script
python unlock_pdf.py locked.pdf unlocked.pdf password
```
Binary file added files/simple.pdf
Binary file not shown.
14 changes: 11 additions & 3 deletions unlock-pdf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "79a889a5-ec8f-4d3f-a4f4-3f03708cc866",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ PDF ปลดล็อกสำเร็จ! บันทึกที่: ./outputs/K-BANK-HOME-unlocked.pdf\n"
"✅ PDF ปลดล็อกสำเร็จ! บันทึกที่: ./outputs/simple-unlocked.pdf\n"
]
}
],
"source": [
"unlock_pdf(\"./files/<file>.pdf\", \"./outputs/<file>-unlocked.pdf\", \"<password>\")"
"unlock_pdf(\"./files/simple.pdf\", \"./outputs/simple-unlocked.pdf\", \"123456789A\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5a2473a7-6aae-406f-b835-d4e43124b7d5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
22 changes: 22 additions & 0 deletions unlock_pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys
import pikepdf

def unlock_pdf(input_pdf, output_pdf, password):
try:
pdf = pikepdf.open(input_pdf, password=password)
pdf.save(output_pdf)
print(f"✅ PDF ปลดล็อกสำเร็จ! บันทึกที่: {output_pdf}")
except pikepdf._qpdf.PasswordError:
print("❌ รหัสผ่านไม่ถูกต้อง")
sys.exit(1)

if __name__ == "__main__":
if len(sys.argv) != 4:
print("⚠️ ใช้งาน: python unlock_pdf.py <input.pdf> <output.pdf> <password>")
sys.exit(1)

input_pdf = sys.argv[1]
output_pdf = sys.argv[2]
password = sys.argv[3]

unlock_pdf(input_pdf, output_pdf, password)