Make pdf in no time with Python (and html)

You can make pdf as fast as you want, using no program but Python, and also using html. So… let’s go.

We need to use the pdfkit module.

Go in cmd and install it this way:

pip install pdfkit
import tkinter as tk
import pdfkit
import os


def pdf(event):
    x = "my.pdf"
    content = txbx.get("0.0", tk.END)
    pdfkit.from_string(content, x)
    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()
txbx.bind("<Control-b>", pdf)

root.mainloop()

Video


Subscribe to the newsletter for updates
Tkinter templates

Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Claude's Games

Arkanoid
Platform 2d

1. Memory game

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

 

Advertisement