├── web-print-agent ├── print.ico ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Model │ └── PrintRe.cs ├── App.xaml ├── packages.config ├── Utils │ ├── Global.cs │ ├── LocalPrinter.cs │ ├── Notification.cs │ └── WindowsMin.cs ├── App.config ├── Service │ ├── Socket │ │ ├── ISocketService.cs │ │ ├── SocketService.cs │ │ ├── MySocketService.cs │ │ └── SocketBase.cs │ ├── MyLogService.cs │ └── PrintService.cs ├── NotificationWindow.xaml ├── MainWindow.xaml ├── App.xaml.cs ├── log4net.config ├── MainWindow.xaml.cs ├── NotificationWindow.xaml.cs ├── web-print-agent.csproj └── DynamicJson.cs ├── test ├── index.html └── test.json ├── README.md ├── web-print-agent.sln └── .gitignore /web-print-agent/print.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlanLang/web-print-agent/HEAD/web-print-agent/print.ico -------------------------------------------------------------------------------- /web-print-agent/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /web-print-agent/Model/PrintRe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace web_print_agent.Model 8 | { 9 | public class PrintRe 10 | { 11 | public double id { get; set; } 12 | public int code { get; set; } 13 | public string msg {get;set;} 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /web-print-agent/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /web-print-agent/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /web-print-agent/Utils/Global.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace web_print_agent.Utils 8 | { 9 | public class Global 10 | { 11 | public static bool canClose = false; 12 | public static bool canSatrt = false; 13 | 14 | public const string SYSISRUN = "系统正在运行"; 15 | public const string PRINTSETSUCESS = "成功设置打印机:"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /web-print-agent/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /web-print-agent/Service/Socket/ISocketService.cs: -------------------------------------------------------------------------------- 1 | using Fleck; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace web_print_agent.Service.Socket 9 | { 10 | public interface ISocketService 11 | { 12 | 13 | /// 14 | /// 当建立socket连接时,会调用此方法 15 | /// 16 | /// 17 | void OnConnected(string clientIp); 18 | 19 | void OnDisconnected(); 20 | 21 | void OnMessage(string msg, IWebSocketConnection client); 22 | 23 | void OnError(Exception ex); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 打印测试 5 | 6 | 7 | 8 | 28 | 29 | -------------------------------------------------------------------------------- /test/test.json: -------------------------------------------------------------------------------- 1 | {"id":1537148688,"page":{"width":210,"height":297},"content":[{"type":"text","text":"南昌故郡,\r\n洪都新府。星分翼轸,地接衡庐。襟三江而带五湖,控蛮荆而引瓯越。物华天宝,龙光射牛斗之墟;人杰地灵,徐孺下陈蕃之榻。雄州雾列,俊采星驰,台隍枕夷夏之交,宾主尽东南之美。都督阎公之雅望,棨戟遥临;宇文新州之懿范,襜帷暂驻。十旬休假,胜友如云;千里逢迎,高朋满座。腾蛟起凤,孟学士之词宗;紫电青霜,王将军之武库。家君作宰,路出名区;童子何知,躬逢胜饯。时维九月,序属三秋。潦水尽而寒潭清,烟光凝而暮山紫。俨骖騑于上路,访风景于崇阿。临帝子之长洲,得仙人之旧馆。层台耸翠,上出重霄;飞阁流丹,下临无地。鹤汀凫渚,穷岛屿之萦回;桂殿兰宫,列冈峦之体势。披绣闼,俯雕甍,山原旷其盈视,川泽盱其骇瞩。闾阎扑地,钟鸣鼎食之家;舸舰迷津,青雀黄龙之轴。虹销雨霁,彩彻区明。落霞与孤鹜齐飞,秋水共长天一色。渔舟唱晚,响穷彭蠡之滨;雁阵惊寒,声断衡阳之浦。遥襟俯畅,逸兴遄飞。爽籁发而清风生,纤歌凝而白云遏。睢园绿竹,气凌彭泽之樽;邺水朱华,光照临川之笔。四美具,二难并。穷睇眄于中天,极娱游于暇日。天高地迥,觉宇宙之无穷;兴尽悲来,识盈虚之有数。望长安于日下,指吴会于云间。地势极而南溟深,天柱高而北辰远。关山难越,谁悲失路之人?萍水相逢,尽是他乡之客。怀帝阍而不见,奉宣室以何年?嗟乎!时运不济,命运多舛。冯唐易老,李广难封。屈贾谊于长沙,非无圣主;窜梁鸿于海曲,岂乏明时。所赖君子安贫,达人知命。老当益壮,宁移白首之心?穷且益坚,不坠青云之志。酌贪泉而觉爽,处涸辙以犹欢。北海虽赊,扶摇可接;东隅已逝,桑榆非晚。孟尝高洁,空怀报国之心;阮藉猖狂,岂效穷途之哭!勃,三尺微命,一介书生。无路请缨,等终军之弱冠;有怀投笔,慕宗懿之长风。舍簪笏于百龄,奉晨昏于万里。非谢家之宝树,接孟氏之芳邻。他日趋庭,叨陪鲤对;今晨捧袂,喜托龙门。杨意不逢,抚凌云而自惜;钟期既遇,奏流水以何惭?鸣呼!胜地不常,盛筵难再。兰亭已矣,梓泽丘墟。临别赠言,幸承恩于伟饯;登高作赋,是所望于群公。敢竭鄙诚,恭疏短引。一言均赋,四韵俱成。请洒潘江,各倾陆海云尔!","size":20,"x":40,"y":5},{"type":"line","x1":1,"y1":1,"x2":1,"y2":5},{"type":"qrcode","text":"打印的内容","width":70,"height":70,"x":55,"y":15}]} -------------------------------------------------------------------------------- /web-print-agent/Service/Socket/SocketService.cs: -------------------------------------------------------------------------------- 1 | using Fleck; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace web_print_agent.Service.Socket 9 | { 10 | /// 11 | /// Socket服务类,此类只允许被继承,不可直接实例化 12 | /// 13 | public abstract class SocketService : ISocketService 14 | { 15 | public IDictionary dic_Sockets = new Dictionary(); 16 | 17 | public virtual void OnConnected(string clientIp) 18 | { 19 | } 20 | 21 | public virtual void OnDisconnected() 22 | { 23 | } 24 | 25 | public abstract void OnError(Exception ex); 26 | 27 | public virtual void OnMessage(string msg, IWebSocketConnection client) 28 | { 29 | 30 | } 31 | 32 | public void sendAll(string msg) 33 | { 34 | foreach (var item in dic_Sockets) 35 | { 36 | item.Value.Send(msg); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /web-print-agent/Service/MyLogService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace web_print_agent.Service 8 | { 9 | public class MyLogService 10 | { 11 | static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo"); 12 | static readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror"); 13 | static readonly log4net.ILog logprint = log4net.LogManager.GetLogger("logprint"); 14 | 15 | public static void Error(string ErrorMsg, Exception ex = null) 16 | { 17 | if (ex != null) 18 | { 19 | logerror.Error(ErrorMsg, ex); 20 | } 21 | else 22 | { 23 | logerror.Error(ErrorMsg); 24 | } 25 | } 26 | public static void Info(string Msg) 27 | { 28 | loginfo.Info(Msg); 29 | } 30 | 31 | public static void Print(string Msg) 32 | { 33 | logprint.Info(Msg); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /web-print-agent/Service/Socket/MySocketService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Fleck; 7 | 8 | namespace web_print_agent.Service.Socket 9 | { 10 | public class MySocketService:SocketService 11 | { 12 | PrintService printService; 13 | public MySocketService(PrintService printService) 14 | { 15 | this.printService = printService; 16 | } 17 | public override void OnError(Exception ex) 18 | { 19 | MyLogService.Error("socket调用发生错误:" + ex.Message,ex); 20 | } 21 | 22 | public override void OnMessage(string msg, IWebSocketConnection client) 23 | { 24 | if (printService.SetPrintOrder(msg)) 25 | { 26 | bool re = printService.TestPrintOrder(); 27 | client.Send(printService.Msg); 28 | base.OnMessage(msg, client); 29 | } 30 | else { 31 | client.Send(printService.Msg); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # web打印代理 2 | ## 简介 3 | 一款静默打印代理工具,通过建立Socket服务,接收打印指令,通过解析打印指令完成打印。 4 | ## 使用方式 5 | 1. 下载源码或者release版 6 | 2. 运行.exe文件 7 | 3. 打开测试页 `index.html` 8 | 4. 点击测试页的打印按钮 9 | 10 | ### 系统功能 11 | * 最小化到状态栏 12 | * 单实例 13 | * 设置默认打印机 14 | * 保留异常日志 15 | * 保留打印日志 16 | * 打印结果反馈 17 | 18 | ### 打印功能 19 | * 自定义纸张大小 20 | * 打印条形码,二维码 21 | * 打印图片 22 | 23 | ## 指令示例 24 | * JSON格式 25 | * 类型:text/qrcoe/datamatrix/barcode/line/image 26 | * 单位:毫米 27 | * 文字换行手动使用`\r\n` 28 | 29 | web->代理 30 | ``` 31 | { 32 | "id":1537148688, 33 | "page":{ 34 | "width":210, 35 | "height":297 36 | }, 37 | "content": 38 | [ 39 | { 40 | "type":"text", 41 | "text":"改需求推荐使用支付宝", 42 | "size":20, 43 | "x":65, 44 | "y":100 45 | }, 46 | { 47 | "type":"line", 48 | "x1":0, 49 | "y1":130, 50 | "x2":210, 51 | "y2":130 52 | }, 53 | { 54 | "type":"qrcode", 55 | "text":"https://qr.alipay.com/tsx04136zdm6mxp7jvv4s2f", 56 | "width":70, 57 | "height":70, 58 | "x":70, 59 | "y":15 60 | } 61 | ] 62 | } 63 | ``` 64 | 代理->web 65 | ``` 66 | { 67 | id:1537148688, 68 | code:0,//0成功,1失败 69 | msg:"返回的消息" 70 | } 71 | ``` 72 | -------------------------------------------------------------------------------- /web-print-agent/NotificationWindow.xaml: -------------------------------------------------------------------------------- 1 | 11 | 12 |