Skip to main content
added 137 characters in body
Source Link
Fabian
  • 1.1k
  • 11
  • 26

I know you asked for PyPDF2 but more simple approach with FPDF:

# https://pyfpdf.readthedocs.io/en/latest/
import fpdf #pip3 intall fpdf
 
pdf = fpdf.FPDF(format='letter') #pdf format
pdf.add_page() #create new page
pdf.set_font("Arial", size=12) # font and textsize
pdf.cell(200, 10, txt="your text", ln=1, align="L")
pdf.cell(200, 10, txt="your text", ln=2, align="L")
pdf.cell(200, 10, txt="your text", ln=3, align="L")
pdf.output("test.pdf")

As you mentioned you dont understand, PyPDF doc so well so i think FPDF is a good start.

PyPDF2 is more suited for reading and merging pdf files.

If you realy like to use PyPDF2 you could achieve text with canvas.

I know you asked for PyPDF2 but more simple approach with FPDF:

# https://pyfpdf.readthedocs.io/en/latest/
import fpdf #pip3 intall fpdf
 
pdf = fpdf.FPDF(format='letter') #pdf format
pdf.add_page() #create new page
pdf.set_font("Arial", size=12) # font and textsize
pdf.cell(200, 10, txt="your text", ln=1, align="L")
pdf.cell(200, 10, txt="your text", ln=2, align="L")
pdf.cell(200, 10, txt="your text", ln=3, align="L")
pdf.output("test.pdf")

As you mentioned you dont understand, PyPDF doc so well so i think FPDF is a good start.

I know you asked for PyPDF2 but more simple approach with FPDF:

# https://pyfpdf.readthedocs.io/en/latest/
import fpdf #pip3 intall fpdf
 
pdf = fpdf.FPDF(format='letter') #pdf format
pdf.add_page() #create new page
pdf.set_font("Arial", size=12) # font and textsize
pdf.cell(200, 10, txt="your text", ln=1, align="L")
pdf.cell(200, 10, txt="your text", ln=2, align="L")
pdf.cell(200, 10, txt="your text", ln=3, align="L")
pdf.output("test.pdf")

As you mentioned you dont understand, PyPDF doc so well so i think FPDF is a good start.

PyPDF2 is more suited for reading and merging pdf files.

If you realy like to use PyPDF2 you could achieve text with canvas.

Source Link
Fabian
  • 1.1k
  • 11
  • 26

I know you asked for PyPDF2 but more simple approach with FPDF:

# https://pyfpdf.readthedocs.io/en/latest/
import fpdf #pip3 intall fpdf
 
pdf = fpdf.FPDF(format='letter') #pdf format
pdf.add_page() #create new page
pdf.set_font("Arial", size=12) # font and textsize
pdf.cell(200, 10, txt="your text", ln=1, align="L")
pdf.cell(200, 10, txt="your text", ln=2, align="L")
pdf.cell(200, 10, txt="your text", ln=3, align="L")
pdf.output("test.pdf")

As you mentioned you dont understand, PyPDF doc so well so i think FPDF is a good start.