Re: [OT] Pre-selecting a printer?

2009-10-29 Thread Jean-Francois Veillette
I am able to share some code, here is the component that does the  
'print panel' of the app.
The code may not be functionnal, it was changed on the fly right here  
while composing this mail (translation from french, simplified and  
removed some class dependencies).
It is a good start that could be integrated in a generic framework  
(wonder or else).
This class was written as a test, a proof of concept.  It worked and  
we never really got back to it to make it 'generic' and 'clean',  so  
there are lots of space for improvement.


Ramsey, you can see in that code how you can access the printer  
capabilities as reported by cups (here it does the minimum).  You  
could check more printer attributes and have your own algoritm to  
choose the best printer from your print job.


enjoy ;-)

- jfv


package a.b.c.webobjects;

import com.webobjects.appserver.*;
import com.webobjects.foundation.*;
import java.util.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;

import javax.print.CancelablePrintJob;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.SimpleDoc;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.Media;
import javax.print.attribute.standard.MediaTray;
import javax.print.attribute.standard.RequestingUserName;
import javax.print.attribute.standard.Sides;

import de.lohndirekt.print.IppPrintServiceLookup;
import de.lohndirekt.print.attribute.auth.RequestingUserPassword;

public class PrintPanel extends WOComponent {

public final static String PRINTER_COOKIE = selectedPrinter;

/* @TypeInfo PrintService */
protected NSArray printerList;
public PrintService printerItem;
public PrintService selectedPrinter;
protected NSArray listPaperTray;
public MediaTray paperTrayItem;
public MediaTray selectedPaperTray;
public int copyNumber;

public PrintPanel(WOContext context) {
super(context);
copyNumber = 1;
// setting cups properties
String uri = System.getProperty(PrintPanel_CUPS_URI);
String usr = System.getProperty(PrintPanel_CUPS_USERNAME);
String pwd = System.getProperty(PrintPanel_CUPS_PASSWORD);
		System.getProperties().setProperty(IppPrintServiceLookup.URI_KEY,   
uri /* http://127.0.0.1:631; */);
		 
System.getProperties().setProperty(IppPrintServiceLookup.USERNAME_KEY,  
usr /* root */);
		 
System.getProperties().setProperty(IppPrintServiceLookup.PASSWORD_KEY,  
pwd /* test */);

}

/**
	 * Take the 'appendToResponse' phase to deal with cookies, before  
showing up the print panel.

 */
public void appendToResponse(WOResponse reponse, WOContext contexte) {
checkCookies();
super.appendToResponse(reponse, contexte);
}

/** Cookie management, enhance user experience */
void checkCookies() {
if(selectedPrinter == null) {
String nom = 
context().request().cookieValueForKey(PRINTER_COOKIE);
NSArray liste = printerList();
if(nom != null) {
java.util.Enumeration en = 
liste.objectEnumerator();
while (en.hasMoreElements()) {
PrintService printer = 
(PrintService)en.nextElement();
if(nom.equals(printer.getName())) {
selectedPrinter = printer;
}
}
} else {
selectedPrinter = 
(PrintService)liste.objectAtIndex(0);
}
}
		WOCookie cookie = new WOCookie(PRINTER_COOKIE,  
selectedPrinter.getName(), /, null, -1, false);

context().response().addCookie(cookie);
}

