ppt2fig 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ppt2fig/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .main import main
2
+
3
+ if __name__=="__main__":
4
+ main()
ppt2fig/index.py ADDED
@@ -0,0 +1,5 @@
1
+ from .main import main as __main__
2
+
3
+
4
+ # if __name__=="__main__":
5
+ # main()
ppt2fig/main.py ADDED
@@ -0,0 +1,101 @@
1
+ import os
2
+ import shutil
3
+ import comtypes.client
4
+ from pdfCropMargins import crop
5
+ import tkinter as tk
6
+ from tkinter.filedialog import asksaveasfilename
7
+
8
+ def ppt_2_pdf(input_ppt_file, page_index, output_pdf_file):
9
+ """
10
+ Convert a Powerpoint file to a pdf file
11
+ :param input_ppt_file: input Powerpoint file
12
+ :param output_pdf_file: output pdf file
13
+ :param format_type:
14
+ :return: a pdf file written in the directory
15
+ """
16
+ powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
17
+ powerpoint.Visible = 1
18
+ input_ppt_file=os.path.abspath(input_ppt_file)
19
+ ppt_file = powerpoint.Presentations.Open(input_ppt_file,ReadOnly=True)
20
+ print_range=ppt_file.PrintOptions.Ranges.Add(page_index,page_index)
21
+ output_pdf_file=os.path.abspath(output_pdf_file)
22
+ if os.path.exists(output_pdf_file):
23
+ os.remove(output_pdf_file)
24
+ ppt_file.ExportAsFixedFormat(output_pdf_file,2,PrintRange=print_range,RangeType=4)
25
+ ppt_file.Close()
26
+
27
+ def current_slide_2_pdf(output_pdf_file):
28
+ """
29
+ Convert a Powerpoint file to a pdf file
30
+ :param output_pdf_file: output pdf file
31
+ :return: a pdf file written in the directory
32
+ """
33
+ try:
34
+ powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
35
+ powerpoint.Visible = 1
36
+ # 尝试获取当前活动的PPT文件
37
+ ppt_file = powerpoint.ActivePresentation
38
+ output_pdf_file = os.path.abspath(output_pdf_file)
39
+ if os.path.exists(output_pdf_file):
40
+ os.remove(output_pdf_file)
41
+ ppt_file.ExportAsFixedFormat(output_pdf_file,2,RangeType=3)
42
+ return True
43
+ except Exception as e:
44
+ tk.messagebox.showerror("错误", f"转换过程出错:{str(e)}")
45
+ return False
46
+
47
+ def main():
48
+ root = tk.Tk()
49
+ defalut_path_map = {} # 对于 每个ppt文件,他的默认导出路径是不同的
50
+
51
+ def helloCallBack():
52
+ try:
53
+ powerpoint = comtypes.client.GetActiveObject("Powerpoint.Application")
54
+ except Exception as e:
55
+ tk.messagebox.showerror("错误", f"Powerpoint应用程序未启动!")
56
+ return
57
+
58
+ try:
59
+ # 先尝试获取当前PPT文件的路径作为默认保存路径
60
+ ppt_file = powerpoint.ActivePresentation
61
+ except Exception as e:
62
+ tk.messagebox.showerror("错误", f"当前没有PPT文件打开!")
63
+ return
64
+
65
+ # 获取PPT文件的路径和文件名(不带扩展名)
66
+ ppt_path = os.path.dirname(ppt_file.FullName)
67
+ ppt_name = os.path.splitext(ppt_file.Name)[0]
68
+
69
+ if ppt_path not in defalut_path_map:
70
+ initial_file = os.path.join(ppt_path, ppt_name + '.pdf')
71
+ defalut_path_map[ppt_path] = initial_file
72
+ else:
73
+ initial_file = defalut_path_map[ppt_path]
74
+
75
+ # 设置默认保存路径和文件名
76
+
77
+ pdf_file_name = asksaveasfilename(
78
+ parent=root,
79
+ initialfile=os.path.basename(initial_file),
80
+ initialdir=os.path.dirname(initial_file),
81
+ filetypes=[("PDF file", "*.pdf")]
82
+ )
83
+
84
+ if pdf_file_name is None or len(pdf_file_name) == 0:
85
+ return
86
+
87
+ if not pdf_file_name.endswith('.pdf'):
88
+ pdf_file_name = pdf_file_name + '.pdf'
89
+
90
+ if current_slide_2_pdf(pdf_file_name):
91
+ tmp_pdf_file_name = pdf_file_name + '.crop'
92
+ crop(["-p", "0", "-u", "-s", pdf_file_name, "-o", tmp_pdf_file_name])
93
+ shutil.move(tmp_pdf_file_name, pdf_file_name)
94
+
95
+ root.attributes("-topmost", True)
96
+ B = tk.Button(root, text="转PDF", command=helloCallBack)
97
+ B.pack()
98
+ root.mainloop()
99
+
100
+ if __name__ == "__main__":
101
+ main()
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ElliottZheng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.2
2
+ Name: ppt2fig
3
+ Version: 1.0.0
4
+ License-File: LICENSE
5
+ Requires-Dist: comtypes
6
+ Requires-Dist: pdfCropMargins
7
+ Dynamic: requires-dist
@@ -0,0 +1,9 @@
1
+ ppt2fig/__main__.py,sha256=MU1ByXR2PacUPAXPC7zdkBekBmcuQYjen7WFETpzNgY,62
2
+ ppt2fig/index.py,sha256=wLy6vGFSquQdtNtLSNfcsESd85ZBsnQmOx04kktCUlI,80
3
+ ppt2fig/main.py,sha256=4HAD10sfHhahBUS-nlmZsZ7eEDK6Aas__8W1LlSFTNk,3845
4
+ ppt2fig-1.0.0.dist-info/LICENSE,sha256=MyyyaM38v58LOOAGCghKKtnen94jDGvXo8tLlVruGwk,1088
5
+ ppt2fig-1.0.0.dist-info/METADATA,sha256=k8W6X2-ECbrXXArc1RApPlkBlgAW_E01fuMMt22YG0o,157
6
+ ppt2fig-1.0.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ ppt2fig-1.0.0.dist-info/entry_points.txt,sha256=eJakz7ZhInv0pkcEJ2_vdSh_f1bEwlCf2iHB1xvoEJs,46
8
+ ppt2fig-1.0.0.dist-info/top_level.txt,sha256=q5tWD05SBA8v3HKIgMbvXhijbN8fNsdGbVbNEmqnxzg,8
9
+ ppt2fig-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ppt2fig = ppt2fig.main:main
@@ -0,0 +1 @@
1
+ ppt2fig