资源简介
Java调用Zebra打印机,采用ZPL指令。支持打印中文,包含ts24.lib文件,支持打印二维码。
代码片段和文件信息
package print;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
public class SimplePrint {
byte[] dotfont;
/**
* 读取指令txt文件
* @return
* @throws Exception
*/
public static String input() throws Exception {
File inputStream = new File(“e:/C.txt“);
InputStreamReader read = new InputStreamReader(new FileInputStream(
inputStream));
BufferedReader reader = new BufferedReader(read);
String string = ““;
StringBuffer buffer = new StringBuffer();
while ((string = reader.readLine()) != null) {
buffer.append(string);
}
read.close();
return buffer.toString();
}
public static void main(String[] args) {
try {
SimplePrint a = new SimplePrint();
String str = input();
a.print(str);//将打印指令发送到打印机
} catch (Exception e) {
e.printStackTrace();
}
}
public SimplePrint() throws Exception {
File file = new File(“c:/d/ts24.lib“);
FileInputStream fis = new FileInputStream(file);
dotfont = new byte[fis.available()];
fis.read(dotfont);
fis.close();
}
public void print(String str) throws PrintException {
PrintService psZebra = PrintServiceLookup.lookupDefaultPrintService();
if (psZebra == null) {
return;
}
DocPrintJob job = psZebra.createPrintJob();
byte[] by = str.getBytes();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(by flavor null);
job.print(doc null);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 62366 2015-04-15 14:31 javaGt800demo\C.txt
文件 301 2015-04-15 15:51 javaGt800demo\Print\.classpath
文件 381 2015-04-15 15:51 javaGt800demo\Print\.project
文件 629 2015-04-15 15:51 javaGt800demo\Print\.settings\org.eclipse.jdt.core.prefs
文件 2790 2015-04-15 15:57 javaGt800demo\Print\bin\print\SimplePrint.class
文件 1875 2015-04-15 15:57 javaGt800demo\Print\src\print\SimplePrint.java
文件 487296 2014-01-24 11:13 javaGt800demo\ts24.lib
文件 6517208 2015-03-30 11:16 javaGt800demo\Zebra_4.6.67.03.exe
目录 0 2015-04-15 16:24 javaGt800demo\Print\bin\print
目录 0 2015-04-15 16:24 javaGt800demo\Print\src\print
目录 0 2015-04-15 16:24 javaGt800demo\Print\.settings
目录 0 2015-04-15 16:24 javaGt800demo\Print\bin
目录 0 2015-04-15 16:24 javaGt800demo\Print\src
目录 0 2015-04-15 16:24 javaGt800demo\Print
目录 0 2018-11-27 10:40 javaGt800demo
----------- --------- ---------- ----- ----
7072846 15
评论
共有 条评论