Skip to content

Commit 53317e7

Browse files
committed
Auto-generated summary:
Commit Date: Fri Mar 8 18:08:25 CST 2024 File changes:
1 parent e14d4d7 commit 53317e7

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
1+
# Regenerator PDF
22
Regenerator PDF 是一款开源工具,可帮助您将PDF文档 转换为有辅助信息的PDF。它可以执行以下功能:
33
- **标记到索引单元**:将 PDF 文档中的标记转换为索引单元,以便于快速导航和搜索。
44
Regenerator PDF 是开源且免费使用的,使其成为学生、研究人员和专业人士的宝贵工具。它兼容 Windows、Mac 和 Linux 操作系统。
55

6+
## 安装
7+
8+
```
9+
pip install pdf-regenerator
10+
```
11+
12+
## 生成PDF目录
13+
14+
```
15+
python3 -m pdf-regenerator $YOU_PDF_PATH $YOU_OUT_FILE_DIR
16+
```

pdf_regenerator/__main__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
import fitz # PyMuPDF
24
from reportlab.pdfgen import canvas
35
from PyPDF2 import PdfReader, PdfWriter
@@ -6,7 +8,8 @@
68

79
@click.command()
810
@click.argument('pdf_path', type=click.Path(exists=True))
9-
def create_pdf_with_contents(pdf_path):
11+
@click.option('--output_path', '-o', help='Output file path', type=click.Path(), default=lambda: os.path.join(os.getcwd()))
12+
def create_pdf_with_contents(pdf_path, output_path):
1013
doc = fitz.open(pdf_path)
1114
toc = []
1215
titles = []
@@ -35,8 +38,13 @@ def create_pdf_with_contents(pdf_path):
3538
for i in range(len(existing_pdf.pages)):
3639
output.add_page(existing_pdf.pages[i]) # 更新调用方式
3740

38-
output_path = "output_with_contents.pdf"
39-
with open(output_path, "wb") as outputStream:
41+
file_name, file_extension = os.path.splitext(os.path.basename(pdf_path))
42+
# 添加标记到文件名
43+
if output_path:
44+
mark = 'mark'
45+
output_file_path = os.path.join(os.path.dirname(output_path), f'{file_name}_{mark}{file_extension}')
46+
47+
with open(output_file_path, "wb") as outputStream:
4048
output.write(outputStream)
4149
if __name__ == "__main__":
4250
create_pdf_with_contents()
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)