Printing Error - pstopdffilter/pstocupsraster failed with err number -31000
Hi All,
I'm hoping someone could assist me with this. After googling like crazy for a solution I thought I had to post here on the forums. I'm a new Mac user (only a few days now) so please bear with me. I will also post this on the Java Forums because I don't know if this is a problem with my code or with the Mac settings.
Setup
I've got a Java Applet running on the mac (written in Eclipse 64 bit) on a Mac with OS X 10.6.4 on. Also, Java 1.6.0_21 (both 32 bit and 64 bit) is installed on the machine. The printer installed is a ZPL Label Printer (Zebra Technologies ZTC GK420d).
If I use another application such as TextEdit to print, it works fine.
*Problem Description*
Whenever I try print from the Applet nothing comes from the printer, my code does not break or catch any exception at all but the printer queue gives the error: *pstopdffilter/pstocupsraster failed with err number -31000.*
Code
The code I use with this Java Applet works absolutely fine on Windows XP 32 bit (IE 7.0, Google Chrome and Firefox) as well as on Windows 7 64 bit (I.E 8.0, Google Chrome and Firefox) but never on the Mac. For any developers who might be able to help, the code is below:
import java.applet.Applet;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.PrintServiceAttribute;
import javax.print.attribute.standard.PrinterName;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
public class UKMJavaPrintApplet extends Applet
{
public void init()
{
System.out.println("Initialising UK Mail Java Printing Applet...");
}
public void start()
{
System.out.println("Starting UK Mail Java Printing Applet...");
PrintLabelZPL("^XA^FO100,40^BY3^B3,,30^FD123ABC^XZ","Zebra Technologies ZTC GK420d");
}
public void stop()
{
System.out.println("Stopping UK Mail Java Printing Applet...");
}
public void destroy()
{
System.out.println("Preparing unload of UK Mail Java Printing Applet...");
}
public int GetPrinterCount()
{
PrintService[] services = null;
int serviceLength = 0;
try
{
services = PrintServiceLookup.lookupPrintServices(null, null);
if(services != null && services.length > 0)
{
serviceLength = services.length;
}
}
catch(Exception z)
{
System.out.println("Failed to get printer count: " + z.getMessage());
z.printStackTrace();
}
return serviceLength;
}
public String GetPrinterName(int index)
{
String sPrinterName = null;
String printerName = "";
PrintService[] services = null;
try
{
services = PrintServiceLookup.lookupPrintServices(null, null);
for (int k=0; k < services.length; k++)
{
PrintServiceAttribute attr = services[k].getAttribute(PrinterName.class);
sPrinterName = ((PrinterName) attr).getValue();
if(index == k)
{
printerName = sPrinterName;
break;
}
}
}
catch(Exception r)
{
System.out.println("Failed to get printer name: " + r.getMessage());
r.printStackTrace();
}
return printerName;
}
public Boolean PrintLabelZPL(String zplString, String printerName)
{
String errStr = "";
Boolean boolSuccess = false;
try
{
if(printerName != null && printerName != "")
{
PrintService psZebra = null;
String sPrinterName = null;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (int i = 0; i < services.length; i++)
{
PrintServiceAttribute attr = services .getAttribute(PrinterName.class);
sPrinterName = ((PrinterName) attr).getValue();
if (printerName.equals(sPrinterName))
{
psZebra = services;
break;
}
}
if (psZebra != null)
{
DocPrintJob job = psZebra.createPrintJob();
byte[] by = zplString.getBytes();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(by, flavor, null);
System.out.println("Printing to: " + printerName);
job.print(doc, pras);
boolSuccess = true;
System.out.println("Printing Successful.");
}
else
{
errStr = "Zebra printer not found.";
System.out.println(errStr);
boolSuccess = false;
}
}
else
{
errStr = "No printer name was provided.";
System.out.println(errStr);
boolSuccess = false;
}
}
catch (PrintException e)
{
System.out.println("Print Failed with PrintException: " + e.getMessage());
boolSuccess = false;
e.printStackTrace();
}
catch (Exception f)
{
System.out.println("Print Failed: " + f.getMessage());
boolSuccess = false;
f.printStackTrace();
}
return boolSuccess;
}
}
Does anyone have any ideas on how I can resolve this and print to the ZPL printer from my Java Applet on the Mac?
Any help would be much appreciated.
Thanks!
I'm hoping someone could assist me with this. After googling like crazy for a solution I thought I had to post here on the forums. I'm a new Mac user (only a few days now) so please bear with me. I will also post this on the Java Forums because I don't know if this is a problem with my code or with the Mac settings.
Setup
I've got a Java Applet running on the mac (written in Eclipse 64 bit) on a Mac with OS X 10.6.4 on. Also, Java 1.6.0_21 (both 32 bit and 64 bit) is installed on the machine. The printer installed is a ZPL Label Printer (Zebra Technologies ZTC GK420d).
If I use another application such as TextEdit to print, it works fine.
*Problem Description*
Whenever I try print from the Applet nothing comes from the printer, my code does not break or catch any exception at all but the printer queue gives the error: *pstopdffilter/pstocupsraster failed with err number -31000.*
Code
The code I use with this Java Applet works absolutely fine on Windows XP 32 bit (IE 7.0, Google Chrome and Firefox) as well as on Windows 7 64 bit (I.E 8.0, Google Chrome and Firefox) but never on the Mac. For any developers who might be able to help, the code is below:
import java.applet.Applet;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.PrintServiceAttribute;
import javax.print.attribute.standard.PrinterName;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
public class UKMJavaPrintApplet extends Applet
{
public void init()
{
System.out.println("Initialising UK Mail Java Printing Applet...");
}
public void start()
{
System.out.println("Starting UK Mail Java Printing Applet...");
PrintLabelZPL("^XA^FO100,40^BY3^B3,,30^FD123ABC^XZ","Zebra Technologies ZTC GK420d");
}
public void stop()
{
System.out.println("Stopping UK Mail Java Printing Applet...");
}
public void destroy()
{
System.out.println("Preparing unload of UK Mail Java Printing Applet...");
}
public int GetPrinterCount()
{
PrintService[] services = null;
int serviceLength = 0;
try
{
services = PrintServiceLookup.lookupPrintServices(null, null);
if(services != null && services.length > 0)
{
serviceLength = services.length;
}
}
catch(Exception z)
{
System.out.println("Failed to get printer count: " + z.getMessage());
z.printStackTrace();
}
return serviceLength;
}
public String GetPrinterName(int index)
{
String sPrinterName = null;
String printerName = "";
PrintService[] services = null;
try
{
services = PrintServiceLookup.lookupPrintServices(null, null);
for (int k=0; k < services.length; k++)
{
PrintServiceAttribute attr = services[k].getAttribute(PrinterName.class);
sPrinterName = ((PrinterName) attr).getValue();
if(index == k)
{
printerName = sPrinterName;
break;
}
}
}
catch(Exception r)
{
System.out.println("Failed to get printer name: " + r.getMessage());
r.printStackTrace();
}
return printerName;
}
public Boolean PrintLabelZPL(String zplString, String printerName)
{
String errStr = "";
Boolean boolSuccess = false;
try
{
if(printerName != null && printerName != "")
{
PrintService psZebra = null;
String sPrinterName = null;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
for (int i = 0; i < services.length; i++)
{
PrintServiceAttribute attr = services .getAttribute(PrinterName.class);
sPrinterName = ((PrinterName) attr).getValue();
if (printerName.equals(sPrinterName))
{
psZebra = services;
break;
}
}
if (psZebra != null)
{
DocPrintJob job = psZebra.createPrintJob();
byte[] by = zplString.getBytes();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(by, flavor, null);
System.out.println("Printing to: " + printerName);
job.print(doc, pras);
boolSuccess = true;
System.out.println("Printing Successful.");
}
else
{
errStr = "Zebra printer not found.";
System.out.println(errStr);
boolSuccess = false;
}
}
else
{
errStr = "No printer name was provided.";
System.out.println(errStr);
boolSuccess = false;
}
}
catch (PrintException e)
{
System.out.println("Print Failed with PrintException: " + e.getMessage());
boolSuccess = false;
e.printStackTrace();
}
catch (Exception f)
{
System.out.println("Print Failed: " + f.getMessage());
boolSuccess = false;
f.printStackTrace();
}
return boolSuccess;
}
}
Does anyone have any ideas on how I can resolve this and print to the ZPL printer from my Java Applet on the Mac?
Any help would be much appreciated.
Thanks!
Mac Mini Aluminum, Mac OS X (10.6.4), 2.4 Ghz Intel Core 2 Duo. 2 GB 1067 MHz DDR3. Macintosh HD.