RSS/Atom feed Twitter
Site is read-only, email is disabled

Printing non-interactively using file-print-gtk

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

4 of 4 messages available
Toggle history

Please log in to manage your subscriptions.

Printing non-interactively using file-print-gtk Niklas Koponen 31 Jul 11:15
  Printing non-interactively using file-print-gtk Niklas Koponen 31 Jul 13:58
   Printing non-interactively using file-print-gtk Niklas Koponen 31 Jul 15:15
    Printing non-interactively using file-print-gtk Ed . 31 Jul 15:26
Niklas Koponen
2014-07-31 11:15:09 UTC (over 9 years ago)

Printing non-interactively using file-print-gtk

Hi!

I'm having the following problem. I'm trying to print images non interactively from a photobooth application I have written. It is a quick and not so dirty solution written in python. It captures the images using 'fswebcam' and the original plan was to print the images using 'lpr'. The printer used is a HP Photosmart Premium 309. It is impossible to get images to print right using lpr. I noticed that using 'eog' the images seemed to be printing ok, so I suspected that gtk printing might work. That led me to gimp, because I knew that there was a non-interactive mechanism to run scripts. The printing also works fine from gimp when done interactively from the menu.

Now to the problem with the file-print-gtk procedure. If I run the file-print-gtk procedure like this

(file-print-gtk RUN-INTERACTIVE image)

and press just the OK button, everything prints nicely.

If I run the procedure like this

(file-print-gtk RUN-INTERACTIVE image)

the image is printed on the photo paper presumably 2 times larger, so that only one quarter of the image is printed on the paper.

I'm a bit confused about what settings are used when the print page setup dialog is shown, and what settings are used when the dialog is not shown. That seems to be obvious that they are different settings.

I read from this thread http://www.gimpusers.com/forums/gimp-user/11146-printing-from-a-batch that one might try to change the parameters in files print-settings and print-page-setup which are located in the gimp user directory. The problem is that I have no idea when these files are used, interactively on non-interactively.

There was also a mentioning about file-print-gtk-page-setup procedure. What does this do?

Any help is appreciated. The photobooth application needs to be ready in a week, and the printing part is the only thing missing. I would not be proud of a solution where the user sees a print dialog and has to press OK. I want to be able to do the printing with only one push of a button.

-Niklas

Niklas Koponen
2014-07-31 13:58:34 UTC (over 9 years ago)

Printing non-interactively using file-print-gtk

Oops... The second procedure call should be

(file-print-gtk RUN-NONINTERACTIVE image)

The main reason that I don't want the print dialog to appear is that it shows too many possibilities to mess the system up. As mentioned, it is going to be a photobooth, and there should be only the three buttons visible, which my application provides. They are 'Take photo', 'Print photo', 'Clear photo'.

The whole script looks like this:

(define (script-fu-quick-print inImage) (let* (
(image (car(gimp-file-load RUN-NONINTERACTIVE inImage inImage))) )
(file-print-gtk RUN-INTERACTIVE image) (gimp-image-delete image)
)
)
(script-fu-register
"script-fu-quick-print"
"Quick Print"
"Prints non interactively"
"Nikkez"
"Copyright 2014"
"July 2014"
""
SF-FILENAME "Input file" "./Projects/photobooth/testimage.jpg" )
(script-fu-menu-register "script-fu-quick-print" "/File/Quick print")

On Thu, Jul 31, 2014 at 2:15 PM, Niklas Koponen wrote:

Hi!

I'm having the following problem. I'm trying to print images non interactively from a photobooth application I have written. It is a quick and not so dirty solution written in python. It captures the images using 'fswebcam' and the original plan was to print the images using 'lpr'. The printer used is a HP Photosmart Premium 309. It is impossible to get images to print right using lpr. I noticed that using 'eog' the images seemed to be printing ok, so I suspected that gtk printing might work. That led me to gimp, because I knew that there was a non-interactive mechanism to run scripts. The printing also works fine from gimp when done interactively from the menu.

Now to the problem with the file-print-gtk procedure. If I run the file-print-gtk procedure like this

