[JAVA2D] DocPrintJob doesn' work with Zebra printer

2008-06-26 Thread java2d
Hi, here's my problem.
My aim is printing a PDF file by DocPrintJob, instead of PrintJob and Printable 
class. Here's a code fragment:

[..]
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
HashPrintServiceAttributeSet serviceAttributeSet = new 
HashPrintServiceAttributeSet();
PrintService[] printServices = 
PrintServiceLookup.lookupPrintServices(flavor, serviceAttributeSet);
for (int i = 0; i  printServices.length; i++) {
String printerName = printServices[i].getName();
if(MYPRINTER.equals(printerName)) { 
//found!!
PrintService printService = printServices[i];
DocPrintJob docPrintJob = 
printService.createPrintJob();
docPrintJob.addPrintJobListener(new 
PrintJobAdapter() {

public void 
printDataTransferCompleted(PrintJobEvent e) {
System.out.println(Document 
sent to printer.);
}
public void 
printJobCompleted(PrintJobEvent e) {
System.out.println(Document 
was successfully printed.);
}
public void 
printJobCancelled(PrintJobEvent e) {
System.out.println(Document 
printing was cancelled.);
}
public void 
printJobFailed(PrintJobEvent e){
System.out.println(Document 
failed to print.);
}
public void 
printJobNoMoreEvents(PrintJobEvent e) {
System.out.println(No more 
print events.);
}
public void 
printJobRequiresAttention(PrintJobEvent e) {
System.out.println(Printer 
requires attention.);
}   
}
);
File f = new File(PDFFILE);
byte[] bytesFromFile = getBytesFromFile(f);
SimpleDoc doc = new SimpleDoc(bytesFromFile, 
flavor, null);
PrintRequestAttributeSet reqAttributeSet = new 
HashPrintRequestAttributeSet();
reqAttributeSet.add(new MediaPrintableArea(0f, 
0f, 1.85f, 1.1f, MediaPrintableArea.INCH));
reqAttributeSet.add(new Copies(1)); 
docPrintJob.print(doc, reqAttributeSet);
[..]

where MYPRINTER is the target printer name (at the moment, ZDesigner LP 2824).
When code is executed, the standard output displays

   Document sent to printer.
   No more print events.

i.e., a [i]printDataTransferCompleted(e)[/i] and a 
[i]printJobNoMoreEvents(e)[/i] is fired to the anonymous PrintJobListener.
But the printer doesn't print (neither a blank page).

Changing the target printer name (i.e., using another printer, an HP Laser 
Jet), all works fine.

Why?

Matteo
[Message sent by forum member 'matteoforesti' (matteoforesti)]

http://forums.java.net/jive/thread.jspa?messageID=282755

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.


Re: [JAVA2D] DocPrintJob doesn' work with Zebra printer

2008-06-26 Thread Phil Race
Sending the raw bytes of a PDF file to a printer will work only if the 
printer itself can interpret PDF.

I'd be surprised if this ZDesigner LP 2824 is capable of this.

https://www.cdw.com/shop/products/default.aspx?EDC=1444344

-phil.


[EMAIL PROTECTED] wrote:

Hi, here's my problem.
My aim is printing a PDF file by DocPrintJob, instead of PrintJob and Printable 
class. Here's a code fragment:

[..]
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
HashPrintServiceAttributeSet serviceAttributeSet = new 
HashPrintServiceAttributeSet();
PrintService[] printServices = 
PrintServiceLookup.lookupPrintServices(flavor, serviceAttributeSet);
for (int i = 0; i  printServices.length; i++) {
String printerName = printServices[i].getName();
if(MYPRINTER.equals(printerName)) { 
//found!!
PrintService printService = printServices[i];
DocPrintJob docPrintJob = 
printService.createPrintJob();
docPrintJob.addPrintJobListener(new 
PrintJobAdapter() {

public void 
printDataTransferCompleted(PrintJobEvent e) {
System.out.println(Document sent to 
printer.);
}
public void 
printJobCompleted(PrintJobEvent e) {
System.out.println(Document was 
successfully printed.);
}
public void 
printJobCancelled(PrintJobEvent e) {
System.out.println(Document 
printing was cancelled.);
}
public void 
printJobFailed(PrintJobEvent e){
System.out.println(Document failed 
to print.);
}
public void 
printJobNoMoreEvents(PrintJobEvent e) {
System.out.println(No more print 
events.);
}
public void 
printJobRequiresAttention(PrintJobEvent e) {
System.out.println(Printer requires 
attention.);
}   
}
);
File f = new File(PDFFILE);
byte[] bytesFromFile = getBytesFromFile(f);
SimpleDoc doc = new SimpleDoc(bytesFromFile, 
flavor, null);
PrintRequestAttributeSet reqAttributeSet = new 
HashPrintRequestAttributeSet();
reqAttributeSet.add(new MediaPrintableArea(0f, 
0f, 1.85f, 1.1f, MediaPrintableArea.INCH));
reqAttributeSet.add(new Copies(1)); 
docPrintJob.print(doc, reqAttributeSet);
[..]

where MYPRINTER is the target printer name (at the moment, ZDesigner LP 2824).
When code is executed, the standard output displays

   Document sent to printer.
   No more print events.

i.e., a [i]printDataTransferCompleted(e)[/i] and a 
[i]printJobNoMoreEvents(e)[/i] is fired to the anonymous PrintJobListener.
But the printer doesn't print (neither a blank page).

Changing the target printer name (i.e., using another printer, an HP Laser 
Jet), all works fine.

Why?

Matteo
[Message sent by forum member 'matteoforesti' (matteoforesti)]

http://forums.java.net/jive/thread.jspa?messageID=282755

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.
  


===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message signoff JAVA2D-INTEREST.  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message help.