Advertisement
Python253

create_example_pdf

Mar 11th, 2024
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Filename: create_example_pdf.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9. This script creates an example PDF file using the fpdf library.
  10. It demonstrates how to add a title and content to the PDF.
  11.  
  12. Requirements:
  13. - Python 3.x
  14. - FPDF library (install using: pip install fpdf)
  15.  
  16. Usage:
  17. 1. Save this script as 'create_example_pdf.py'.
  18. 2. Install the FPDF library using the command: 'pip install fpdf'
  19. 3. Run the script.
  20.  
  21. Note: Adjust the 'pdf_filename' variable in the script as needed.
  22. """
  23. from fpdf import FPDF
  24.  
  25. def create_example_pdf(pdf_filename):
  26.     pdf = FPDF()
  27.     pdf.add_page()
  28.     pdf.set_font("Arial", size=12)
  29.  
  30.     # Example data
  31.     title = "Example PDF"
  32.     content = (
  33.         "This is an example PDF file created using the fpdf library.\n"
  34.         "Content: Hello, World!."
  35.     )
  36.  
  37.     # Add title
  38.     pdf.set_font("Arial", 'B', 16)
  39.     pdf.cell(0, 10, title, 0, 1, 'C')
  40.     pdf.ln(10)
  41.  
  42.     # Add content
  43.     pdf.set_font("Arial", size=12)
  44.     pdf.multi_cell(0, 10, content)
  45.  
  46.     # Save the PDF
  47.     pdf.output(pdf_filename)
  48.  
  49. if __name__ == "__main__":
  50.     pdf_filename = 'example.pdf'
  51.     create_example_pdf(pdf_filename)
  52.     print(f"Example PDF file '{pdf_filename}' created.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement