Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdf #224

Open
adunraharza opened this issue Dec 15, 2024 · 1 comment
Open

pdf #224

adunraharza opened this issue Dec 15, 2024 · 1 comment

Comments

@adunraharza
Copy link

from fpdf import FPDF

class PDF(FPDF):
def header(self):
self.set_font('Arial', 'B', 12)
self.cell(0, 10, 'Tabel Kebenaran', 0, 1, 'C')

def chapter_title(self, title):
    self.set_font('Arial', 'B', 12)
    self.cell(0, 10, title, 0, 1, 'L')
    self.ln(5)

def chapter_body(self, body):
    self.set_font('Arial', '', 12)
    self.multi_cell(0, 10, body)
    self.ln()

pdf = PDF()
pdf.add_page()

Tabel Kebenaran 1

pdf.chapter_title('1. (pvq)^~p')
table1 = """| p | q | p v q | ~p | (p v q) ^ ~p |
|---|---|---|---|---|
| T | T | T | F | F |
| T | F | T | F | F |
| F | T | T | T | T |
| F | F | F | T | F |"""
pdf.chapter_body(table1)

Tabel Kebenaran 2

pdf.chapter_title('2. (p^q) v (qvr)')
table2 = """| p | q | r | p ^ q | q v r | (p ^ q) v (q v r) |
|---|---|---|---|---|---|
| T | T | T | T | T | T |
| T | T | F | T | T | T |
| T | F | T | F | T | T |
| T | F | F | F | F | F |
| F | T | T | F | T | T |
| F | T | F | F | T | T |
| F | F | T | F | T | T |
| F | F | F | F | F | F |"""
pdf.chapter_body(table2)

Tabel Kebenaran 3

pdf.chapter_title('3. (pvq) vp')
table3 = """| p | q | p v q | (p v q) v p |
|---|---|---|---|
| T | T | T | T |
| T | F | T | T |
| F | T | T | T |
| F | F | F | F |"""
pdf.chapter_body(table3)

pdf.output('tabel_kebenaran.pdf')

@Lucas-C
Copy link

Lucas-C commented Dec 16, 2024

Hi @adunraharza 🙂

Note that PyFPDF is not maintained anymore.
See #207.

fpdf2 is its successor: https://pypi.org/project/fpdf2/
On GitHub it's there: https://github.com/py-pdf/fpdf2

If you are using pip, switching is very easy:

pip uninstall pypdf
pip install fpdf2

fpdf2 has support for tables: https://py-pdf.github.io/fpdf2/Tables.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants