0% found this document useful (0 votes)
2 views2 pages

Generate Rich Text PDF Reports

The document provides a Python script using the FPDF library to create a rich text PDF with 6 pages. Each page includes a main header, subheader, standard paragraphs, and a simulated bulleted list. The script generates 5 separate PDF files named 'Generated_Report_1.pdf' to 'Generated_Report_5.pdf'.

Uploaded by

prudhviraj5228
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Generate Rich Text PDF Reports

The document provides a Python script using the FPDF library to create a rich text PDF with 6 pages. Each page includes a main header, subheader, standard paragraphs, and a simulated bulleted list. The script generates 5 separate PDF files named 'Generated_Report_1.pdf' to 'Generated_Report_5.pdf'.

Uploaded by

prudhviraj5228
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

from fpdf import FPDF

def create_rich_text_pdf(filename, doc_number):


pdf = FPDF()
pdf.set_auto_page_break(auto=True, margin=15)

# Content to simulate rich text


lorem_ipsum = (
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
"Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris "
"nisi ut aliquip ex ea commodo consequat. "
)

# Create 6 Pages
for page_num in range(1, 7):
pdf.add_page()

# 1. Main Header (Bold, Large)


pdf.set_font("Arial", "B", 24)
[Link](0, 20, f"Document #{doc_number}: Page {page_num}", ln=True, align='C')

# 2. Subheader (Italic)
pdf.set_font("Arial", "I", 14)
pdf.set_text_color(100, 100, 100) # Grey color
[Link](0, 10, "Section 1: Introduction to Rich Text", ln=True)

# 3. Standard Paragraph
pdf.set_text_color(0, 0, 0) # Reset to black
pdf.set_font("Arial", "", 12)
pdf.multi_cell(0, 10, lorem_ipsum * 3)
[Link](10)

# 4. Bulleted List Simulation


pdf.set_font("Arial", "B", 12)
[Link](0, 10, "Key Points:", ln=True)
pdf.set_font("Arial", "", 12)
for i in range(1, 4):
[Link](10, 10, f"-", align='R')
[Link](0, 10, f"Important point number {i} regarding this topic.", ln=True)

[Link](10)

# 5. Footer Text
pdf.set_font("Courier", "I", 10)
pdf.multi_cell(0, 10, "Note: This document was generated automatically to simulate a 6-page rich text
format.")

[Link](filename)

# Loop to generate 5 separate files


for i in range(1, 6):
filename = f"Generated_Report_{i}.pdf"
create_rich_text_pdf(filename, i)
print(f"Successfully created: {filename}")

You might also like