Created
August 9, 2023 18:13
-
-
Save EnkrateiaLucca/5d15c6f52c3ed26c337b1c87f788d642 to your computer and use it in GitHub Desktop.
Creates a pdf using the fpdf package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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