How to send esc/p2 commands to dot matrix printer in Java

919 Views Asked by At

I am printing a string using JtextArea.

Here is my code.

  JTextArea text = new JTextArea();

  text.setText(XmlReceiptPrinter.sb.toString());

  text.setFont(new Font("Courier New", Font.BOLD, 9));
  PrintRequestAttributeSet attrSet = new HashPrintRequestAttributeSet();

  // Set Margins
  // For A4 paper(width = 210mm X height = 297mm)
  int margin = 22;
  int y_margin=12;
  attrSet.add(new MediaPrintableArea(margin,y_margin,219-margin,130-y_margin,Size2DSyntax.MM));
  //
  text.print(null, new MessageFormat(""), false, this.service, attrSet, true);

I am giving print to a dot matrix LQ-350 printer. I have set page height and width. It is printing in correct area.

But after printing in the first paper, the paper is scrolling up and setting third page ready to next print. So it is skipping the second page.

I want to set page length for dot matrix printer. In DotMatrix user manual I found some esc/p2 sequence need to send while printing. How can I use?

0

There are 0 best solutions below