From 8a1e8c478af339a12fb19cc2085113433cb0d850 Mon Sep 17 00:00:00 2001 From: JiJi Date: Wed, 25 Jan 2023 00:22:24 +0800 Subject: [PATCH] Initial commit --- .gitignore | 4 +++ README.en.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++ assets/logo.svg | 52 +++++++++++++++++++++++++++++++++++ pdfuck.py | 38 +++++++++++++++++++++++++ requirements.txt | Bin 0 -> 316 bytes setup.cfg | 18 ++++++++++++ setup.py | 5 ++++ 8 files changed, 257 insertions(+) create mode 100644 .gitignore create mode 100644 README.en.md create mode 100644 README.md create mode 100644 assets/logo.svg create mode 100644 pdfuck.py create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..997cf63 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.venv +__pycache__ +dist +pdfuck.egg-info \ No newline at end of file diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..508066c --- /dev/null +++ b/README.en.md @@ -0,0 +1,70 @@ +![](assets/logo.svg) + +[简体中文](README.md) | [**English**](README.en.md) + +--- + +## Introduction + +[PDFuck](https://github.com/mmdjiji/pdfuck) is a tool to remove PDF editing password, which is used in CLI (command line) mode. + +## Installation + +Before installing, please ensure that you have installed Python (>=3.0) and its matching version of pip, and then enter the following command at the command prompt: + +```bash +pip install pdfuck +``` + +## Usage + +### Remove PDF password + +For example, if you want to remove the password from the PDF file which is located in `example.pdf`, just enter the following command: + +```bash +pdfuck example.pdf +``` + +The default path of the output file is `example.fucked.pdf`. + +### Manually specify the output file path + +If you want to specify the path of the output file manually, you can use the `-o` parameter, for example: + +```bash +pdfuck example.pdf -o target.pdf +``` + +### PDF file requires opening password + +Use the `-p` parameter to manually specify the opening password, for example: + +```bash +pdfuck example.pdf -p password +``` + +## Credit + +Thanks for the following open source projects. The completion of this project is inseparable from the code contributed by these authors. + +* [pikepdf](https://github.com/pikepdf/pikepdf) + +## Workflow + +### Configure development environment + +```bash +pip install -r requirements.txt +``` + +### Build and test + +```bash +python -m build +pip install --editable . +``` + +## License + +[GPL-3.0](LICENSE) diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c58e8d --- /dev/null +++ b/README.md @@ -0,0 +1,70 @@ +![](assets/logo.svg) + +[**简体中文**](README.md) | [English](README.en.md) + +--- + +## 简介 + +[PDFuck](https://github.com/mmdjiji/pdfuck) 是一个去除 PDF 编辑密码的工具,以命令行方式使用。 + +## 安装 + +在安装前,请确保你安装了 Python (>=3.0) 及与之版本相匹配的 pip,然后在命令提示符中输入下面的命令: + +```bash +pip install pdfuck +``` + +## 使用 + +### 去除 PDF 密码 + +例如,想要去除密码的 PDF 文件位于 `example.pdf`,只需输入下面的命令: + +```bash +pdfuck example.pdf +``` + +输出文件的默认路径为 `example.fucked.pdf`。 + +### 手动指定输出文件路径 + +如果想要手动指定输出文件的路径,可以使用 `-o` 参数,例如: + +```bash +pdfuck example.pdf -o target.pdf +``` + +### PDF 文件含有打开密码 + +使用 `-p` 参数手动指定打开密码,例如: + +```bash +pdfuck example.pdf -p password +``` + +## 致谢 + +感谢以下开源项目,本项目的完成离不开这些作者贡献的代码。 + +* [pikepdf](https://github.com/pikepdf/pikepdf) + +## 工作流 + +### 配置开发环境 + +```bash +pip install -r requirements.txt +``` + +### 构建与测试 + +```bash +python -m build +pip install --editable . +``` + +## 开源协议 + +[GPL-3.0](LICENSE) diff --git a/assets/logo.svg b/assets/logo.svg new file mode 100644 index 0000000..5005238 --- /dev/null +++ b/assets/logo.svg @@ -0,0 +1,52 @@ + + +
+ +

+ PDFuck +

+
+
+
diff --git a/pdfuck.py b/pdfuck.py new file mode 100644 index 0000000..8ff3105 --- /dev/null +++ b/pdfuck.py @@ -0,0 +1,38 @@ +# pdfuck.py +# Author JiJi +# GitHub https://github.com/mmdjiji/pdfuck + +import argparse +import pikepdf + +def pdfuck(filepath, output, password): + + # add '.fuck' sign for the output file + if not output: + splited = filepath.rsplit('.', 1) + prefix = splited[0] + output = prefix + '.fucked' + if(len(splited) >= 2): + suffix = splited[1] + output += '.' + suffix + + try: + with pikepdf.open(filename_or_stream=filepath, password=password) as pdf: + pdf.save(filename_or_stream=output) + print('Decryption succeeded, saved to \'' + output + '\'') + + except Exception as e: + print(e) + +def main(): + parser = argparse.ArgumentParser(description='PDFuck: Remove the password of your PDF file') + parser.add_argument('filepath', metavar='', type=str, help='path of the source PDF file') + parser.add_argument('-o', '--output', metavar='', type=str, help='path of the target PDF file') + parser.add_argument('-p', '--password', metavar='', type=str, help='reading password of the source PDF file') + args = parser.parse_args() + + filepath, output, password = args.filepath, args.output, args.password or '' + pdfuck(filepath=filepath, output=output, password=password) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..eee2b260ad1ebe448c2fa8541c23d21009582fe2 GIT binary patch literal 316 zcmXw#K@Ng26hvoj;#C?zLv*2M@CF6}6{)n58ujw({81MDB%L=izkJ>Y+|j|K!4?~2 zaL6??%rQfaKrP^g3Rj+qS&}P7G-wg2w`40MW(5r53S~K_S(3+-30{i1*F1%kNMDVf z^F;T+X)Og7B!1q=`(8Z_j#5jx9aj8CHjZr0mA2DsZ0Cna>#@Em>7{K0F4{O@k2Bf8 W{84-^cH$Ei+q(PjWcT)m>_uOIE-wZE literal 0 HcmV?d00001 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..562637d --- /dev/null +++ b/setup.cfg @@ -0,0 +1,18 @@ +[metadata] +name = pdfuck +version = 1.0.0 +author = JiJi +long_description = file: README.md +license = GPL-3.0 +url = https://github.com/mmdjiji/pdfuck +classifiers = + Programming Language :: Python :: 3 + +[options] +packages = find: +install_requires = + pikepdf + +[options.entry_points] +console_scripts = + pdfuck = pdfuck:main \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..4b2f6c4 --- /dev/null +++ b/setup.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- + +import setuptools +setuptools.setup()