(file-print-gtk RUN-INTERACTIVE image)

and press just the OK button, everything prints nicely.

If I run the procedure like this

(file-print-gtk RUN-INTERACTIVE image)

the image is printed on the photo paper presumably 2 times larger, so that only one quarter of the image is printed on the paper.

I'm a bit confused about what settings are used when the print page setup dialog is shown, and what settings are used when the dialog is not shown. That seems to be obvious that they are different settings.

I read from this thread http://www.gimpusers.com/forums/gimp-user/11146-printing-from-a-batch that one might try to change the parameters in files print-settings and print-page-setup which are located in the gimp user directory. The problem is that I have no idea when these files are used, interactively on non-interactively.

There was also a mentioning about file-print-gtk-page-setup procedure. What does this do?

Any help is appreciated. The photobooth application needs to be ready in a week, and the printing part is the only thing missing. I would not be proud of a solution where the user sees a print dialog and has to press OK. I want to be able to do the printing with only one push of a button.

-Niklas

Niklas Koponen
2014-07-31 15:15:41 UTC (over 9 years ago)

Printing non-interactively using file-print-gtk

I'm in a real hurry so every working solution seems to be fine with me :-)

I found the test automation tool xdotool which enabled me to send Return keypress to the window. There were problems getting the window id, but this script finally did the trick.

#!/bin/sh

gimp -i -b "(script-fu-quick-print \"$1\")" -b "(gimp-quit 0)" & xdotool search --sync --class print
xdotool search --onlyvisible --name Print | xargs -I {} -n 1 xdotool key --window {} Return

This is quite ugly, but it works, and now I can move forward.

-Niklas

On Thu, Jul 31, 2014 at 4:58 PM, Niklas Koponen wrote:

Oops... The second procedure call should be

(file-print-gtk RUN-NONINTERACTIVE image)

The main reason that I don't want the print dialog to appear is that it shows too many possibilities to mess the system up. As mentioned, it is going to be a photobooth, and there should be only the three buttons visible, which my application provides. They are 'Take photo', 'Print photo', 'Clear photo'.

The whole script looks like this:

(define (script-fu-quick-print inImage) (let* (
(image (car(gimp-file-load RUN-NONINTERACTIVE inImage inImage))) )
(file-print-gtk RUN-INTERACTIVE image) (gimp-image-delete image)
)
)
(script-fu-register
"script-fu-quick-print"
"Quick Print"
"Prints non interactively"
"Nikkez"
"Copyright 2014"
"July 2014"
""
SF-FILENAME "Input file" "./Projects/photobooth/testimage.jpg" )
(script-fu-menu-register "script-fu-quick-print" "/File/Quick print")

On Thu, Jul 31, 2014 at 2:15 PM, Niklas Koponen wrote:

Hi!

I'm having the following problem. I'm trying to print images non interactively from a photobooth application I have written. It is a quick and not so dirty solution written in python. It captures the images using 'fswebcam' and the original plan was to print the images using 'lpr'. The printer used is a HP Photosmart Premium 309. It is impossible to get images to print right using lpr. I noticed that using 'eog' the images seemed to be printing ok, so I suspected that gtk printing might work. That led me to gimp, because I knew that there was a non-interactive mechanism to run scripts. The printing also works fine from gimp when done interactively from the menu.

Now to the problem with the file-print-gtk procedure. If I run the file-print-gtk procedure like this

(file-print-gtk RUN-INTERACTIVE image)

and press just the OK button, everything prints nicely.

If I run the procedure like this

(file-print-gtk RUN-INTERACTIVE image)

the image is printed on the photo paper presumably 2 times larger, so that only one quarter of the image is printed on the paper.

I'm a bit confused about what settings are used when the print page setup dialog is shown, and what settings are used when the dialog is not shown. That seems to be obvious that they are different settings.

I read from this thread http://www.gimpusers.com/forums/gimp-user/11146-printing-from-a-batch that one might try to change the parameters in files print-settings and print-page-setup which are located in the gimp user directory. The problem is that I have no idea when these files are used, interactively on non-interactively.

