-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (36 loc) · 1.72 KB
/
main.py
File metadata and controls
45 lines (36 loc) · 1.72 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
import json
from reportlab.lib.pagesizes import A4
from reportlab.lib import colors
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import getSampleStyleSheet
# Load data from JSON file
with open("data.json", "r", encoding="utf-8") as f:
data = json.load(f)
# Create PDF with zero margins
pdf_file = r"C:\Users\Smoothingo\Downloads\p_output.pdf" # Change this path to your desired output path
pdf = SimpleDocTemplate(pdf_file, pagesize=A4, rightMargin=0, leftMargin=0, topMargin=0, bottomMargin=0)
elements = []
# Get the default style
styles = getSampleStyleSheet()
normal_style = styles["BodyText"]
# Extract relevant information and add it to the PDF
for vault_id, vault_content in data["vaults"].items():
for item in vault_content["items"]:
service_name = item["data"]["metadata"].get("name", "N/A")
email = item["data"]["content"].get("itemEmail", "N/A")
password = item["data"]["content"].get("password", "N/A")
url = item["data"]["content"].get("urls", ["N/A"])[0] if item["data"]["content"].get("urls") else "N/A"
# Create a formatted text string for each account without line breaks
account_info = (
f"Service: {service_name}\n"
f"Username/Email: {email}\n"
f"Password: {password}\n"
f"URL: {url}\n"
)
# Add the account info as a single Paragraph
elements.append(Paragraph(account_info.replace('\n', '<br/>'), normal_style))
# Add a small space after each account using a blank line
elements.append(Paragraph("<br/>", normal_style)) # This creates a line break
# Build the PDF
pdf.build(elements)
print(f"PDF generated successfully as '{pdf_file}'")