Back and updated due to popular demand!
Dear friends and Pickaxe legends,
Here is how you can generate a basic PDF (unbranded) using the existing ‘PDF Generator’ action.
1) Click on the PDF Gen action
2) Click ‘Clone’
3) Update your trigger prompt to inform the action what is should do and when.
4) Fill in the essential fields
5) Under the ‘Additional packages’ section remove the preexisting XML PDF Python package, and replace it with ‘FPDF’ instead.
Code template:
You can use this code as a template, but pay attention to indentation in your code as it could cause errors.
import os
import requests
from fpdf import fpdf
def generate_pdf_audit_report(analysis_data: str):
"""
This action generates a professionally formatted Amazon Listing Audit Report as a PDF. The report includes a structured analysis of the listing, highlighting areas for optimization, compliance issues, and strategic recommendations for improving visibility and conversions.
Args:
analysis_data (string): The structured Amazon Listing Analysis data returned from the Make workflow.
"""
pdf_filename = "Amazon_Listing_Audit_Report.pdf"
pdf_path = os.path.join("/tmp", pdf_filename)
try:
# Initialize PDF
pdf = FPDF()
pdf.set_auto_page_break(auto=True, margin=15)
pdf.add_page()
# Branding Colors
header_bg_color = (0, 74, 173) # Blue
header_text_color = (255, 255, 255) # White
body_text_color = (0, 0, 0) # Black
# Header Section
pdf.set_fill_color(*header_bg_color)
pdf.set_text_color(*header_text_color)
pdf.set_font("Arial", "B", 16)
pdf.cell(200, 10, "Amazon Listing Optimization Report", ln=True, align='C', fill=True)
# Reset text color for body
pdf.set_text_color(*body_text_color)
# Section: Audit Summary
pdf.set_font("Arial", "B", 14)
pdf.cell(200, 10, "Audit Summary", ln=True)
pdf.set_font("Arial", "", 12)
pdf.multi_cell(0, 10, analysis_data.split("\n")[0]) # First line as summary
# Section: Detailed Findings
pdf.set_font("Arial", "B", 14)
pdf.cell(200, 10, "Detailed Findings", ln=True)
pdf.set_font("Arial", "", 12)
for line in analysis_data.split("\n")[1:5]: # Findings section
pdf.cell(0, 10, f"- {line.strip()}", ln=True)
# Section: Recommended Improvements
pdf.set_font("Arial", "B", 14)
pdf.cell(200, 10, "Recommended Improvements", ln=True)
pdf.set_font("Arial", "", 12)
for rec in analysis_data.split("\n")[5:]: # Recommendations
pdf.cell(0, 10, f"- {rec.strip()}", ln=True)
# Save PDF
pdf.output(pdf_path)
return pdf_path
except Exception as e:
error_log_path = "/tmp/pdf_generation_error.log"
with open(error_log_path, "w") as log_file:
log_file.write(f"Error generating PDF: {str(e)}\n")
log_file.write(traceback.format_exc())
return f"Error occurred. See log file: {error_log_path}"
The result should look something like this (note the code may or may not have some CSS from one of my previous projects. Feel free to update the template to work for your project!):
If you have any questions drop them down below!