打印机 型号:X-1000VL
用的是PPLB
环境是windowsX64 eclipse jdk1.8(64位)
jar包 jna-4.2.2..jar
dll : WinPort.dll ,Winpplb.dll (64位) 这两个dll放在C:\Windows\System32 或者放在项目根目录下
代码:
package sample;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class pplb {
public interface Winpplb extends Library {
Winpplb API = (Winpplb) Native.loadLibrary("Winpplb",
Winpplb.class);
int B_Bar2d_Maxi(int x, int y, int cl, int cc, int pc, String data);
int B_Bar2d_PDF417(int x, int y, int w, int v, int s, int c, int px,
int py, int r, int l, int t, int o, String data);
int B_Bar2d_PDF417_N(int x, int y, int w, String para, String data);
void B_ClosePrn();
int B_CreatePrn(int selection, String filename);
int B_Del_Form(String formname);
int B_Del_Pcx(String pcxname);
int B_Draw_Box(int x, int y, int thickness, int hor_dots,
int ver_dots);
int B_Draw_Line(char mode, int x, int y, int hor_dots, int ver_dots);
int B_Error_Reporting(char option);
int B_Get_DLL_VersionA(int nShowMessage);
int B_Get_Graphic_ColorBMP(int x, int y, String filename);
int B_Get_Graphic_ColorBMPEx(int x, int y, int nWidth, int nHeight,
int rotate, String id_name, String filename);
int B_Get_Pcx(int x, int y, String filename);
int B_Initial_Setting(int Type, String Source);
int B_WriteData(int IsImmediate, byte[] pbuf, int length);
int B_ReadData(byte[] pbuf, int length, int dwTimeoutms);
int B_Load_Pcx(int x, int y, String pcxname);
int B_Open_ChineseFont(String path);
int B_Print_Form(int labset, int copies, String form_out, String var);
int B_Print_MCopy(int labset, int copies);
int B_Print_Out(int labset);
int B_Prn_Barcode(int x, int y, int ori, String type, int narrow,
int width, int height, char human, String data);
void B_Prn_Configuration();
int B_Prn_Text(int x, int y, int ori, int font, int hor_factor,
int ver_factor, char mode, String data);
int B_Prn_Text_Chinese(int x, int y, int fonttype, String id_name,
String data);
int B_Prn_Text_TrueType(int x, int y, int FSize, String FType,
int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, String id_name,
String data);
int B_Prn_Text_TrueType_W(int x, int y, int FHeight, int FWidth,
String FType, int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut,
String id_name, String data);
int B_Prn_Text_TrueType_Uni(int x, int y, int FSize, String FType, int Fspin,
int FWeight, int FItalic, int FUnline, int FStrikeOut, String id_name,
String data, int format);
int B_Prn_Text_TrueType_UniB(int x, int y, int FSize, String FType, int Fspin,
int FWeight, int FItalic, int FUnline, int FStrikeOut, String id_name,
String data, int format);
int B_Select_Option(int option);
int B_Select_Option2(int option, int p);
int B_Select_Symbol(int num_bit, int symbol, int country);
int B_Select_Symbol2(int num_bit, String csymbol, int country);
int B_Set_Backfeed(char option);
int B_Set_BMPSave(int nSave, String strBMPFName);
int B_Set_Darkness(int darkness);
int B_Set_DebugDialog(int nEnable);
int B_Set_Direction(char direction);
int B_Set_Form(String formfile);
int B_Set_Labgap(int lablength, int gaplength);
int B_Set_Labwidth(int labwidth);
int B_Set_Originpoint(int hor, int ver);
int B_Set_Prncomport(int baud, char parity, int data, int stop);
int B_Set_Prncomport_PC(int nBaudRate, int nByteSize, int nParity,
int nStopBits, int nDsr, int nCts, int nXonXoff);
int B_Set_Speed(int speed);
int B_Set_ProcessDlg(int nShow);
int B_Set_ErrorDlg(int nShow);
int B_GetUSBBufferLen();
int B_EnumUSB(byte[] buf);
int B_CreateUSBPort(int nPort);
int B_ResetPrinter();
int B_GetPrinterResponse(byte[] buf, int nMax);
int B_TFeedMode(int nMode);
int B_TFeedTest();
int B_CreatePort(int nPortType, int nPort, String filename);
int B_Execute_Form(String form_out, String var);
int B_Bar2d_QR(int x, int y, int model, int scl, char error,
char dinput, int c, int d, int p, String data);
int B_GetNetPrinterBufferLen();
int B_EnumNetPrinter(byte[] buf);
int B_CreateNetPort(int nPort);
}
public static void main(String[] args) {
System.setProperty("jna.encoding", "GBK");
int nLen = Winpplb.API.B_GetUSBBufferLen() + 1;
byte[] pbuf = null;
if (nLen > 1)
{
pbuf = new byte[nLen];
Winpplb.API.B_EnumUSB(pbuf);
//return Convert.ToString(pbuf);
Winpplb.API.B_CreateUSBPort(1);
}
else
{
System.out.println("2");
}
// sample setting.
Winpplb.API.B_Set_Backfeed('B');
Winpplb.API.B_Set_Darkness(9);
//Winpplb.API.B_Set_Speed(3);
//print text, true type text.
Winpplb.API.B_Set_Originpoint(20, 10);
Winpplb.API.B_Get_Graphic_ColorBMPEx(20, 10, 790,540,0,"result11","D:\\result11.BMP");
// output.
Winpplb.API.B_Print_Out(1);// copy 2.
// close port.
Winpplb.API.B_ClosePrn();
}
}