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

E-BOOKS #199

Open
as804 opened this issue Dec 16, 2024 · 0 comments
Open

E-BOOKS #199

as804 opened this issue Dec 16, 2024 · 0 comments

Comments

@as804
Copy link

as804 commented Dec 16, 2024

from fpdf import FPDF

class PDF(FPDF):
def header(self):
self.set_font('Arial', 'B', 12)
self.cell(0, 10, 'Mi E-Book', 0, 1, 'C')
self.ln(10)

def chapter_title(self, chapter_num, chapter_title):
    self.set_font('Arial', 'B', 12)
    self.cell(0, 10, f'Capítulo {chapter_num} : {chapter_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()

def add_chapter(self, chapter_num, chapter_title, body):
    self.add_page()
    self.chapter_title(chapter_num, chapter_title)
    self.chapter_body(body)

Crear instancia del PDF

pdf = PDF()
pdf.set_left_margin(10)
pdf.set_right_margin(10)

Añadir capítulos

pdf.add_chapter(1, 'Introducción', 'Este es el texto del primer capítulo de mi e-book.')
pdf.add_chapter(2, 'Capítulo 2', 'Este es el texto del segundo capítulo de mi e-book.')

Guardar el PDF

pdf.output('mi_ebook.pdf')

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

1 participant