# 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.

$5.0M $4.0M $3.0M $2.0M $1.0M $0
$3.0M
Apr
$3.3M
May
$3.5M
Jun
$4.0M
Jul
$4.5M
Aug
$5.0M
Sep

Revenue Growth Trend

Quarter-over-quarter growth rate demonstrates accelerating momentum.

+5%
+8%
+12%
+15%
Q4 2022
Q1 2023
Q2 2023
Q3 2023

Market Share Analysis

Product Category Distribution

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")