Skip to main content

DocPrintJob doesn' work with Zebra printer

3 replies [Last post]
matteoforesti
Offline
Joined: 2005-06-09

_

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.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) and a printJobNoMoreEvents(e) 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?

null

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pjmorce
Offline
Joined: 2008-01-30

Hello

did your resolved this problem?

how?

thanks

regards

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.

java2d@JAVADESKTOP.ORG 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 listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

matteoforesti
Offline
Joined: 2005-06-09

The same behavior occurs using a simple txt file instead of PDF file.

No changes using a DocFlavor.INPUT_STREAM instead of DocFlavor.BYTE_ARRAY.

In all probability, not the whole printers are able to work by DocPrintJob usage.

Matteo