Print with Java with IP-configured printer

Asked

Viewed 119 times

2

Well I needed to solve a problem which is, since the software is going to run in the cloud, I was thinking of sending the information to the printer via the IP-configured printer on the machine, I’ve already set it up on Windows but haven’t found any right example on the Internet to do it the way I want, through a fixed IP. Some way to tailor this code below to do this?

    try {

        InputStream inputStream = new ByteArrayInputStream(cupomNaoFiscal.getBytes());
        DocFlavor docFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
        SimpleDoc simpleDoc = new SimpleDoc(inputStream, docFlavor, null);
        PrintService printService = PrintServiceLookup.lookupDefaultPrintService();

        PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
        printRequestAttributeSet.add(new JobName("Impressão", null));
        printRequestAttributeSet.add(OrientationRequested.PORTRAIT);
        printRequestAttributeSet.add(MediaSizeName.ISO_A8);
        printRequestAttributeSet.add();

        DocPrintJob docPrintJob = printService.createPrintJob();

        docPrintJob.print(simpleDoc, printRequestAttributeSet);

        inputStream.close();

    } catch (Exception e) {
        return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
    }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.