Re: Postscript to pdf
Am 21.09.15 um 17:20 schrieb Baladjy KICHENASSAMY: Hello, This is my programe : on mac i was able to output ps file but i didn't got the pdf file :/ Maybe ps2pdf is not installed? I think it doesn't come with the Mac. You need to get it via fink, homebrew, macports or an official ghostscript binary. The same holds true for convert, which is a tool from ImageMagick. Yet another option would be to wrap the pdf4tcl library: http://sourceforge.net/projects/pdf4tcl/ It can create PDF from a canvas without an external dependency. The Tcl code for it looks like this: package require pdf4tcl set size [list [winfo width $win] [winfo height $win]] set pdf [pdf4tcl::new %AUTO% -paper $size -compress false] $pdf canvas $win $pdf write -file $fn $pdf destroy In principle, you could run this code via Tkinter.eval() You would need to set "win" to your canvas path and "fn" to the file name path. Yet another option would be to use a Python package like Reportlab to create the PDFs, which requires you to reimplement the drawing code. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
On Tuesday, September 22, 2015 at 2:20:56 AM UTC-5, Bala Ji wrote: > Hello, > This is my programe : on mac i was able to output ps file but i didn't > got the pdf file :/ > > # -*- coding: utf-8 -*- > # script lecture_gif.py > from Tkinter import * > import tkMessageBox > import Tkconstants > import tkFileDialog > from PIL import ImageTk > import PIL.Image > import os, sys > import subprocess > > > def Ouvrir(): > Canevas.delete(ALL) # on efface la zone graphique > > filename = tkFileDialog.askopenfilename(title="Ouvrir une > image",filetypes=[('gif files','.gif'),('all files','.*')]) > print(filename) > photo = PhotoImage(file=filename) > gifdict[filename] = photo # référence > print(gifdict) > > Canevas.create_image(0,0,anchor=NW,image=photo) > Canevas.config(height=photo.height(),width=photo.width()) > > Mafenetre.title("Image "+str(photo.width())+" x "+str(photo.height())) > > def insertimage(): > n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg", > "*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')]) > img = PIL.Image.open(n) > img = img.resize((229, 253)) > photoimg = ImageTk.PhotoImage(img) > label = Label(image=photoimg) > label.image = photoimg # keep a reference! > Canevas.create_image(65,320,anchor=W,image = photoimg) > def insertsign(): > n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg", > "*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')]) > img = PIL.Image.open(n) > img = img.resize((300, 100)) > photoimg = ImageTk.PhotoImage(img) > Canevas.create_image(600,500,anchor=W,image = photoimg) > Canvas.pack() > > def Fermer(): > Canevas.delete(ALL) > Mafenetre.title("Image") > > def save(): > Canevas.update() > Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') > subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) > > # def convert(): > # ps2pdf -dEPSCrop image.ps > # convert -density 300 PASSPORTQUALITE.ps output.png > > # class TkFileDialogExample(Tkinter.Frame): > # > # def __init__(self, root): > # > # Tkinter.Frame.__init__(self, root) > # button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5} > # Tkinter.Button(self, text='Save', > command=self.asksaveasfilename).pack(**button_opt) > # > # self.file_opt = options = {} > # options['filetypes'] = [('all files', '.*'), ('text files', '.txt')] > # options['initialfile'] = 'myfile.txt' > # options['parent'] = root > # > # def asksaveasfilename(self): > # filename = tkFileDialog.asksaveasfilename(**self.file_opt) > # > # if filename: > # return open(filename, 'w') > # > # if __name__=='__main__': > # root = Tkinter.Tk() > # TkFileDialogExample(root).pack() > # root.mainloop() > def Apropos(): > tkMessageBox.showinfo("A propos","Tutorial") > > def Write(): > def delete(): > e1.delete(0,END) > e2.delete(0,END) > e3.delete(0,END) > e4.delete(0,END) > e5.delete(0,END) > e6.delete(0,END) > Canevas.delete("e1") > def valider(): > Canevas.create_text(315,200,anchor=W,text="Surname/Nom",fill='Black',font='Arial > 14') > Canevas.create_text(315,220,anchor=W,text=e1.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(315,250,anchor=W,text="Given > name/Prénom",fill='Black',font='Arial 14') > Canevas.create_text(315,270,anchor=W,text=e2.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(315,300,anchor=W,text="Fonction/Function",fill='Black',font='Arial > 14') > Canevas.create_text(315,320,anchor=W,text=e3.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(470,395,anchor=W,text=e4.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(500,438,anchor=W,text=e5.get(),fill='Black',font='Arial > 30',tags ="e1") > Canevas.create_text(228,503,anchor=W,text=e6.get(),fill='Black',font='Arial > 30',tags ="e1") > master = Tk() > Label(master, text="Surname/Nom").grid(row=0) > Label(master, text="Given name/Prénom").grid(row=1) > Label(master, text="Fonction/Function").grid(row=2) > Label(master, text="Validity Date").grid(row=3) > Label(master, text="Chef").grid(row=4) > Label(master, text="Student number").grid(row=5) > e1 = Entry(master) > e2 = Entry(master) > e3 = Entry(master) > e4 = Entry(master) > e5 = Entry(master) > e6 = Entry(master) > e1.grid(row=0, column=1) > e2.grid(row=1, column=1) > e3.grid(row=2, column=1) > e4.grid(row=3, column=1) > e5.grid(row=4, column=1) > e6.grid(row=5, column=1) > Button(master, text='Ok', command=valider).grid(row=2, column=2, > sticky=W, pady=4) > Button(master, text='Delete', command=delete).grid(row=3, column=2, > sticky=W, pady=4) > mainloop( ) > > # Main window > Mafenetre = Tk() > Mafenetre.title("Image") > > # Création d'un widget Menu > menubar = Menu(Mafenetre) > > menufichier = Menu(menubar,tearoff=0) > menufichier.add_command(label="Open mask",command=Ouvrir) >
Re: Postscript to pdf
Hello, This is my programe : on mac i was able to output ps file but i didn't got the pdf file :/ # -*- coding: utf-8 -*- # script lecture_gif.py from Tkinter import * import tkMessageBox import Tkconstants import tkFileDialog from PIL import ImageTk import PIL.Image import os, sys import subprocess def Ouvrir(): Canevas.delete(ALL) # on efface la zone graphique filename = tkFileDialog.askopenfilename(title="Ouvrir une image",filetypes=[('gif files','.gif'),('all files','.*')]) print(filename) photo = PhotoImage(file=filename) gifdict[filename] = photo # référence print(gifdict) Canevas.create_image(0,0,anchor=NW,image=photo) Canevas.config(height=photo.height(),width=photo.width()) Mafenetre.title("Image "+str(photo.width())+" x "+str(photo.height())) def insertimage(): n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg", "*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')]) img = PIL.Image.open(n) img = img.resize((229, 253)) photoimg = ImageTk.PhotoImage(img) label = Label(image=photoimg) label.image = photoimg # keep a reference! Canevas.create_image(65,320,anchor=W,image = photoimg) def insertsign(): n=tkFileDialog.askopenfilename(filetypes = [("Image Files", ("*.jpg", "*.gif")),("JPEG",'*.jpg'),("GIF",'*.gif'),('All','*')]) img = PIL.Image.open(n) img = img.resize((300, 100)) photoimg = ImageTk.PhotoImage(img) Canevas.create_image(600,500,anchor=W,image = photoimg) Canvas.pack() def Fermer(): Canevas.delete(ALL) Mafenetre.title("Image") def save(): Canevas.update() Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) # def convert(): # ps2pdf -dEPSCrop image.ps # convert -density 300 PASSPORTQUALITE.ps output.png # class TkFileDialogExample(Tkinter.Frame): # # def __init__(self, root): # # Tkinter.Frame.__init__(self, root) # button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5} # Tkinter.Button(self, text='Save', command=self.asksaveasfilename).pack(**button_opt) # # self.file_opt = options = {} # options['filetypes'] = [('all files', '.*'), ('text files', '.txt')] # options['initialfile'] = 'myfile.txt' # options['parent'] = root # # def asksaveasfilename(self): # filename = tkFileDialog.asksaveasfilename(**self.file_opt) # # if filename: # return open(filename, 'w') # # if __name__=='__main__': # root = Tkinter.Tk() # TkFileDialogExample(root).pack() # root.mainloop() def Apropos(): tkMessageBox.showinfo("A propos","Tutorial") def Write(): def delete(): e1.delete(0,END) e2.delete(0,END) e3.delete(0,END) e4.delete(0,END) e5.delete(0,END) e6.delete(0,END) Canevas.delete("e1") def valider(): Canevas.create_text(315,200,anchor=W,text="Surname/Nom",fill='Black',font='Arial 14') Canevas.create_text(315,220,anchor=W,text=e1.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(315,250,anchor=W,text="Given name/Prénom",fill='Black',font='Arial 14') Canevas.create_text(315,270,anchor=W,text=e2.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(315,300,anchor=W,text="Fonction/Function",fill='Black',font='Arial 14') Canevas.create_text(315,320,anchor=W,text=e3.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(470,395,anchor=W,text=e4.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(500,438,anchor=W,text=e5.get(),fill='Black',font='Arial 30',tags ="e1") Canevas.create_text(228,503,anchor=W,text=e6.get(),fill='Black',font='Arial 30',tags ="e1") master = Tk() Label(master, text="Surname/Nom").grid(row=0) Label(master, text="Given name/Prénom").grid(row=1) Label(master, text="Fonction/Function").grid(row=2) Label(master, text="Validity Date").grid(row=3) Label(master, text="Chef").grid(row=4) Label(master, text="Student number").grid(row=5) e1 = Entry(master) e2 = Entry(master) e3 = Entry(master) e4 = Entry(master) e5 = Entry(master) e6 = Entry(master) e1.grid(row=0, column=1) e2.grid(row=1, column=1) e3.grid(row=2, column=1) e4.grid(row=3, column=1) e5.grid(row=4, column=1) e6.grid(row=5, column=1) Button(master, text='Ok', command=valider).grid(row=2, column=2, sticky=W, pady=4) Button(master, text='Delete', command=delete).grid(row=3, column=2, sticky=W, pady=4) mainloop( ) # Main window Mafenetre = Tk() Mafenetre.title("Image") # Création d'un widget Menu menubar = Menu(Mafenetre) menufichier = Menu(menubar,tearoff=0) menufichier.add_command(label="Open mask",command=Ouvrir) menufichier.add_command(label="Save mask",command=save) #menufichier.add_command(label="Convert pdf",command=convert) menufichier.add_command(label="Close mask",command=Fermer) menufichier.add_command(label="Quit",command=Mafenetre.destroy) menubar.add_cascade(label="File", menu=menufichier) menuwrite = Menu(menubar,tearoff=0) menuwrite.add_command(label="Insert informations",command=Write)
Re: Postscript to pdf
well one more question :/ i tried this def save(): Canevas.update() Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) i got the ps file but i didn't get the pdf file :/ 2015-09-20 21:52 GMT+02:00 Laura Creighton: > In a message of Sun, 20 Sep 2015 21:32:34 +0200, Baladjy KICHENASSAMY writes: >>o ok i got it >>actually it's very easy the commande is : >>ps2pdf -dEPSCrop image.ps >> >>sorry but i'm new to python my last question is how to integrate this >>to python... i want that the output file must be a pdf ? >> >>1) i created a button which i'll save my id card as "ps" file >> >>def save(): >>Canevas.update() >>Canevas.postscript(file=tkFileDialog.asksaveasfilename(), >> colormode='color') > >>2) so now i want to create a button to convert this "ps" file into "pdf" >> >>def convert(): >> help :/ > > You need to run the subprocess module to run your command. > https://docs.python.org/2/library/subprocess.html (for python 2) > https://docs.python.org/3.4/library/subprocess.html (for python 3) > > is this enough or do you need more help getting it to work? > > Laura > -- KICHENASSAMY Baladjy Ingénieur en Génie Mécanique Spécialiste Contrôle Non Destructif et Qualification des procédés spéciaux COSAC CND Niveau 2 RT et PT Aircelle SAFRAN Tel:06.03.72.53.12 -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
On Sun, 20 Sep 2015 23:11:20 +0200, Baladjy KICHENASSAMY wrote: > i tried this > > def save(): > Canevas.update() > Canevas.postscript(file=tkFileDialog.asksaveasfilename(), > colormode='color') > subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) > > > i got the ps file but i didn't get the pdf file :/ Check that subprocess.call() returns zero, or use subprocess.check_output() instead. Also, if this is a GUI program and you have no easy way to check what is written to stdout or stderr, try: p = subprocess.Popen(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"], stderr=subprocess.PIPE) out, err = p.communicate() if p.returncode != 0: raise RuntimeError(err) -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
Am 20.09.15 um 20:27 schrieb Baladjy KICHENASSAMY: Hello, I'm using macosx, ps2pdf version i don't know :/ sorry ok actually i found what is the problem... There is no problem with the ps file every thing is fine =) You could try ps2pdf -dEPSCrop input.ps output.pdf that should create a PDF with the papersize derived from an EPS image. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
In a message of Sun, 20 Sep 2015 09:50:02 -0700, Bala Ji writes: >Thank u laura, >I tired it but the problem when i use it there is only half of the image >its like the software cut the image >-- >https://mail.python.org/mailman/listinfo/python-list Ok. We need more information. What OS are you using? What version of ps2pdf did you use, and where did you get it? The next thing we need to find out is whether your ps file contained all the infomation, or whether you lost data before you tried to convert it to a pdf. Do you know? Have you seen your ps file and are sure it is ok? We will get this to work. Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
In a message of Sun, 20 Sep 2015 21:32:34 +0200, Baladjy KICHENASSAMY writes: >o ok i got it >actually it's very easy the commande is : >ps2pdf -dEPSCrop image.ps > >sorry but i'm new to python my last question is how to integrate this >to python... i want that the output file must be a pdf ? > >1) i created a button which i'll save my id card as "ps" file > >def save(): >Canevas.update() >Canevas.postscript(file=tkFileDialog.asksaveasfilename(), > colormode='color') >2) so now i want to create a button to convert this "ps" file into "pdf" > >def convert(): > help :/ You need to run the subprocess module to run your command. https://docs.python.org/2/library/subprocess.html (for python 2) https://docs.python.org/3.4/library/subprocess.html (for python 3) is this enough or do you need more help getting it to work? Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
In a message of Sun, 20 Sep 2015 23:11:20 +0200, Baladjy KICHENASSAMY writes: >well one more question :/ > >i tried this > >def save(): > Canevas.update() > Canevas.postscript(file=tkFileDialog.asksaveasfilename(), >colormode='color') > subprocess.call(["ps2pdf", "-dEPSCrop", "test.ps", "test.pdf"]) > > >i got the ps file but i didn't get the pdf file :/ It's 00:41 here in Sweden, and I have an 08:00 meeting. I am off to bed. Perhaps somebody else can help now, otherwise I will be back tomorrow. I've never tried to get subprocess to run as part of a savefile dialog. Try building a tkinter app that takes a filename argument (somepostscript file you have lying around) and then push the button, in the same dir makes a pdf of your ps using subprocess. If that works, then see about getting save to run that subprocess as part of the save process. I am very curious about whether that can be done -- but first check that your subprocess is working, period. The wretched thing is slightly different between windows and linux, and even between different linuxes, so needing to fiddle a bit here is normal (and frustrating). So right now I cannot tell if your problem is 'save doesn't like it like that' or 'your subprocess isn't working'. But nothing in Tkinter likes 'Canevas' -- (which is great French but rotten English) you must have written Canvas in your code. Paste the real thing in next time, ok? Sorry I am off now, Laura -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
In a message of Sun, 20 Sep 2015 09:20:10 -0700, Bala Ji writes: >Hello, > >I'm doing a software to make an id card for a school club so i used TKINTER to >make this software. >So i can enter details like name, student number etc.. > >So finally i got a Postscript file the problem is that i want to make a pdf >file do you have any ideas? "convert ps to pdf" > >Thank u >regards There is a free program that does this called ps2pdf which is available for linux, windows and mac os. Laura -- https://mail.python.org/mailman/listinfo/python-list
Postscript to pdf
Hello, I'm doing a software to make an id card for a school club so i used TKINTER to make this software. So i can enter details like name, student number etc.. So finally i got a Postscript file the problem is that i want to make a pdf file do you have any ideas? "convert ps to pdf" Thank u regards -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
On 9/20/2015 12:20 PM, Bala Ji wrote: Hello, I'm doing a software to make an id card for a school club so i used TKINTER to make this software. So i can enter details like name, student number etc.. So finally i got a Postscript file the problem is that i want to make a pdf file do you have any ideas? "convert ps to pdf" Where does the .ps file come from? tkinter canvas to .ps? If so, I suggest not to do that. Get reportlab or another python pdf generator (search pypi.python.org for 'pdf' or web for 'python generate pdf'.) -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
o ok i got it actually it's very easy the commande is : ps2pdf -dEPSCrop image.ps sorry but i'm new to python my last question is how to integrate this to python... i want that the output file must be a pdf ? 1) i created a button which i'll save my id card as "ps" file def save(): Canevas.update() Canevas.postscript(file=tkFileDialog.asksaveasfilename(), colormode='color') 2) so now i want to create a button to convert this "ps" file into "pdf" def convert(): help :/ Regards 2015-09-20 21:09 GMT+02:00 Laura Creighton: > In a message of Sun, 20 Sep 2015 20:27:48 +0200, Baladjy KICHENASSAMY writes: >>Hello, >> >>I'm using macosx, ps2pdf version i don't know :/ sorry >>ok actually i found what is the problem... >> >>There is no problem with the ps file every thing is fine =) >> >>Can u please just tell me how to change paper settings ? >>i want to go from portait to landscape ? >> > > Aha! Great to know. > Do you have a real printer there, in which case is this a printer problem? > If so, I need the name of the printer and its model number to help look up > the way to make it do landscape. > > If you just want to have ps2pdf produce landscape files, that is > surprisingly difficult, for the ps2pdf that uses ghostscript to > get the work done. ps2pdf 'guesses' what is the correct orientation > and, stupidly, there is no way to tell it 'stop guessing, I know > what I want'. It's very bad at guessing things that don't have > text -- or enough text -- in them. > > Most of the time ps2pdf is just this: > > gs \ > -o output.pdf \ > -sDEVICE=pdfwrite \ > -dPDFSETTINGS=/prepress \ > -dHaveTrueTypes=true \ > -dEmbedAllFonts=true \ > -dSubsetFonts=false \ > -c ".setpdfwrite <> setdistillerparams" \ > -f input.ps > > where input.ps is the file you have and output.pdf is the pdf you want. > and we can make gs orient itself as you want with > > -c "<> setpagedevice" > > Orientation 3 is landscape. Orientation 0 is portrait. > > If this is your problem, then see if you have gs (ghostscript) > and in that case see if this horrible long command works. > > Laura > -- KICHENASSAMY Baladjy Ingénieur en Génie Mécanique Spécialiste Contrôle Non Destructif et Qualification des procédés spéciaux COSAC CND Niveau 2 RT et PT Aircelle SAFRAN Tel:06.03.72.53.12 -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
Hello, I'm using macosx, ps2pdf version i don't know :/ sorry ok actually i found what is the problem... There is no problem with the ps file every thing is fine =) Can u please just tell me how to change paper settings ? i want to go from portait to landscape ? 2015-09-20 20:12 GMT+02:00 Laura Creighton: > In a message of Sun, 20 Sep 2015 09:50:02 -0700, Bala Ji writes: >>Thank u laura, >>I tired it but the problem when i use it there is only half of the image >>its like the software cut the image >>-- >>https://mail.python.org/mailman/listinfo/python-list > > Ok. We need more information. > What OS are you using? > What version of ps2pdf did you use, and where did you get it? > > The next thing we need to find out is whether your ps file contained > all the infomation, or whether you lost data before you tried to > convert it to a pdf. Do you know? Have you seen your ps file > and are sure it is ok? > > We will get this to work. > > Laura -- KICHENASSAMY Baladjy Ingénieur en Génie Mécanique Spécialiste Contrôle Non Destructif et Qualification des procédés spéciaux COSAC CND Niveau 2 RT et PT Aircelle SAFRAN Tel:06.03.72.53.12 -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
Thank u laura, I tired it but the problem when i use it there is only half of the image its like the software cut the image -- https://mail.python.org/mailman/listinfo/python-list
Re: Postscript to pdf
In a message of Sun, 20 Sep 2015 20:27:48 +0200, Baladjy KICHENASSAMY writes: >Hello, > >I'm using macosx, ps2pdf version i don't know :/ sorry >ok actually i found what is the problem... > >There is no problem with the ps file every thing is fine =) > >Can u please just tell me how to change paper settings ? >i want to go from portait to landscape ? > Aha! Great to know. Do you have a real printer there, in which case is this a printer problem? If so, I need the name of the printer and its model number to help look up the way to make it do landscape. If you just want to have ps2pdf produce landscape files, that is surprisingly difficult, for the ps2pdf that uses ghostscript to get the work done. ps2pdf 'guesses' what is the correct orientation and, stupidly, there is no way to tell it 'stop guessing, I know what I want'. It's very bad at guessing things that don't have text -- or enough text -- in them. Most of the time ps2pdf is just this: gs \ -o output.pdf \ -sDEVICE=pdfwrite \ -dPDFSETTINGS=/prepress \ -dHaveTrueTypes=true \ -dEmbedAllFonts=true \ -dSubsetFonts=false \ -c ".setpdfwrite <> setdistillerparams" \ -f input.ps where input.ps is the file you have and output.pdf is the pdf you want. and we can make gs orient itself as you want with -c "<> setpagedevice" Orientation 3 is landscape. Orientation 0 is portrait. If this is your problem, then see if you have gs (ghostscript) and in that case see if this horrible long command works. Laura -- https://mail.python.org/mailman/listinfo/python-list