Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96884 > unrolled thread

Postscript to pdf

Started byBala Ji <baladjy@gmail.com>
First post2015-09-20 09:20 -0700
Last post2015-09-21 00:17 -0400
Articles 17 — 8 participants

Back to article view | Back to comp.lang.python


Contents

  Postscript to pdf Bala Ji <baladjy@gmail.com> - 2015-09-20 09:20 -0700
    Re: Postscript to pdf Laura Creighton <lac@openend.se> - 2015-09-20 18:40 +0200
      Re: Postscript to pdf Bala Ji <baladjy@gmail.com> - 2015-09-20 09:50 -0700
        Re: Postscript to pdf Laura Creighton <lac@openend.se> - 2015-09-20 20:12 +0200
        Re: Postscript to pdf Laura Creighton <lac@openend.se> - 2015-09-20 21:09 +0200
        Re: Postscript to pdf Baladjy KICHENASSAMY <baladjy@gmail.com> - 2015-09-20 20:27 +0200
          Re: Postscript to pdf Christian Gollwitzer <auriocus@gmx.de> - 2015-09-21 15:39 +0200
        Re: Postscript to pdf Baladjy KICHENASSAMY <baladjy@gmail.com> - 2015-09-20 21:32 +0200
        Re: Postscript to pdf Laura Creighton <lac@openend.se> - 2015-09-20 21:52 +0200
        Re: Postscript to pdf Laura Creighton <lac@openend.se> - 2015-09-21 00:50 +0200
        Re: Postscript to pdf Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-09-20 20:25 -0400
        Re: Postscript to pdf Baladjy KICHENASSAMY <baladjy@gmail.com> - 2015-09-20 23:11 +0200
          Re: Postscript to pdf Nobody <nobody@nowhere.invalid> - 2015-09-21 13:56 +0100
        Re: Postscript to pdf Baladjy KICHENASSAMY <baladjy@gmail.com> - 2015-09-21 17:20 +0200
          Re: Postscript to pdf Christian Gollwitzer <auriocus@gmx.de> - 2015-09-23 08:40 +0200
          Re: Postscript to pdf mithra <curtis.rendon@gmail.com> - 2015-09-23 17:01 -0700
    Re: Postscript to pdf Terry Reedy <tjreedy@udel.edu> - 2015-09-21 00:17 -0400

#96884 — Postscript to pdf

FromBala Ji <baladjy@gmail.com>
Date2015-09-20 09:20 -0700
SubjectPostscript to pdf
Message-ID<f1c3720b-ee32-4a22-bdfa-7a1bedebc16f@googlegroups.com>
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

[toc] | [next] | [standalone]


#96885

FromLaura Creighton <lac@openend.se>
Date2015-09-20 18:40 +0200
Message-ID<mailman.42.1442767228.21674.python-list@python.org>
In reply to#96884
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 

[toc] | [prev] | [next] | [standalone]


#96887

FromBala Ji <baladjy@gmail.com>
Date2015-09-20 09:50 -0700
Message-ID<ed98eb8c-8316-41bc-97ff-008c2f0c91f3@googlegroups.com>
In reply to#96885
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

[toc] | [prev] | [next] | [standalone]


#96889

FromLaura Creighton <lac@openend.se>
Date2015-09-20 20:12 +0200
Message-ID<mailman.0.1442772765.28679.python-list@python.org>
In reply to#96887
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

[toc] | [prev] | [next] | [standalone]


#96892

FromLaura Creighton <lac@openend.se>
Date2015-09-20 21:09 +0200
Message-ID<mailman.1.1442776152.28679.python-list@python.org>
In reply to#96887
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 <</NeverEmbed [ ]>> 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 "<</Orientation 3>> 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

[toc] | [prev] | [next] | [standalone]


#96895

FromBaladjy KICHENASSAMY <baladjy@gmail.com>
Date2015-09-20 20:27 +0200
Message-ID<mailman.4.1442778639.28679.python-list@python.org>
In reply to#96887
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 <lac@openend.se>:
> 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

[toc] | [prev] | [next] | [standalone]


#96943

FromChristian Gollwitzer <auriocus@gmx.de>
Date2015-09-21 15:39 +0200
Message-ID<mtp16o$nqi$1@dont-email.me>
In reply to#96895
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

[toc] | [prev] | [next] | [standalone]


#96896

FromBaladjy KICHENASSAMY <baladjy@gmail.com>
Date2015-09-20 21:32 +0200
Message-ID<mailman.5.1442778639.28679.python-list@python.org>
In reply to#96887
ohhhh 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 <lac@openend.se>:
> 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 <</NeverEmbed [ ]>> 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 "<</Orientation 3>> 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

[toc] | [prev] | [next] | [standalone]


#96897