	/** Commande la génération des fichiers pdf et le retour de ceux-ci  
dans la réponse au serveur web. */

public WOComponent preview() {
NSData pdf = pdf();
FileDownloader tf = 
(FileDownloader)pageWithName(FileDownloader);
tf.setTypeMime(FileDownloader.TYPE_PDF);
tf.setData(pdf);
tf.setFileName(aFileName.pdf);
return tf;
}

public NSArray printerList() {
if(printerList == null) {
			printerList = new NSArray(new  
IppPrintServiceLookup().getPrintServices(DocFlavor.INPUT_STREAM.PDF,  
null));


Re: [OT] Pre-selecting a printer?

2009-10-27 Thread Johan Henselmans

On 26 okt 2009, at 02:09, Pascal Robert wrote:

 We have an app that use CUPS to print labels. The framework use JIPSI :
 
 http://www.lohndirekt.de/software/jipsi_quickstart_drucksoftware.html
 
 Disclaimer : I didn't setup the CUPS server and didn't work on the app, I 
 just know that we have an app that use it :-) You should look at the IPP 
 stuff in LEWOStuff from Andrew.
 
 No, that would be crazy, even for me (^_^)
 
 I was just wondering if it were possible to set up a client Mac to  
 print automatically to a specific printer based on characteristics of 
 
 the print job.  So, let's say I have a color inkjet printer, a black 
 
 and white laser printer, and a star receipt printer.  If I print out a
 
 picture, I want the picture to go to the color printer.  If I'm  
 printing a black and white, text only document, then I want that to go
 
 to the laser, and if I have a print job that is 7cm wide, it should go
 
 to the receipt printer.  Automatically... or at the very least, pre- 
 selected in the print dialog so that all I have to do is hit the enter
 
 key to print.  It seems the only options I really have is to select a 
 
 specific printer, or default to the last printer used. I'm wondering 

You could do it via the command Line: 

see: http://www.cups.org/documentation.php/options.html


The actual options supported are defined in the printer's PPD file in the 
PageSize, InputSlot, and MediaType options. You can list them using 
thelpoptions(1) command:

lpoptions -p printer -l


so:
lpstat -a | awk  '{print echo; echo $1; echo; lpoptions -p $1 -l}'| sh

would give you a rude way to find out which printer support which options. 

Here is some of the output I messed with to find out the supported pageSizes.

sh-3.2# lpstat -a | awk  '{print echo Printer $1; lpoptions -p $1 -l}'| 
sh | grep -E Printer|PageSize 
Printer BOCA_SYSTEMS_44_200
PageSize/Media Size: w144h144 w144h234 w144h288 w153h234 w153h288 w162h234 
w162h288 w180h144 w180h234 w180h288 w198h144 w216h144 w216h234 w216h288 
w243h153 w252h144 w288h144 w288h180 w288h234 w288h288 w306h153 w324h144 
w360h144 w360h153 w360h180 w360h234 w360h288 w396h144 w396h153 w396h180 
w396h198 w396h234 w396h288 w405h144 w432h144 w432h153 w432h180 w432h198 
w432h234 w432h288 w441h184 w459h96 w468h144 w468h234 w468h288 w504h144 w504h234 
w504h288 w531h234 w531h288 w576h72 w576h96 w576h144 *w576h234 w576h288 w648h234 
w648h288 w720h234 w720h288 w792h72 w792h96 w792h234 w792h288 w864h234 w864h288 
w936h234 w1152h72 w1152h96 w1152h144 w1152h153 w1152h180 w1152h184 w1152h198 
w1152h234 w1152h288 Letter Legal A4 Custom
Printer Canon_iP3000___Soundmini
PageSize/Media Size: iso-a5 iso-a4 jis-b5 *na-letter na-legal 
na-number-10-envelope iso-designated-long-envelope DMSIZE_4X6 DMSIZE_5X7 
DMSIZE_DISCTRAY3 DMSIZE_CREDITCARD DMSIZE_MINUS_A4 DMSIZE_MINUS_LETTER 
DMSIZE_MINUS_4X6 DMSIZE_MINUS_5X7 DMSIZE_MINUS_CREDITCARD Custom
Printer DYMO_LabelWriter_320
PageSize/Media Size: *30256_Shipping 30252_Address 30253_Address_(2_up) 
30258_Diskette 30277_File_Folder_(2_up) 30299_Jewelry_Label_(2_up) 
30320_Address 30321_Large_Address 30323_Shipping 30324_Diskette 
30325_Video_Spine 30326_Video_Top 30327_File_Folder 30330_Return_Address 
30332_1_in_x_1_in 30333_1_2_in_x_1_in_(2_up) 30334_2-1_4_in_x_1-1_4_in 
30335_1_2_in_x_1_2_in_(4_up) 30336_1_in_x_2-1_8_in 30337_Audio_Cassette 
30339_8mm_Video_(2_up) 30345_3_4_in_x_2-1_2_in 30346_1_2_in_x_1-7_8_in 
30347_1_in_x_1-1_2_in 30348_9_10_in_x_1-1_4_in 30364_Name_Badge_Label 
30365_Name_Badge_Card 30370_Zip_Disk 30373_Price_Tag_Label 
30374_Appointment_Card 30376_Hanging_File_Insert 30383_PC_Postage_3-Part 
30384_PC_Postage_2-Part 30387_PC_Postage_EPS 99010_Standard_Address 
99012_Large_Address 99014_Name_Badge_Label 99014_Shipping 99015_Diskette 
99016_Video_Spine 99016_Video_Top 99017_Suspension_File 99018_Small_Lever_Arch 
99019_Large_Lever_Arch 11351_Jewelry_Label 11352_Return_Address_Int 
11353_Multi-Purpose 11354_Multi-Purpose 11355_Multi-Purpose 
11356_White_Name_Badge 30854_CD_Label 30886_CD_Label Continuous_Narrow 
Continuous_Wide
Printer Phaser_8550DP__00_00_aa_a1_21_60_
PageSize/Media Size: *Letter Legal Executive IndexCard Statement 
FanFoldGermanLegal Env6x9 Env10 EnvMonarch EnvA7 Env5Half EnvPersonal A4 A5 A6 
ISOB5 B5 EnvDL EnvC5 EnvChou3 EnvChou4 Custom



have fun!

 
 if it is possible to select the most appropriate printer based on  
 characteristics of the print job.
 
 CUPS looked pretty neat.  I imagined there might be some hidden  
 configuration magic in it, so I thought I would ask the list to see if
 
 anyone know of any. (^_^)
 
 Ramsey
 
 On Oct 25, 2009, at 6:39 PM, Andrew Lindesay wrote:
 
 Hi Ramsey;
 
 Do you mean that you would like to change the default printer on a 
 
 users' machine from a web page?
 
 cheers.
 
 Are you able to just print directly to the printer from the  
 application server?
 
 ...
 Is it possible, if I have control of the client machines, to  
 select a printer based on 

Re: [OT] Pre-selecting a printer?

2009-10-25 Thread Andrew Lindesay

Hi Ramsey;

Are you able to just print directly to the printer from the  
application server?


cheers.

Is it possible, if I have control of the client machines, to select  
a printer based on the printed page size?  Also, is it possible to  
bypass the print dialog?  I tried searching the Apple printing list  
but didn't come up with a lot of answers...


___
Andrew Lindesay
www.lindesay.co.nz

___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: [OT] Pre-selecting a printer?

2009-10-25 Thread Ramsey Lee Gurley


On Oct 25, 2009, at 4:26 PM, Andrew Lindesay wrote:


Hi Ramsey;

Are you able to just print directly to the printer from the  
application server?


cheers.

Is it possible, if I have control of the client machines, to select  
a printer based on the printed page size?  Also, is it possible to  
bypass the print dialog?  I tried searching the Apple printing list  
but didn't come up with a lot of answers...


___
Andrew Lindesay
www.lindesay.co.nz



I was thinking of something like a star printer hooked to a client  
machine.  Is there anything in OS X that would let me configure the OS  
to automatically send jobs to the right place?  I found


http://localhost:631/

and it it started me thinking about it.  Looks pretty cool.

Just wondering... (^_^)

Ramsey




smime.p7s
Description: S/MIME cryptographic signature
 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: [OT] Pre-selecting a printer?

2009-10-25 Thread Andrew Lindesay

Hi Ramsey;

Do you mean that you would like to change the default printer on a  
users' machine from a web page?


cheers.

Are you able to just print directly to the printer from the  
application server?



...
Is it possible, if I have control of the client machines, to  
select a printer based on the printed page size?  Also, is it  
possible to bypass the print dialog?  I tried searching the Apple  
printing list but didn't come up with a lot of answers...

...
I was thinking of something like a star printer hooked to a client  
machine.  Is there anything in OS X that would let me configure the  
OS to automatically send jobs to the right place?  I found


___
Andrew Lindesay
www.lindesay.co.nz

___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: [OT] Pre-selecting a printer?

2009-10-25 Thread David Avendasora


On Oct 25, 2009, at 11:44 AM, Ramsey Lee Gurley wrote:

Is it possible, if I have control of the client machines, to select  
a printer based on the printed page size?  Also, is it possible to  
bypass the print dialog?  I tried searching the Apple printing list  
but didn't come up with a lot of answers...


Hi Ramsey!

Um Java Client!

It's the answer to everything, don't cha know. :-)

Dave





Ramsey

___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/webobjects%40avendasora.com

This email sent to webobje...@avendasora.com


___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: [OT] Pre-selecting a printer?

2009-10-25 Thread Ramsey Lee Gurley

No, that would be crazy, even for me (^_^)

I was just wondering if it were possible to set up a client Mac to  
print automatically to a specific printer based on characteristics of  
the print job.  So, let's say I have a color inkjet printer, a black  
and white laser printer, and a star receipt printer.  If I print out a  
picture, I want the picture to go to the color printer.  If I'm  
printing a black and white, text only document, then I want that to go  
to the laser, and if I have a print job that is 7cm wide, it should go  
to the receipt printer.  Automatically... or at the very least, pre- 
selected in the print dialog so that all I have to do is hit the enter  
key to print.  It seems the only options I really have is to select a  
specific printer, or default to the last printer used. I'm wondering  
if it is possible to select the most appropriate printer based on  
characteristics of the print job.


CUPS looked pretty neat.  I imagined there might be some hidden  
configuration magic in it, so I thought I would ask the list to see if  
anyone know of any. (^_^)


Ramsey

On Oct 25, 2009, at 6:39 PM, Andrew Lindesay wrote:


Hi Ramsey;

Do you mean that you would like to change the default printer on a  
users' machine from a web page?


cheers.

Are you able to just print directly to the printer from the  
application server?



...
Is it possible, if I have control of the client machines, to  
select a printer based on the printed page size?  Also, is it  
possible to bypass the print dialog?  I tried searching the Apple  
printing list but didn't come up with a lot of answers...

...
I was thinking of something like a star printer hooked to a client  
machine.  Is there anything in OS X that would let me configure the  
OS to automatically send jobs to the right place?  I found


___
Andrew Lindesay
www.lindesay.co.nz





smime.p7s
Description: S/MIME cryptographic signature
 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: [OT] Pre-selecting a printer?

2009-10-25 Thread Pascal Robert
We have an app that use CUPS to print labels. The framework use JIPSI :

http://www.lohndirekt.de/software/jipsi_quickstart_drucksoftware.html

Disclaimer : I didn't setup the CUPS server and didn't work on the app, I just 
know that we have an app that use it :-) You should look at the IPP stuff in 
LEWOStuff from Andrew.

 No, that would be crazy, even for me (^_^)
 
 I was just wondering if it were possible to set up a client Mac to  
 print automatically to a specific printer based on characteristics of 
 
 the print job.  So, let's say I have a color inkjet printer, a black 
 
 and white laser printer, and a star receipt printer.  If I print out a
  
 picture, I want the picture to go to the color printer.  If I'm  
 printing a black and white, text only document, then I want that to go
  
 to the laser, and if I have a print job that is 7cm wide, it should go
  
 to the receipt printer.  Automatically... or at the very least, pre- 
 selected in the print dialog so that all I have to do is hit the enter
  
 key to print.  It seems the only options I really have is to select a 
 
 specific printer, or default to the last printer used. I'm wondering 
 
 if it is possible to select the most appropriate printer based on  
 characteristics of the print job.
 
 CUPS looked pretty neat.  I imagined there might be some hidden  
 configuration magic in it, so I thought I would ask the list to see if
  
 anyone know of any. (^_^)
 
 Ramsey
 
 On Oct 25, 2009, at 6:39 PM, Andrew Lindesay wrote:
 
  Hi Ramsey;
 
  Do you mean that you would like to change the default printer on a 
 
  users' machine from a web page?
 
  cheers.
 
  Are you able to just print directly to the printer from the  
  application server?
 
  ...
  Is it possible, if I have control of the client machines, to  
  select a printer based on the printed page size?  Also, is it  
  possible to bypass the print dialog?  I tried searching the Apple
  
  printing list but didn't come up with a lot of answers...
  ...
  I was thinking of something like a star printer hooked to a client 
 
  machine.  Is there anything in OS X that would let me configure the
  
  OS to automatically send jobs to the right place?  I found
 
  ___
  Andrew Lindesay
  www.lindesay.co.nz
 
 
 
  ___
 Do not post admin requests to the list. They will be ignored.
 Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
 Help/Unsubscribe/Update your Subscription:
 http://lists.apple.com/mailman/options/webobjects-dev/probert%40macti.ca
 
 This email sent to prob...@macti.ca

-- 

--- 
Pascal Robert 

http://www.macti.ca 
http://www.linkedin.com/in/macti 

Skype: MacTICanada 
AIM/iChat : MacTICanada 
 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com