Paper Stops in Printer - Java Printing Problems

This class is used to print a file. I have a JButton (not shown in the code below) that runs this code and opens a print dialog. However, when I press print, it starts printing, but if the text doesn't fill the entire page, it stops and doesn't pop it out of the printer. Am I missing something that might be causing this problem?

try{
        FileInputStream textStream;
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        textStream = new FileInputStream(testFileName);
        DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
        Doc test = new SimpleDoc(textStream, flavor, null);

        PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, aset);

        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();

        if(services.length == 0){
            if(defaultService==null){
                System.out.println("NO PRINTERS");
            }else{
                DocPrintJob job = defaultService.createPrintJob();
                job.print(test, aset);
            }
        }else{

            PrintService service = ServiceUI.printDialog(null, 200, 200, services, defaultService, flavor, aset);


            if(service != null){
                DocPrintJob job = service.createPrintJob();
                job.print(test, aset);
            }
        }

    }catch (IOException | PrintException e){
        e.printStackTrace();
    }

      

+3


source to share


1 answer


javax.print

and your code works like this:

Read InputStream

(some file) of some (unspecified = INPUT_STREAM.AUTOSENSE

) format and "send" ( .print

) PrintJob to the printer system for operating systems.

What happens next depends entirely on your operating system settings, such as correctly installed printer drivers and printer connectivity.



In your case, the destination queue may not support the file format (aka PDL) you are trying to print. Even text PDLs use ESC sequences to control the printer. Windows and Unix / Mac systems have different approaches. CUPS can handle PDL like PDF or Postscript by default.

Once the job.print () method has finished with the OS to process the print data. To track down the problem, you must check your printer system. On Unix, probably CUPS .

0


source







All Articles