Python Forum
Using Pypdf2 write a string to a pdf file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Pypdf2 write a string to a pdf file
#5
Thank you very much! I can use that!

Question: where should I put text2pdf.py? I mean, so that when I run the python script in bash, bash will find text2pdf.py?

I think I expressed myself badly. I will read each row of each excel file as a string, then write the strings of 1 excel file to 1 pdf, so that 1 pdf contains the data of 1 excel file.

Also, I was advised to use fpdf. I have not tried this yet, ran out of time yesterday.

# https://pyfpdf.readthedocs.io/en/latest/
import fpdf #pip3 install 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")
Reply


Messages In This Thread
RE: Using Pypdf2 write a string to a pdf file - by Pedroski55 - Apr-11-2019, 09:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  What does .flush do? How can I change this to write to the file? Pedroski55 3 337 Apr-22-2024, 01:15 PM
Last Post: snippsat
  Last record in file doesn't write to newline gonksoup 3 516 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  write to csv file problem jacksfrustration 11 1,724 Nov-09-2023, 01:56 PM
Last Post: deanhystad
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,661 Nov-09-2023, 10:56 AM
Last Post: mg24
  PyPDF2 deprecation problem gowb0w 5 4,629 Sep-21-2023, 12:38 PM
Last Post: Pedroski55
  Need to replace a string with a file (HTML file) tester_V 1 815 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  ModuleNotFoundError: No module named 'PyPDF2' Benitta2525 1 1,677 Aug-07-2023, 05:32 AM
Last Post: DPaul
  How do I read and write a binary file in Python? blackears 6 7,474 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,173 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Read text file, modify it then write back Pavel_47 5 1,738 Feb-18-2023, 02:49 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020