Skip to content

Instantly share code, notes, and snippets.

@EnkrateiaLucca
Created August 9, 2023 18:13
Show Gist options
  • Save EnkrateiaLucca/5d15c6f52c3ed26c337b1c87f788d642 to your computer and use it in GitHub Desktop.
Save EnkrateiaLucca/5d15c6f52c3ed26c337b1c87f788d642 to your computer and use it in GitHub Desktop.
Creates a pdf using the fpdf package
import fpdf
def make_pdf(text):
"""Makes a PDF file from the given text."""
# Create a new FPDF object.
pdf = fpdf.FPDF()
# Add a page to the PDF object.
pdf.add_page()
# Set the font of the text.
pdf.set_font("Arial", size=12)
# Insert the text into the page.
pdf.cell(200, 10, text)
# Save the PDF file.
pdf.output("output.pdf")
if __name__ == "__main__":
text = "This is a sample PDF file created with Python."
make_pdf(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment