2012-08-16 10 views
6

मैं एक साधारण स्ट्रिंग ("विश्व नमस्ते") प्रिंटर को भेजने के लिए कोशिश कर रहा हूँ करने के लिए सादा पाठ भेजा जा रहा है, लेकिन किसी कारण से, यह केवल पहला वर्ण ("एच")डिफ़ॉल्ट प्रिंटर

यहाँ प्रिंट कोड

public class CardPrinter { 
    public static void main(String[] args) { 
     try { 
      PrintService mPrinter = null; 
      Boolean bFoundPrinter = false; 

      PrintService[] printServices = PrinterJob.lookupPrintServices(); 

      // 
      // Iterates the print services and print out its name. 
      // 
      for (PrintService printService : printServices) { 
       String sPrinterName = printService.getName(); 
       if (sPrinterName.equals("DTC4000 Card Printer")) { 
        mPrinter = printService; 
        bFoundPrinter = true; 
       } 
      } 

      // Open the image file 
      String testData = "Hello World !"; 
      InputStream is = new ByteArrayInputStream(testData.getBytes()); 
      DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE ; 

      // Find the default service 
      PrintService service = PrintServiceLookup.lookupDefaultPrintService(); 
      System.out.println(service); 

      // Create the print job 
      DocPrintJob job = service.createPrintJob(); 
      Doc doc= new SimpleDoc(is, flavor, null); 

      // Monitor print job events; for the implementation of PrintJobWatcher, 
      PrintJobWatcher pjDone = new PrintJobWatcher(job); 

      // Print it 
      job.print(doc, null); 

      // Wait for the print job to be done 
      pjDone.waitForDone(); 

      // It is now safe to close the input stream 
      is.close(); 
     } catch (PrintException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 

    static class PrintJobWatcher { 
     // true iff it is safe to close the print job's input stream 
     boolean done = false; 

     PrintJobWatcher(DocPrintJob job) { 
      // Add a listener to the print job 
      job.addPrintJobListener(new PrintJobAdapter() { 
       public void printJobCanceled(PrintJobEvent pje) { 
        allDone(); 
       } 
       public void printJobCompleted(PrintJobEvent pje) { 
        allDone(); 
       } 
       public void printJobFailed(PrintJobEvent pje) { 
        allDone(); 
       } 
       public void printJobNoMoreEvents(PrintJobEvent pje) { 
        allDone(); 
       } 
       void allDone() { 
        synchronized (PrintJobWatcher.this) { 
         done = true; 
         PrintJobWatcher.this.notify(); 
        } 
       } 
      }); 
     } 
     public synchronized void waitForDone() { 
      try { 
       while (!done) { 
        wait(); 
       } 
      } catch (InterruptedException e) { 
      } 
     } 
    } 
} 

कोई विचार?

उत्तर

5

एक रूप फ़ीड जोड़ना,

String testData = "Hello World !\f"; 

समस्या

+0

आप कृपया जांच कर सकता है हल क्यों अपने अपने प्रिंटर के लिए कुछ भी प्रिंट नहीं? – YumYumYum

+1

कैसे, वास्तव में, _I_ अपने प्रिंटर की जांच कर सकता है? :-) – Shai

+0

मैं आपको टीमव्यूज़र दे सकता हूं? वेब कैमरे से? क्योंकि कोड सर काम नहीं कर रहा है। – YumYumYum

संबंधित मुद्दे