There was also a mentioning about file-print-gtk-page-setup procedure. What does this do?

Any help is appreciated. The photobooth application needs to be ready in a week, and the printing part is the only thing missing. I would not be proud of a solution where the user sees a print dialog and has to press OK. I want to be able to do the printing with only one push of a button.

-Niklas

Ed .
2014-07-31 15:26:11 UTC (over 9 years ago)

Printing non-interactively using file-print-gtk

Good work! Thanks for letting us know the problem is solved-ish.

-----Original Message----- From: Niklas Koponen
Sent: Thursday, July 31, 2014 4:15 PM To: gimp-developer-list@gnome.org
Subject: Re: [Gimp-developer] Printing non-interactively using file-print-gtk

I'm in a real hurry so every working solution seems to be fine with me :-)

I found the test automation tool xdotool which enabled me to send Return keypress to the window. There were problems getting the window id, but this script finally did the trick.

#!/bin/sh

gimp -i -b "(script-fu-quick-print \"$1\")" -b "(gimp-quit 0)" & xdotool search --sync --class print
xdotool search --onlyvisible --name Print | xargs -I {} -n 1 xdotool key --window {} Return

This is quite ugly, but it works, and now I can move forward.

-Niklas

On Thu, Jul 31, 2014 at 4:58 PM, Niklas Koponen wrote:

Oops... The second procedure call should be

(file-print-gtk RUN-NONINTERACTIVE image)

The main reason that I don't want the print dialog to appear is that it shows too many possibilities to mess the system up. As mentioned, it is going to be a photobooth, and there should be only the three buttons visible, which my application provides. They are 'Take photo', 'Print photo', 'Clear photo'.

The whole script looks like this:

(define (script-fu-quick-print inImage) (let* (
(image (car(gimp-file-load RUN-NONINTERACTIVE inImage inImage))) )
(file-print-gtk RUN-INTERACTIVE image) (gimp-image-delete image)
)
)
(script-fu-register
"script-fu-quick-print"
"Quick Print"
"Prints non interactively"
"Nikkez"
"Copyright 2014"
"July 2014"
""
SF-FILENAME "Input file" "./Projects/photobooth/testimage.jpg" )
(script-fu-menu-register "script-fu-quick-print" "/File/Quick print")

On Thu, Jul 31, 2014 at 2:15 PM, Niklas Koponen wrote:

Hi!

I'm having the following problem. I'm trying to print images non interactively from a photobooth application I have written. It is a quick and not so dirty solution written in python. It captures the images using 'fswebcam' and the original plan was to print the images using 'lpr'. The printer used is a HP Photosmart Premium 309. It is impossible to get images
to print right using lpr. I noticed that using 'eog' the images seemed to be printing ok, so I suspected that gtk printing might work. That led me to
gimp, because I knew that there was a non-interactive mechanism to run scripts. The printing also works fine from gimp when done interactively from the menu.

Now to the problem with the file-print-gtk procedure. If I run the file-print-gtk procedure like this

(file-print-gtk RUN-INTERACTIVE image)

and press just the OK button, everything prints nicely.

If I run the procedure like this

(file-print-gtk RUN-INTERACTIVE image)

the image is printed on the photo paper presumably 2 times larger, so that only one quarter of the image is printed on the paper.

I'm a bit confused about what settings are used when the print page setup dialog is shown, and what settings are used when the dialog is not shown. That seems to be obvious that they are different settings.

I read from this thread http://www.gimpusers.com/forums/gimp-user/11146-printing-from-a-batch that one might try to change the parameters in files print-settings and print-page-setup which are located in the gimp user directory. The problem
is that I have no idea when these files are used, interactively on non-interactively.

There was also a mentioning about file-print-gtk-page-setup procedure. What does this do?

Any help is appreciated. The photobooth application needs to be ready in a week, and the printing part is the only thing missing. I would not be proud of a solution where the user sees a print dialog and has to press OK.
I want to be able to do the printing with only one push of a button.

-Niklas