Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin2li committed Jul 15, 2023
1 parent 375e31e commit 0880396
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,16 @@ https://pandoc.org/installing.html

3. 路径格式

全部使用绝对路径,类似:`C:\Users\kevin\Downloads\test.txt`
全部使用绝对路径,类似:`C:\Users\kevin\Downloads\test.txt`, 注意不要用引号包裹路径

Windows下可以选中目标文件后使用`Ctrl+Shift+C`快速复制文件绝对路径。
> 如何快速获取文件绝对路径?
> 1. Windows下可以选中目标文件后使用`Ctrl+Shift+C`快速复制文件绝对路径。
> 2. MacOS下可以选中目标文件后使用`Command+Opion+C`快速复制文件绝对路径。
软件会自动检测路径是否存在,不合法的路径将不会被通过,也不会进行继续的处理。

如果想批量操作,可以使用通配符`*`。例如批量对PDF文件进行旋转,路径可以填`C:\Users\kevin\Downloads\*.pdf`,将会匹配`C:\Users\kevin\Downloads`目录下所有的PDF文件。除少数功能(插入/替换等)外,大部分都支持批量操作。
如果想批量操作,可以使用通配符`*`
例如批量对PDF文件进行旋转,路径可以填`C:\Users\kevin\Downloads\*.pdf`,将会匹配`C:\Users\kevin\Downloads`目录下所有的PDF文件。除少数功能(插入/替换等)外,大部分都支持批量操作。

4. 坐标

Expand Down
14 changes: 11 additions & 3 deletions thirdparty/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ def create_text_wartmark(
y_offset : Union[int, float] = 0,
multiple_mode : bool = False,
output_path : str = None,
) -> None:
):
try:
if output_path is None:
output_path = "watermark.pdf"
Expand Down Expand Up @@ -1155,9 +1155,11 @@ def create_text_wartmark(
c.drawString(start_x,start_y-i*line_height,part)
c.save()
dump_json(cmd_output_path, {"status": "success", "message": ""})
return True
except:
logger.error(traceback.format_exc())
dump_json(cmd_output_path, {"status": "error", "message": traceback.format_exc()})
return False

def create_image_wartmark(
width : Union[int, float],
Expand Down Expand Up @@ -1202,9 +1204,11 @@ def create_image_wartmark(
c.showPage()
c.save()
dump_json(cmd_output_path, {"status": "success", "message": ""})
return True
except:
logger.error(traceback.format_exc())
dump_json(cmd_output_path, {"status": "error", "message": traceback.format_exc()})
return False

@batch_process
def watermark_pdf_by_text(doc_path: str, wm_text: str, page_range: str = "all", layer: str = "bottom", output_path: str = None, **args):
Expand All @@ -1213,7 +1217,9 @@ def watermark_pdf_by_text(doc_path: str, wm_text: str, page_range: str = "all",
page = doc[-1]
p = Path(doc_path)
tmp_wm_path = str(p.parent / "tmp_wm.pdf")
create_text_wartmark(wm_text=wm_text, width=page.rect.width, height=page.rect.height, output_path=tmp_wm_path, **args)
ok = create_text_wartmark(wm_text=wm_text, width=page.rect.width, height=page.rect.height, output_path=tmp_wm_path, **args)
if not ok:
return
wm_doc: fitz.Document = fitz.open(tmp_wm_path)
roi_indices = parse_range(page_range, doc.page_count)
for page_index in range(doc.page_count):
Expand All @@ -1240,7 +1246,9 @@ def watermark_pdf_by_image(doc_path: str, wm_path: str, page_range: str = "all",
page = doc[-1]
p = Path(doc_path)
tmp_wm_path = str(p.parent / "tmp_wm.pdf")
create_image_wartmark(wm_image_path=wm_path, width=page.rect.width, height=page.rect.height, output_path=tmp_wm_path, **args)
ok = create_image_wartmark(wm_image_path=wm_path, width=page.rect.width, height=page.rect.height, output_path=tmp_wm_path, **args)
if not ok:
return
wm_doc = fitz.open(tmp_wm_path)
roi_indices = parse_range(page_range, doc.page_count)
for i in roi_indices:
Expand Down

0 comments on commit 0880396

Please sign in to comment.