A simple script to generate a pdf from a text or an html. You need to install pdfkit
pip install pdfkit
https://github.com/formazione/python_book
https://github.com/formazione/pypdf
import tkinter as tk
import pdfkit
import os
def pdf(event):
filename = "my.pdf"
content = txbx.get("0.0", tk.END)
# you can go to the next line with this code
content = content.replace("\n", "<br>")
pdfkit.from_string(content, filename)
print("pdf created")
os.startfile("my.pdf")
root = tk.Tk()
# WIDGETS: text box => Text class of tkinter (tk)
label = tk.Label(root, text="CTRL + b to make a page (use also html)")
label.pack()
txbx = tk.Text(root, height=20, insertbackground="white")
txbx['font'] = "Arial 14"
txbx['bg'] = "black"
txbx['fg'] = "white"
txbx['borderwidth'] = 2
txbx.pack(fill=tk.BOTH, expand=1)
txbx.focus()
# Command that creates the pdf from the text
txbx.bind("<Control-b>", pdf)
root.mainloop()
Twitter: @pythonprogrammi - python_pygame