# import requests
# import json
# # Step 1: Load large HTML content from external file
# with open("template.html", "r", encoding="utf-8") as f:
# html_content = f.read()
# # Step 2: Prepare payload
# payload = json.dumps({
# "html_content": html_content
# })
# headers = {
# 'Content-Type': 'application/json'
# }
# # Step 3: Make the API request
# url = "http://localhost:5000/api/html-to-pdf"
# response = requests.post(url, headers=headers, data=payload)
# # Step 4: Save the PDF if successful
# if response.status_code == 200:
# with open("output.pdf", "wb") as f:
# f.write(response.content)
# print("✅ PDF saved as output.pdf")
# else:
# print(f"❌ Error: {response.status_code}\n{response.text}")
#this is option 1
# this is option 2
import requests
import json
# Inline HTML (okay for small content only)
html_content = """
Business Performance Report
Quarterly Performance Report
Q3 2023 Business Metrics & Analytics
Executive Summary
This report provides a comprehensive overview of business performance for Q3 2023. Our company has demonstrated strong growth across key metrics, with particular success in customer acquisition and revenue generation.
+15.3%
Revenue Growth
+22.7%
New Customers
94.2%
Customer Satisfaction
+8.5%
Operational Efficiency
Revenue Analysis
Monthly Revenue (in millions)
Revenue growth over the past six months shows consistent upward trajectory.
Breakdown of revenue by product category for Q3 2023.
Software Solutions (35%)
Consulting Services (30%)
Hardware Products (20%)
Support & Maintenance (15%)
"""
# Prepare payload
payload = json.dumps({
"html_code": html_content
})
headers = {
'Content-Type': 'application/json'
}
# Send request
url = "http://localhost:5000/api/html-to-pdf"
response = requests.post(url, headers=headers, data=payload)
# Save result
import json
# Step 1: Full JSON string
json_data = response.text
# Step 2: Parse JSON to extract the list string
data = json.loads(json_data)
byte_string = data["pdf_base64"]
# Step 3: Convert to byte list
byte_list = [int(b.strip()) for b in byte_string.split(",")]
# Step 4: Convert to bytes and save as PDF
pdf_data = bytes(byte_list)
with open("outputs.pdf", "wb") as f:
f.write(pdf_data)
print("✅ PDF saved as outputs.pdf")