-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPDFConvertor.py
More file actions
43 lines (37 loc) · 1.12 KB
/
PDFConvertor.py
File metadata and controls
43 lines (37 loc) · 1.12 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
from fpdf import FPDF
from datetime import datetime
def create_pdf_with_github_link(text, github_url, pdf_name):
#Create PDF object
pdf = FPDF()
# Add a page
pdf.add_page()
#Set Font
pdf.set_font("Arial", size=12)
try:
# Add some text
pdf.cell(0, 10, "Test PDF Creation", ln=True)
pdf.cell(0, 10, f"Created on: {datetime.now()}", ln=True)
pdf.image("github.png", x=10, y=pdf.get_y(), w=10)
except Exception as e:
print(f"Error creating PDF: {e}")
#Add github link
pdf.set_text_color(0,0,255)
# Create a clickable link
pdf.cell(0,10,txt=github_url,link=github_url)
#Save the PDF
pdf.output(pdf_name)
#Call the function
if __name__ == "__main__":
print("Enter your text(Press Enter to finish): ")
lines = []
while True:
line = input()
if line == "":
lines.append(line)
break
text = "\n".join(lines)
#Get Github repository URL
github = input("Enter your Github URL: ")
#Create PDF
create_pdf_with_github_link(text, github, "Github_Link.pdf")
print("PDF Created Successfully")