-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
101 lines (81 loc) · 2.87 KB
/
Copy pathmain.py
File metadata and controls
101 lines (81 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from pypdf import PdfWriter
import pdfkit
# Create a PDF merger object
merger = PdfWriter()
# Path to wkhtmltopdf.exe (download and install if not already)
path_wkhtmltopdf = r"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"
config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
# PDF Generator---------------------------------------------------------------------------------------------------------
# Ask user for content
def gen_pdf():
title = input("Enter a title for your PDF page: ")
body_content = input("Paste your content here: ")
# HTML Template (with styling like a modern webpage)
html = f"""
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{title}</title>
<style>
body {{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 40px;
background-color: #f4f4f4;
color: #333;
}}
.container {{
background: #fff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0,0,0,0.1);
}}
h1 {{
color: #007BFF;
text-align: center;
}}
p {{
font-size: 16px;
line-height: 1.6;
}}
</style>
</head>
<body>
<div class="container">
<h1>{title}</h1>
<p>{body_content}</p>
</div>
</body>
</html>
"""
# Generate PDF
pdfkit.from_string(html, "generated_pdf.pdf", configuration=config)
print("✅ Stylish PDF generated successfully: generated_pdf.pdf")
# ----------------------------------------------------------------------------------------
# PDF Merger-------------------------------------------------------------------------------------------------------------
def merge():
ls = input("Enter names separated by spaces:\n").split()
for pdf in ls:
merger.append(pdf)
# Merge pdf
merger.write("super_merged.pdf")
merger.close()
print("✅ PDFs merged successfully: super_merged.pdf")
# ----------------------------------------------------------------------------------------------------------------------------
# run the program
def main():
while True:
print("1. Generate PDF")
print("2. Merge PDFs")
print("3. Exit")
choice = input("Enter your choice: ")
if choice == '1':
gen_pdf()
elif choice == '2':
merge()
elif choice == '3':
break
if __name__ == "__main__":
main()
# Created By Rohit Sharma
# -----------------------------------------------------------------------------------------------------------------------------