Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to save a textbox text as a pdf file but I got an encoding error, I have tried the following:

What I have tried:

from tkinter import *
 from tkinter import ttk
 from tkinter import filedialog
 from tkinter.filedialog import askopenfile
 from tkinter.filedialog import * 
 from fpdf import FPDF

def export(self):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", size=15)
    pdf.cell(40, 10, self.agreemanttext.get("1.0", END).strip())
    pdf.output(asksaveasfilename(filetypes=[("PDF file", "*.pdf")]), "F")


def agreemnttext(self):
    self.buying_agreementsample_cash ="""text"""
    self.agreemanttextframe = Frame(self.agreemantpage, width=900, height=900)
    self.agreemanttextframe.place(x=1, y=40)
    self.agreemanttext = Text(self.agreemanttextframe, width=124, height=57)
    self.agreemanttext.pack()
    self.agreemanttext.tag_configure('tag-center', justify='right')
    self.agreemanttext.insert('end', self.buying_agreementsample_cash, 'tag-center')
    self.agreemanttext.config(state='disabled')

    self.exportbutton=Button(self.agreemantpage,text="export as pdf",command=self.export)
    self.exportbutton.place(x=80,y=600)

but I got this error: p = self.pages[n].encode("latin1") if PY3K else self.pages[n] UnicodeEncodeError: 'latin-1' codec can't encode characters in position 50-54: ordinal not in range(256)
Posted
Updated 2-Jun-22 15:47pm
v3

1 solution

You can paste the text file in a word processing software like Google Docs or Microsoft Word and then you can download or save them as pdf. Thanks
 
Share this answer
 
Comments
OriginalGriff 3-Jun-22 0:20am    
This is not a solution to a development problem: it requires user effort instead of software automation!

Think of it like driving a car: your solution requires each passenger to have their own chauffer on call 24 hours a day!
asaad kittaneh 3-Jun-22 11:17am    
Pandora Finance thank you for answering, but I think it need more of a critical solution
asaad kittaneh 3-Jun-22 11:18am    
@OriginalGriff is there any solution ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900