0 Replies Latest reply on Oct 1, 2013 12:28 PM by jtyreman

    Printing a string from Java (INPUT_STREAM/BYTE_ARRAY)


      Hi all,


      got the following code:


              DocFlavor psInFormat = DocFlavor.BYTE_ARRAY.AUTOSENSE;
              Doc myDoc = new SimpleDoc(content.getBytes(), psInFormat, null);
              PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
              PrintService[] services =
                  PrintServiceLookup.lookupPrintServices(psInFormat, aset);
              aset.add(new Copies(1));
              // this step is necessary because I have several printers configured
              PrintService myPrinter = null;
              for (int i = 0; i < services.length; i++) {
                  String svcName = services[i].toString();
                  System.out.println("service found: " + svcName);
                  if (svcName.contains("BranchTest")) {
                      myPrinter = services[i];
              if (myPrinter != null) {
                  DocPrintJob job = myPrinter.createPrintJob();
                  try {
                      PrintJobWatcher pjw = new PrintJobWatcher(job);
                      job.print(myDoc, aset);
                      } catch (Exception pe) {
              } else {
                  returnString = "no printer services found";


      the issue is that on eclipse within a windows environment this works perfectly, but on linux with only a ppd installed for the printer it errors, it looks like it is interpreting the string as postscript?


      2 Questions:


      A ) is there a different way of printing a string through Java

      B) is there a way of printing a string in POSTSCRIPT?


      Many Thanks