First working implementation of the program

This commit is contained in:
2026-07-27 17:42:48 +09:00
parent 9f9c72e824
commit e5bb49a596
12 changed files with 618 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
import logging
from xmlrpc.client import boolean
##############################################################################################################################
#Function to create a simple logger that logs messages to a file and optionally prints them to the console.
#If logger_name = "", then the root logger will be used. If you want to create a custom logger, provide a name for it.
##############################################################################################################################
def simple_logger(log_relative_path = str, printToConsole = boolean, logger_name = ""):
logger = logging.getLogger(logger_name)
logger.setLevel(logging.INFO)
formatter = logging.Formatter(fmt="%(asctime)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S")
file_handler = logging.FileHandler(log_relative_path)
file_handler.setFormatter(formatter)
file_handler.setLevel(logging.INFO)
logger.addHandler(file_handler)
if printToConsole:
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
console_handler.setLevel(logging.INFO)
logger.addHandler(console_handler)
return logger
+60
View File
@@ -0,0 +1,60 @@
html_template = """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
/* Existing styles... */
/* Styles for Links */
a {{
color: #0000ff; /* Sets the link color to blue */
text-decoration: underline; /* Ensures the underline is visible */
}}
a:visited {{
color: #0000ff; /* Keeps the link blue even after it is clicked */
}}
/* Styles for clean Table Lines */
table {{
width: 100%;
border-collapse: collapse; /* Merges adjacent cell borders into a single line */
margin: 20px 0;
font-size: 11pt;
}}
th, td {{
border: 1px solid #bdc3c7; /* Draws the actual grid lines */
padding: 10px;
text-align: left;
}}
th {{
background-color: #f2f4f4; /* Optional: adds a neat background header color */
font-weight: bold;
color: #2c3e50;
}}
tr:nth-child(even) {{
background-color: #f9f9f9; /* Optional: adds zebra striping to rows */
}}
</style>
</head>
<body>
{content}
</body>
</html>
"""
import markdown
from weasyprint import HTML
def export_to_pdf(inputText, filename):
# Step 1: Convert Markdown components to HTML chunks.
# The 'tables' and 'fenced_code' extensions keep standard LLM formatting neat.
html_content = markdown.markdown(inputText, extensions=['tables', 'fenced_code'])
# Step 2: Inject the content into our CSS-styled HTML boilerplate template
final_html = html_template.format(content=html_content)
# Step 3: Render directly to a high-fidelity PDF file
HTML(string=final_html).write_pdf(filename)
#print(f"Successfully generated styled PDF at: {output_pdf_path}")