Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: create_example_pdf.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script creates an example PDF file using the fpdf library.
- It demonstrates how to add a title and content to the PDF.
- Requirements:
- - Python 3.x
- - FPDF library (install using: pip install fpdf)
- Usage:
- 1. Save this script as 'create_example_pdf.py'.
- 2. Install the FPDF library using the command: 'pip install fpdf'
- 3. Run the script.
- Note: Adjust the 'pdf_filename' variable in the script as needed.
- """
- from fpdf import FPDF
- def create_example_pdf(pdf_filename):
- pdf = FPDF()
- pdf.add_page()
- pdf.set_font("Arial", size=12)
- # Example data
- title = "Example PDF"
- content = (
- "This is an example PDF file created using the fpdf library.\n"
- "Content: Hello, World!."
- )
- # Add title
- pdf.set_font("Arial", 'B', 16)
- pdf.cell(0, 10, title, 0, 1, 'C')
- pdf.ln(10)
- # Add content
- pdf.set_font("Arial", size=12)
- pdf.multi_cell(0, 10, content)
- # Save the PDF
- pdf.output(pdf_filename)
- if __name__ == "__main__":
- pdf_filename = 'example.pdf'
- create_example_pdf(pdf_filename)
- print(f"Example PDF file '{pdf_filename}' created.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement