用applet。
可以参考下.自己写的一个例子import java.awt.Graphics
import java.awt.Graphics2D
import java.awt.Image
import java.awt.print.PageFormat
import java.awt.print.Paper
import java.awt.print.Printable
import java.awt.print.PrinterException
import java.awt.print.PrinterJob
import java.util.Queue
import com.google.zxing.WriterException
public class QrPrint implements Printable {
public void print() throws PrinterException {
PrinterJob pj = PrinterJob.getPrinterJob()
PageFormat pf = pj.defaultPage()
Paper paper = new Paper()
double margin = 0.1// half inch
paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,paper.getHeight() - margin * 2)
pf.setPaper(paper)
pj.setPrintable(this, pf)
pj.print()
}
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if ("判断如果打印完了就退出") {
return Printable.NO_SUCH_PAGE
}
try {
Image eanImage = generateEANBufferedImage(content,120,20)
Graphics2D g2 = (Graphics2D) graphics
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY()) //设置可成像的X和Y轴的距离
g2.drawImage(eanImage, 0, 80, null) //设置打印的边距
g2.drawString("字符串:",130,20)
} catch (WriterException e) {
e.printStackTrace()
return Printable.NO_SUCH_PAGE
}
return Printable.PAGE_EXISTS
}
private BufferedImage generateBufferedImage(String content,int width,int height) throws WriterException {
Hashtable<EncodeHintType,String>hints = new Hashtable<EncodeHintType,String>()
hints.put(EncodeHintType.CHARACTER_SET, "utf-8")
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.EAN_13, width, height, hints)
return MatrixToImageWriter.toBufferedImage(bitMatrix)
}
}
在打印机设置里。斑马zt411打印机调速在打印机设置里1、首先进入电脑桌面,点击鼠标右键选择“开始”选项。在“开始”选项的下拉菜单中,选择“打印和传真”,双击鼠标右键。
2、其次在“打印和传真”下拉界面,选择斑马打印机安装好的驱动。鼠标右击“打印首选项”。
3、最后在“选项”下拉界面,可更改打印速度。