FromLaura Creighton <lac@openend.se>
Date2015-09-20 21:52 +0200
Message-ID<mailman.7.1442778771.28679.python-list@python.org>
In reply to#96887
In a message of Sun, 20 Sep 2015 21:32:34 +0200, Baladjy KICHENASSAMY writes:
>ohhhh 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

[toc] | [prev] | [next] | [standalone]


#96902

FromLaura Creighton <lac@openend.se>
Date2015-09-21 00:50 +0200
Message-ID<mailman.11.1442789426.28679.python-list@python.org>
In reply to#96887
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

[toc] | [prev] | [next] | [standalone]


#96904

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2015-09-20 20:25 -0400
Message-ID<mailman.13.1442795119.28679.python-list@python.org>
In reply to#96887
On Sun, 20 Sep 2015 21:52:43 +0200, Laura Creighton <lac@openend.se>
declaimed the following:

>In a message of Sun, 20 Sep 2015 21:32:34 +0200, Baladjy KICHENASSAMY writes:
>>ohhhh 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


	At this point one begins to wonder if, since PDF is the desired end
product, it might not be better to redo the effort targeting the use of
ReportLab rather than the round-about PS to PDF conversion?
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#96919

FromBaladjy KICHENASSAMY <baladjy@gmail.com>
Date2015-09-20 23:11 +0200
Message-ID<mailman.22.1442822127.28679.python-list@python.org>
In reply to#96887
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 <lac@openend.se>:
> In a message of Sun, 20 Sep 2015 21:32:34 +0200, Baladjy KICHENASSAMY writes:
>>ohhhh 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

[toc] | [prev] | [next] | [standalone]


#96939

FromNobody <nobody@nowhere.invalid>
Date2015-09-21 13:56 +0100
Message-ID<pan.2015.09.21.12.56.28.790000@nowhere.invalid>
In reply to#96919
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)

[toc] | [prev] | [next] | [standalone]


#96973

FromBaladjy KICHENASSAMY <baladjy@gmail.com>
Date2015-09-21 17:20 +0200
Message-ID<mailman.55.1442906405.28679.python-list@python.org>
In reply to#96887
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)
menuwrite.add_command(label="Insert image",command=insertimage)
menuwrite.add_command(label="Insert signature",command=insertsign)
menubar.add_cascade(label="Informations", menu=menuwrite)


menuaide = Menu(menubar,tearoff=0)
menuaide.add_command(label="A propos",command=Apropos)
menubar.add_cascade(label="Aide", menu=menuaide)

# Affichage du menu
Mafenetre.config(menu=menubar)

# Création d'un widget Canvas
Canevas = Canvas(Mafenetre)
Canevas.pack(padx=5,pady=5)

# Utilisation d'un dictionnaire pour conserver une référence
gifdict={}

Mafenetre.mainloop()

2015-09-21 0:50 GMT+02:00 Laura Creighton <lac@openend.se>:
> 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



-- 
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

[toc] | [prev] | [next] | [standalone]


#97019

FromChristian Gollwitzer <auriocus@gmx.de>
Date2015-09-23 08:40 +0200
Message-ID<mtthe6$6qb$1@dont-email.me>
In reply to#96973
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

[toc] | [prev] | [next] | [standalone]


#97052

Frommithra <curtis.rendon@gmail.com>
Date2015-09-23 17:01 -0700
Message-ID<681fe58f-92c2-461c-85d8-b700bcc893b9@googlegroups.com>
In reply to#96973
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)
> 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)
> menuwrite.add_command(label="Insert image",command=insertimage)
> menuwrite.add_command(label="Insert signature",command=insertsign)
> menubar.add_cascade(label="Informations", menu=menuwrite)
> 
> 
> menuaide = Menu(menubar,tearoff=0)
> menuaide.add_command(label="A propos",command=Apropos)
> menubar.add_cascade(label="Aide", menu=menuaide)
> 
> # Affichage du menu
> Mafenetre.config(menu=menubar)
> 
> # Création d'un widget Canvas
> Canevas = Canvas(Mafenetre)
> Canevas.pack(padx=5,pady=5)
> 
> # Utilisation d'un dictionnaire pour conserver une référence
> gifdict={}
> 
> Mafenetre.mainloop()
> 
> 2015-09-21 0:50 GMT+02:00 Laura Creighton <lac@openend.se>:
> > 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"])
> >>

Try putting the entire path to ps2pdf in the subprocess call, something like:
/usr/local/bin/ps2pdf

[toc] | [prev] | [next] | [standalone]


#96911

FromTerry Reedy <tjreedy@udel.edu>
Date2015-09-21 00:17 -0400
Message-ID<mailman.19.1442809080.28679.python-list@python.org>
In reply to#96884
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web