Home > Back-end >  java awt print issue(print keeps printing in unknown format and forever)?
java awt print issue(print keeps printing in unknown format and forever)?

Time:10-10

I am using jwt awt to print pdf file in java. But the print keeps printing in unknown format and forever. Please find the below image, enter image description here

I have used java code,

    PrintService service = PrintUtility.findPrintService("Champ RP Series");
        FileInputStream inputStream = new FileInputStream("D:/Rose/Work/17.pdf");
        PrintRequestAttributeSet  pras = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
        Doc doc = new SimpleDoc(inputStream, flavor, null);
        DocPrintJob job = service.createPrintJob();

        job.print(doc, pras);
        inputStream.close();

Is there any way to preview this before printing? How can I solve this issue? Thank you

CodePudding user response:

If your printer is a Champ it needs the pdf converted into Esc/POS Printer Language

Here we have a web page or PDF prior to print on the left and the Esc/POS codes the printer needs on the right. There is NO way you can directly send PDF to POS thermal unless it has an onboard PDF reading computer.

Generally "Thermal Printers" require either an encoded binary 7/8bit stream that includes "Escape Characters" sometimes seen as left arrow or box, that will not be used in a PDF, or 6/7bit text stream such as Zebra Print Language (ZPL) as used mainly by dispatch label devices.

enter image description here

Simulated Output enter image description here

The System Printer Application converts lines of input text (billing items) into strings of plain text with instructions as to which font to use from the printers onboard fonts (ANK Font Font A: 12x24dots, Font B: 9x17dots). The technology is similar to traditional monochrome dot matrix printers such as Epson 80 series (simulated above) but updated to cater for high speed serial (USB BT WiFi) rather than "fast" clunky Centronics LPT1 parallel cables.

You asked if you can preview before print and the best I can find are
php java tools https://github.com/dacduong/escpos-printer-simulator
or commercial apps (as above https://www.pclviewer.com/escdownload.htm)
or this one looks promising as lightweight android based mobile? https://github.com/402d/Virtual_POS_printer

  • Related