├── .gitattributes ├── .gitignore ├── Bing.Printer.sln ├── LICENSE ├── README.md ├── build ├── pack.bat └── version.props ├── documents └── Bing.Printer.xmind ├── src ├── Bing.Printer.Abstractions │ ├── Bing.Printer.Abstractions.csproj │ ├── Builders │ │ └── IBarcodeBuilder.cs │ ├── Enums │ │ ├── Align.cs │ │ ├── BarcodeFontType.cs │ │ ├── BarcodePositionType.cs │ │ ├── BarcodeType.cs │ │ ├── BarcodeWidth.cs │ │ ├── CodeTable.cs │ │ ├── FontSize.cs │ │ ├── FontType.cs │ │ ├── PrintPaperType.cs │ │ ├── PrintStyle.cs │ │ ├── PrinterModeState.cs │ │ └── QrCodeSize.cs │ ├── Extensions │ │ └── PrinterExtensions.cs │ ├── IPrintCommand.cs │ ├── IPrintPaper.cs │ ├── IPrinter.cs │ ├── Operations │ │ ├── IBarcode.cs │ │ ├── IDrawer.cs │ │ ├── IFontStyle.cs │ │ ├── IImage.cs │ │ ├── IInitializePrint.cs │ │ ├── IPagerCut.cs │ │ ├── IPrintLine.cs │ │ ├── IPrintStyle.cs │ │ ├── IQrCode.cs │ │ ├── IStyle.cs │ │ └── IWriter.cs │ └── Options │ │ ├── BarcodeOptions.cs │ │ ├── PrintOptions.cs │ │ └── QrCodeOptions.cs ├── Bing.Printer.Core │ ├── Bing.Printer.Core.csproj │ ├── Exceptions │ │ └── PrintException.cs │ ├── Extensions │ │ └── PrinterExtensions.cs │ ├── Factories │ │ └── PrintPaperFactory.cs │ ├── Pagers │ │ ├── PrintPaper58mm.cs │ │ └── PrintPaper80mm.cs │ └── PrinterBase.cs └── Bing.Printer.EscPos │ ├── ASCIIControlConst.cs │ ├── ASCIIShowConst.cs │ ├── Bing.Printer.EscPos.csproj │ ├── Builders │ └── BarcodeBuilder.cs │ ├── Command.cs │ ├── CommandConst.cs │ ├── Commands │ ├── BarcodeCommand.cs │ ├── DrawerCommand.cs │ ├── FontStyleCommand.cs │ ├── ImageCommand.cs │ ├── InitializePrintCommand.cs │ ├── PagerCutCommand.cs │ ├── PrintLineCommand.cs │ ├── PrintStyleCommand.cs │ ├── QrCodeCommand.cs │ ├── StyleCommand.cs │ └── WriterCommand.cs │ ├── EscPosPrinter.cs │ ├── IEscPosPrinter.cs │ └── PrintCommand.cs └── tests └── Bing.Printer.Tests ├── Bing.Printer.Tests.csproj ├── BusinessTest.cs ├── Commands ├── FontStyleCommandTest.cs ├── PagerCutCommandTest.cs ├── PrintStyleCommandTest.cs └── WriterCommandTest.cs ├── EscPosPrinterTest.cs ├── TestBase.cs └── images ├── abe-lincoln.png ├── kitten.jpg ├── pd-logo-100.png ├── pd-logo-200.png ├── pd-logo-300.bmp ├── pd-logo-300.gif ├── pd-logo-300.jpg ├── pd-logo-300.png ├── pd-logo-400.png ├── pd-logo-500.png ├── pd-logo-600.png ├── pd-logo.png └── pd-logo.svg /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /Bing.Printer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Printer.Abstractions", "src\Bing.Printer.Abstractions\Bing.Printer.Abstractions.csproj", "{FF74E367-1062-4031-B712-4B79A283C8AE}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Printer.EscPos", "src\Bing.Printer.EscPos\Bing.Printer.EscPos.csproj", "{AF63462E-B1D9-4F27-B0BC-A0A85E9AEC3A}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Printer.Tests", "tests\Bing.Printer.Tests\Bing.Printer.Tests.csproj", "{ECAF6355-0F49-48E2-9CD3-E88EA9453149}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Printer.Core", "src\Bing.Printer.Core\Bing.Printer.Core.csproj", "{6D06AA61-4ADB-475D-8FE5-8AAAFFC71803}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "00-document", "00-document", "{8B83F472-19F3-4DD7-A4C2-87A0143FA6EB}" 15 | ProjectSection(SolutionItems) = preProject 16 | build\pack.bat = build\pack.bat 17 | README.md = README.md 18 | build\version.props = build\version.props 19 | EndProjectSection 20 | EndProject 21 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01-src", "01-src", "{28D3ECD1-D78F-4BEF-B627-9B6D495E8C12}" 22 | EndProject 23 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02-tests", "02-tests", "{098A1272-8524-4584-BA97-FDA569B72455}" 24 | EndProject 25 | Global 26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 | Debug|Any CPU = Debug|Any CPU 28 | Release|Any CPU = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {FF74E367-1062-4031-B712-4B79A283C8AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {FF74E367-1062-4031-B712-4B79A283C8AE}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {FF74E367-1062-4031-B712-4B79A283C8AE}.Release|Any CPU.ActiveCfg = Release|Any CPU 34 | {FF74E367-1062-4031-B712-4B79A283C8AE}.Release|Any CPU.Build.0 = Release|Any CPU 35 | {AF63462E-B1D9-4F27-B0BC-A0A85E9AEC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {AF63462E-B1D9-4F27-B0BC-A0A85E9AEC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {AF63462E-B1D9-4F27-B0BC-A0A85E9AEC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {AF63462E-B1D9-4F27-B0BC-A0A85E9AEC3A}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {ECAF6355-0F49-48E2-9CD3-E88EA9453149}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 40 | {ECAF6355-0F49-48E2-9CD3-E88EA9453149}.Debug|Any CPU.Build.0 = Debug|Any CPU 41 | {ECAF6355-0F49-48E2-9CD3-E88EA9453149}.Release|Any CPU.ActiveCfg = Release|Any CPU 42 | {ECAF6355-0F49-48E2-9CD3-E88EA9453149}.Release|Any CPU.Build.0 = Release|Any CPU 43 | {6D06AA61-4ADB-475D-8FE5-8AAAFFC71803}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {6D06AA61-4ADB-475D-8FE5-8AAAFFC71803}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {6D06AA61-4ADB-475D-8FE5-8AAAFFC71803}.Release|Any CPU.ActiveCfg = Release|Any CPU 46 | {6D06AA61-4ADB-475D-8FE5-8AAAFFC71803}.Release|Any CPU.Build.0 = Release|Any CPU 47 | EndGlobalSection 48 | GlobalSection(SolutionProperties) = preSolution 49 | HideSolutionNode = FALSE 50 | EndGlobalSection 51 | GlobalSection(NestedProjects) = preSolution 52 | {FF74E367-1062-4031-B712-4B79A283C8AE} = {28D3ECD1-D78F-4BEF-B627-9B6D495E8C12} 53 | {AF63462E-B1D9-4F27-B0BC-A0A85E9AEC3A} = {28D3ECD1-D78F-4BEF-B627-9B6D495E8C12} 54 | {ECAF6355-0F49-48E2-9CD3-E88EA9453149} = {098A1272-8524-4584-BA97-FDA569B72455} 55 | {6D06AA61-4ADB-475D-8FE5-8AAAFFC71803} = {28D3ECD1-D78F-4BEF-B627-9B6D495E8C12} 56 | EndGlobalSection 57 | GlobalSection(ExtensibilityGlobals) = postSolution 58 | SolutionGuid = {2B180E80-4532-4EF0-8658-3C57193CEDFF} 59 | EndGlobalSection 60 | EndGlobal 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 jianxuanbing 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bing.Printer 2 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://mit-license.org/) 3 | 4 | Bing.Printer是Bing应用框架的热敏打印操作核心库。 5 | 主要用于热敏打印相关功能操作。 6 | 7 | ## Nuget Packages 8 | |Nuget|版本号|说明| 9 | |---|---|---| 10 | |Bing.Printer.Abstractions|[![NuGet Badge](https://buildstats.info/nuget/Bing.Printer.Abstractions?includePreReleases=true)](https://www.nuget.org/packages/Bing.Printer.Abstractions)| 11 | |Bing.Printer.Core|[![NuGet Badge](https://buildstats.info/nuget/Bing.Printer.Core?includePreReleases=true)](https://www.nuget.org/packages/Bing.Printer.Core)| 12 | |Bing.Printer.EscPos|[![NuGet Badge](https://buildstats.info/nuget/Bing.Printer.EscPos?includePreReleases=true)](https://www.nuget.org/packages/Bing.Printer.EscPos)| 13 | 14 | ## 实现功能 15 | 16 | ## 依赖类库 17 | - System.Drawing.Common 18 | 19 | ## Demo 20 | 21 | ## 接口说明 22 | 23 | 24 | ## 作者 25 | 26 | 简玄冰 27 | 28 | ## 贡献与反馈 29 | 30 | > 如果你在阅读或使用Bing中任意一个代码片断时发现Bug,或有更佳实现方式,请通知我们。 31 | 32 | > 为了保持代码简单,目前很多功能只建立了基本结构,细节特性未进行迁移,在后续需要时进行添加,如果你发现某个类无法满足你的需求,请通知我们。 33 | 34 | > 你可以通过github的Issue或Pull Request向我们提交问题和代码,如果你更喜欢使用QQ进行交流,请加入我们的交流QQ群。 35 | 36 | > 对于你提交的代码,如果我们决定采纳,可能会进行相应重构,以统一代码风格。 37 | 38 | > 对于热心的同学,将会把你的名字放到**贡献者**名单中。 39 | 40 | ## 免责声明 41 | - 虽然我们对代码已经进行高度审查,并用于自己的项目中,但依然可能存在某些未知的BUG,如果你的生产系统蒙受损失,Bing 团队不会对此负责。 42 | - 出于成本的考虑,我们不会对已发布的API保持兼容,每当更新代码时,请注意该问题。 43 | 44 | ## 开源地址 45 | [https://github.com/bing-framework/Bing.Printer](https://github.com/bing-framework/Bing.Printer) 46 | 47 | ## License 48 | 49 | **MIT** 50 | 51 | > 这意味着你可以在任意场景下使用 Bing 应用框架而不会有人找你要钱。 52 | 53 | > Bing 会尽量引入开源免费的第三方技术框架,如有意外,还请自行了解。 54 | -------------------------------------------------------------------------------- /build/pack.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo %1 3 | cd .. 4 | 5 | rem clear old packages 6 | del output\* /q/f/s 7 | 8 | rem build 9 | dotnet build Bing.Printer.sln -c Release 10 | 11 | rem pack 12 | dotnet pack ./src/Bing.Printer.Abstractions/Bing.Printer.Abstractions.csproj 13 | dotnet pack ./src/Bing.Printer.Core/Bing.Printer.Core.csproj 14 | dotnet pack ./src/Bing.Printer.EscPos/Bing.Printer.EscPos.csproj 15 | 16 | rem push 17 | for %%i in (output\release\*.nupkg) do dotnet nuget push %%i -k %1 -s https://www.nuget.org/api/v2/package -------------------------------------------------------------------------------- /build/version.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0 4 | 0 5 | 1 6 | 20190709-1 7 | $(VersionMajor).$(VersionMinor).$(VersionPatch) 8 | 9 | 10 | 11 | 简玄冰 12 | 简玄冰 13 | 简玄冰 14 | https://github.com/bing-framework/Bing.Printer/blob/master/LICENSE 15 | https://github.com/bing-framework/Bing.Printer 16 | https://github.com/bing-framework/Bing.Printer 17 | git 18 | bing;applicationframework;dotnetcore;aspnetcore; 19 | Bing应用框架以MIT开源发布,可随意使用 20 | 21 | -------------------------------------------------------------------------------- /documents/Bing.Printer.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/documents/Bing.Printer.xmind -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Bing.Printer.Abstractions.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | Bing.Printer 6 | Bing.Printer.Abstractions是Bing应用框架的热敏打印操作抽象类库。 7 | Bing是一个.net core平台下的应用框架,旨在于提升小型团队的开发能力,由常用公共操作类、架构基类、第三方组件封装、第三方业务接口封装等组成。 8 | 9 | 10 | 11 | ..\..\output\release\ 12 | ..\..\output\release\netstandard2.0\Bing.Printer.Abstractions.xml 13 | 14 | 15 | 16 | ..\..\output\release\ 17 | ..\..\output\release\netstandard2.0\Bing.Printer.Abstractions.xml 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Builders/IBarcodeBuilder.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | 3 | namespace Bing.Printer.Builders 4 | { 5 | /// 6 | /// 条形码生成器 7 | /// 8 | public interface IBarcodeBuilder 9 | { 10 | /// 11 | /// 初始化 12 | /// 13 | void Init(); 14 | 15 | /// 16 | /// 设置宽度 17 | /// 18 | /// 宽度 19 | IBarcodeBuilder Width(BarcodeWidth width); 20 | 21 | /// 22 | /// 设置高度 23 | /// 24 | /// 高度 25 | IBarcodeBuilder Height(int height); 26 | 27 | /// 28 | /// 设置标签显示位置 29 | /// 30 | /// 位置 31 | IBarcodeBuilder LabelPosition(BarcodePositionType position); 32 | 33 | /// 34 | /// 设置标签字体 35 | /// 36 | /// 类型 37 | IBarcodeBuilder LabelFontB(BarcodeFontType type); 38 | 39 | /// 40 | /// 生成条形码 41 | /// 42 | /// 条形码类型 43 | /// 值 44 | byte[] Build(BarcodeType type, string value); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/Align.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 对齐方式 5 | /// 6 | public enum Align 7 | { 8 | /// 9 | /// 左对齐 10 | /// 11 | Left = 0, 12 | /// 13 | /// 居中 14 | /// 15 | Center = 1, 16 | /// 17 | /// 右对齐 18 | /// 19 | Right = 2 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/BarcodeFontType.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 条形码字体类型 5 | /// 6 | public enum BarcodeFontType 7 | { 8 | /// 9 | /// 字体A 10 | /// 11 | A = 0, 12 | /// 13 | /// 字体B 14 | /// 15 | B = 1 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/BarcodePositionType.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 条形码位置类型 5 | /// 6 | public enum BarcodePositionType 7 | { 8 | /// 9 | /// 无 10 | /// 11 | None = 0, 12 | /// 13 | /// 上面 14 | /// 15 | Above = 1, 16 | /// 17 | /// 下面 18 | /// 19 | Below = 2, 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/BarcodeType.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 条形码类型 5 | /// 6 | public enum BarcodeType 7 | { 8 | Ean13 = 0x43, 9 | Ean8 = 0x44, 10 | Code39 = 0x45, 11 | Code128 = 0x49 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/BarcodeWidth.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 条形码宽度 5 | /// 6 | public enum BarcodeWidth 7 | { 8 | /// 9 | /// 最紧凑 10 | /// 11 | Thinnest = 2, 12 | /// 13 | /// 紧凑 14 | /// 15 | Thin = 3, 16 | /// 17 | /// 默认 18 | /// 19 | Default = 4, 20 | /// 21 | /// 稀疏 22 | /// 23 | Thick = 5, 24 | /// 25 | /// 最稀疏 26 | /// 27 | Thickest = 6 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/CodeTable.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 字符代码表 5 | /// 6 | public enum CodeTable 7 | { 8 | /// 9 | /// Page 0 USA, Standard Europe [CP437] 10 | /// 11 | CP437 = 0, 12 | /// 13 | /// Page 1 Katakana 14 | /// 15 | Katakana = 1, 16 | /// 17 | /// Page 2 Multilingual(Latin-1) [CP850] 18 | /// 19 | CP850 = 2, 20 | /// 21 | /// Page 3Portuguese [CP860] 22 | /// 23 | CP860 = 3, 24 | /// 25 | /// Page 4 Canadian-French [CP863] 26 | /// 27 | CP863 = 4, 28 | /// 29 | /// Page 5 Nordic [CP865] 30 | /// 31 | CP865 = 5, 32 | /// 33 | /// Page 6 Slavic(Latin-2) [CP852] 34 | /// 35 | CP852 = 6, 36 | /// 37 | /// Page 7 Turkish [CP857] 38 | /// 39 | CP857 = 7, 40 | /// 41 | /// Page 8 Greek [CP737] 42 | /// 43 | CP737 = 8, 44 | /// 45 | /// Page 9 Russian(Cyrillic) [CP866] 46 | /// 47 | CP866 = 9, 48 | /// 49 | /// Page 10 Hebrew [CP862] 50 | /// 51 | CP862 = 10, 52 | /// 53 | /// Page 11 Baltic [CP775] 54 | /// 55 | CP775 = 11, 56 | /// 57 | /// Page 12 Polish 58 | /// 59 | Polish = 12, 60 | /// 61 | /// Page 13 Latin-9 [ISO8859-15] 62 | /// 63 | ISO8859_15 = 13, 64 | /// 65 | /// Page 14 Latin1[Win1252] 66 | /// 67 | Win1252 = 14, 68 | /// 69 | /// Page 15 Multilingual Latin I + Euro[CP858] 70 | /// 71 | CP858 = 15, 72 | /// 73 | /// Page 16 Russian(Cyrillic)[CP855] 74 | /// 75 | CP855 = 16, 76 | /// 77 | /// Page 17 Russian(Cyrillic)[Win1251] 78 | /// 79 | Win1251 = 17, 80 | /// 81 | /// Page 18 Central Europe[Win1250] 82 | /// 83 | Win1250 = 18, 84 | /// 85 | /// Page 19 Greek[Win1253] 86 | /// 87 | Win1253 = 19, 88 | /// 89 | /// Page 20 Turkish[Win1254] 90 | /// 91 | Win1254 = 20, 92 | /// 93 | /// Page 21 Hebrew[Win1255] 94 | /// 95 | Win1255 = 21, 96 | /// 97 | /// Page 22 Vietnam[Win1258] 98 | /// 99 | Win1258 = 22, 100 | /// 101 | /// Page 23 Baltic[Win1257] 102 | /// 103 | Win1257 = 23, 104 | /// 105 | /// Page 24 Azerbaijani 106 | /// 107 | Azerbaijani = 24, 108 | /// 109 | /// Thai[CP874] 110 | /// 111 | CP874 = 30, 112 | /// 113 | /// Page 25 Arabic [CP720] 114 | /// 115 | CP720 = 40, 116 | /// 117 | /// Page 26 Arabic [Win 1256] 118 | /// 119 | Win1256 = 41, 120 | /// 121 | /// Page 27 Arabic (Farsi) 122 | /// 123 | Farsi = 42, 124 | /// 125 | /// Page 30 Japanese [CP932] 126 | /// 127 | cp932 = 252, 128 | /// 129 | /// Page 31 Korean [CP949] 130 | /// 131 | CP949 = 253, 132 | /// 133 | /// Page 32 Traditional Chinese [CP950] 134 | /// 135 | CP950 = 254, 136 | /// 137 | /// Page 33 Simplified Chinese [CP936] 138 | /// 139 | CP936 = 255, 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/FontSize.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 字体大小 5 | /// 6 | public enum FontSize 7 | { 8 | /// 9 | /// 默认大小 10 | /// 11 | Size0 = 0, 12 | 13 | /// 14 | /// 1倍大小 15 | /// 16 | Size1 = 1, 17 | 18 | /// 19 | /// 2倍大小 20 | /// 21 | Size2 = 2, 22 | 23 | /// 24 | /// 3倍大小 25 | /// 26 | Size3 = 3, 27 | 28 | /// 29 | /// 4倍大小 30 | /// 31 | Size4 = 4, 32 | 33 | /// 34 | /// 5倍大小 35 | /// 36 | Size5 = 5, 37 | 38 | /// 39 | /// 6倍大小 40 | /// 41 | Size6 = 6, 42 | 43 | /// 44 | /// 7倍大小 45 | /// 46 | Size7 = 7, 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/FontType.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 字体类型 5 | /// 6 | public enum FontType 7 | { 8 | /// 9 | /// 标准 ASCII 字体(13 x 24) 中文字体(24 x 24) 10 | /// 11 | Normal = 0, 12 | /// 13 | /// 压缩 ASCII 字体(9 x 17) 中文字体(24 x 24) 14 | /// 15 | Compress0 = 1, 16 | /// 17 | /// ASCII 字体(8 x 16) 中文字体(16 x 16) 18 | /// 19 | Compress2 = 2, 20 | /// 21 | /// ASCII 字体(9 x 17) 中文字体(16 x 16) 22 | /// 23 | Compress1 = 3 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/PrintPaperType.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 打印纸类型 5 | /// 6 | public enum PrintPaperType 7 | { 8 | /// 9 | /// 纸宽58mm 10 | /// 11 | Paper58, 12 | /// 13 | /// 纸宽80mm 14 | /// 15 | Paper80 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/PrintStyle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bing.Printer.Enums 4 | { 5 | /// 6 | /// 打印样式 7 | /// 8 | [Flags] 9 | public enum PrintStyle 10 | { 11 | /// 12 | /// 无 13 | /// 14 | None = 0, 15 | /// 16 | /// 加粗 17 | /// 18 | FontB = 1, 19 | /// 20 | /// 粗体 21 | /// 22 | Bold = 1 << 3, 23 | /// 24 | /// 双倍高度 25 | /// 26 | DoubleHeight = 1 << 4, 27 | /// 28 | /// 双倍宽度 29 | /// 30 | DoubleWidth = 1 << 5, 31 | /// 32 | /// 下划线 33 | /// 34 | Underline = 1 << 7 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/PrinterModeState.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 打印模式状态 5 | /// 6 | public enum PrinterModeState 7 | { 8 | /// 9 | /// 启动 10 | /// 11 | On, 12 | /// 13 | /// 关闭 14 | /// 15 | Off 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Enums/QrCodeSize.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Enums 2 | { 3 | /// 4 | /// 二维码大小 5 | /// 6 | public enum QrCodeSize 7 | { 8 | /// 9 | /// 尺寸1 10 | /// 11 | Size0, 12 | /// 13 | /// 尺寸2 14 | /// 15 | Size1, 16 | /// 17 | /// 尺寸3 18 | /// 19 | Size2 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Extensions/PrinterExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Bing.Printer.Extensions 6 | { 7 | /// 8 | /// 打印机扩展 9 | /// 10 | public static class PrinterExtensions 11 | { 12 | /// 13 | /// 转换为字节 14 | /// 15 | public static byte ToByte(this char c) => (byte) c; 16 | 17 | /// 18 | /// 转换为字节 19 | /// 20 | public static byte ToByte(this Enum c) => (byte) Convert.ToInt16(c); 21 | 22 | /// 23 | /// 转换为字节 24 | /// 25 | public static byte ToByte(this short c) => (byte) c; 26 | 27 | /// 28 | /// 转换为字节 29 | /// 30 | public static byte ToByte(this int c) => (byte)c; 31 | 32 | /// 33 | /// 添加字节数组 34 | /// 35 | /// 字节数组 36 | /// 待添加的字节数组 37 | public static byte[] AddBytes(this byte[] bytes, byte[] addBytes) 38 | { 39 | if (addBytes == null) 40 | return bytes; 41 | var list = new List(); 42 | list.AddRange(bytes); 43 | list.AddRange(addBytes); 44 | return list.ToArray(); 45 | } 46 | 47 | /// 48 | /// 添加字节 49 | /// 50 | /// 字节数组 51 | /// 待添加的字节 52 | public static byte[] AddByte(this byte[] bytes, byte? addByte) 53 | { 54 | if (addByte == null) 55 | return bytes; 56 | var list = new List(); 57 | list.AddRange(bytes); 58 | list.Add(addByte.Value); 59 | return list.ToArray(); 60 | } 61 | 62 | /// 63 | /// 添加字节数组 64 | /// 65 | /// 字节数组 66 | /// 待添加的字符串 67 | public static byte[] AddBytes(this byte[] bytes, string value) 68 | { 69 | if (string.IsNullOrWhiteSpace(value)) 70 | return bytes; 71 | var list = new List(); 72 | list.AddRange(bytes); 73 | list.AddRange(Encoding.GetEncoding("GB18030").GetBytes(value)); 74 | return list.ToArray(); 75 | } 76 | 77 | /// 78 | /// 添加换行 79 | /// 80 | public static byte[] AddLf(this byte[] bytes) => bytes.AddBytes("\n"); 81 | 82 | /// 83 | /// 添加换行 84 | /// 85 | public static byte[] AddCrLf(this byte[] bytes) => bytes.AddBytes("\r\n"); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/IPrintCommand.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Operations; 2 | 3 | namespace Bing.Printer 4 | { 5 | /// 6 | /// 打印命令 7 | /// 8 | public interface IPrintCommand 9 | { 10 | /// 11 | /// 字体样式操作 12 | /// 13 | IFontStyle FontStyle { get; set; } 14 | 15 | /// 16 | /// 页面截断操作 17 | /// 18 | IPagerCut PagerCut { get; set; } 19 | 20 | /// 21 | /// 绘制器操作 22 | /// 23 | IDrawer Drawer { get; set; } 24 | 25 | /// 26 | /// 二维码操作 27 | /// 28 | IQrCode QrCode { get; set; } 29 | 30 | /// 31 | /// 条形码操作 32 | /// 33 | IBarcode Barcode { get; set; } 34 | 35 | /// 36 | /// 样式操作 37 | /// 38 | IStyle Style { get; set; } 39 | 40 | /// 41 | /// 初始化打印操作 42 | /// 43 | IInitializePrint InitializePrint { get; set; } 44 | 45 | /// 46 | /// 打印样式操作 47 | /// 48 | IPrintStyle PrintStyle { get; set; } 49 | 50 | /// 51 | /// 图片操作 52 | /// 53 | IImage Image { get; set; } 54 | 55 | /// 56 | /// 写入操作 57 | /// 58 | IWriter Writer { get; set; } 59 | 60 | /// 61 | /// 打印行操作 62 | /// 63 | IPrintLine PrintLine { get; set; } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/IPrintPaper.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer 2 | { 3 | /// 4 | /// 打印纸 5 | /// 6 | public interface IPrintPaper 7 | { 8 | /// 9 | /// 获取行宽度 10 | /// 11 | int GetLineWidth(); 12 | 13 | /// 14 | /// 获取一行字符串宽度 15 | /// 16 | /// 文本大小 17 | int GetLineStringWidth(int textSize); 18 | 19 | /// 20 | /// 获取最大绘制宽度 21 | /// 22 | int GetDrawableMaxWidth(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/IPrinter.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | using Bing.Printer.Operations; 3 | 4 | namespace Bing.Printer 5 | { 6 | /// 7 | /// 打印机 8 | /// 9 | public interface IPrinter 10 | { 11 | /// 12 | /// 打印纸类型 13 | /// 14 | PrintPaperType PrintPaper { get; set; } 15 | } 16 | 17 | /// 18 | /// 打印机 19 | /// 20 | /// 打印机类型 21 | public interface IPrinter : IPrinter 22 | , IWriter 23 | , IFontStyle 24 | , IPrintStyle 25 | , IPagerCut 26 | , IDrawer 27 | , IQrCode 28 | , IBarcode 29 | , IStyle 30 | , IInitializePrint 31 | , IPrintLine 32 | , IImage 33 | where TPrinter : IPrinter 34 | { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IBarcode.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | using Bing.Printer.Options; 3 | 4 | namespace Bing.Printer.Operations 5 | { 6 | /// 7 | /// 条码操作 8 | /// 9 | /// 类型 10 | public interface IBarcode 11 | { 12 | /// 13 | /// 设置 Code39 类型条形码 14 | /// 15 | /// 值 16 | /// 标签显示位置 17 | /// 宽度 18 | /// 高度 19 | /// 是否使用字体B 20 | T Code39(string value, BarcodePositionType position, BarcodeWidth width, int height, bool fontB); 21 | 22 | /// 23 | /// 设置 Code128 类型条形码 24 | /// 25 | /// 值 26 | /// 标签显示位置 27 | /// 宽度 28 | /// 高度 29 | /// 是否使用字体B 30 | T Code128(string value, BarcodePositionType position, BarcodeWidth width, int height, bool fontB); 31 | 32 | /// 33 | /// 设置 Ean13 类型条形码 34 | /// 35 | /// 值 36 | /// 标签显示位置 37 | /// 宽度 38 | /// 高度 39 | /// 是否使用字体B 40 | T Ean13(string value, BarcodePositionType position, BarcodeWidth width, int height, bool fontB); 41 | 42 | /// 43 | /// 设置条形码 44 | /// 45 | /// 值 46 | /// 条形码选项 47 | T Barcode(string value, BarcodeOptions options); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IDrawer.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Operations 2 | { 3 | /// 4 | /// 绘制器操作 5 | /// 6 | /// 类型 7 | public interface IDrawer 8 | { 9 | /// 10 | /// 打开绘制器 11 | /// 12 | T OpenDrawer(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IFontStyle.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | 3 | namespace Bing.Printer.Operations 4 | { 5 | /// 6 | /// 字体样式操作 7 | /// 8 | /// 类型 9 | public interface IFontStyle 10 | { 11 | /// 12 | /// 加粗。将文字加粗 13 | /// 14 | /// 值 15 | T Bold(string value); 16 | 17 | /// 18 | /// 加粗-开。将文字加粗 19 | /// 20 | T BoldOn(); 21 | 22 | /// 23 | /// 加粗-关。将文字加粗 24 | /// 25 | T BoldOff(); 26 | 27 | /// 28 | /// 倍宽 29 | /// 30 | /// 值 31 | T DoubleWidth(string value); 32 | 33 | /// 34 | /// 倍宽-开 35 | /// 36 | T DoubleWidthOn(); 37 | 38 | /// 39 | /// 倍宽-关 40 | /// 41 | T DoubleWidthOff(); 42 | 43 | /// 44 | /// 倍高 45 | /// 46 | /// 值 47 | T DoubleHeight(string value); 48 | 49 | /// 50 | /// 倍高-开 51 | /// 52 | T DoubleHeightOn(); 53 | 54 | /// 55 | /// 倍高-关 56 | /// 57 | T DoubleHeightOff(); 58 | 59 | /// 60 | /// 倍宽高 61 | /// 62 | /// 值 63 | T DoubleWidthHeight(string value); 64 | 65 | /// 66 | /// 倍宽高-开 67 | /// 68 | T DoubleWidthHeightOn(); 69 | 70 | /// 71 | /// 倍宽高-关 72 | /// 73 | T DoubleWidthHeightOff(); 74 | 75 | /// 76 | /// 下划线(1点宽)。为文字添加下划线 77 | /// 78 | /// 值 79 | T Underline(string value); 80 | 81 | /// 82 | /// 下划线(2点宽)。为文字添加下划线 83 | /// 84 | /// 值 85 | T Underline2(string value); 86 | 87 | /// 88 | /// 下划线(1点宽)。为文字添加下划线 89 | /// 90 | T UnderlineOn(); 91 | 92 | /// 93 | /// 下划线(2点宽)。为文字添加下划线 94 | /// 95 | T Underline2On(); 96 | 97 | /// 98 | /// 下划线。为文字添加下划线 99 | /// 100 | T UnderlineOff(); 101 | 102 | /// 103 | /// 黑白反显 104 | /// 105 | /// 值 106 | T BlackWhite(string value); 107 | 108 | /// 109 | /// 黑白反显-开 110 | /// 111 | T BlackWhiteOn(); 112 | 113 | /// 114 | /// 黑白反显-关 115 | /// 116 | T BlackWhiteOff(); 117 | 118 | /// 119 | /// 顺时针90度旋转 120 | /// 121 | /// 值 122 | T Rotate90(string value); 123 | 124 | /// 125 | /// 顺时针180度旋转 126 | /// 127 | /// 值 128 | T Rotate180(string value); 129 | 130 | /// 131 | /// 顺时针270度旋转 132 | /// 133 | /// 值 134 | T Rotate270(string value); 135 | 136 | /// 137 | /// 顺时针90度旋转-开 138 | /// 139 | T Rotate90On(); 140 | 141 | /// 142 | /// 顺时针180度旋转-开 143 | /// 144 | T Rotate180On(); 145 | 146 | /// 147 | /// 顺时针270度旋转-开 148 | /// 149 | T Rotate270On(); 150 | 151 | /// 152 | /// 顺时针旋转-关 153 | /// 154 | T RotateOff(); 155 | 156 | /// 157 | /// 设置字体大小 158 | /// 159 | /// 字体大小 160 | T FontSize(FontSize size); 161 | 162 | /// 163 | /// 设置字体大小 164 | /// 165 | /// 字体大小 166 | T FontSize(int size); 167 | 168 | /// 169 | /// 设置字体大小 170 | /// 171 | /// 宽度 172 | /// 高度 173 | T FontSize(int width, int height); 174 | 175 | /// 176 | /// 设置字体类型 177 | /// 178 | /// 字体类型 179 | T FontType(FontType type); 180 | 181 | /// 182 | /// 设置倍宽。仅支持4个级别 183 | /// 184 | /// 字体大小 185 | T DoubleWidth(FontSize size); 186 | 187 | /// 188 | /// 设置倍高。仅支持4个级别 189 | /// 190 | /// 字体大小 191 | T DoubleHeight(FontSize size); 192 | 193 | /// 194 | /// 设置字符代码页 195 | /// 196 | /// 字符代码表 197 | T FontCode(CodeTable table); 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IImage.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using System.IO; 3 | 4 | namespace Bing.Printer.Operations 5 | { 6 | /// 7 | /// 图片操作 8 | /// 9 | /// 类型 10 | public interface IImage 11 | { 12 | /// 13 | /// 打印图片 14 | /// 15 | /// 图片路径 16 | T PrintImage(string imgPath); 17 | 18 | /// 19 | /// 打印图片 20 | /// 21 | /// 流 22 | T PrintImage(Stream stream); 23 | 24 | /// 25 | /// 打印图片 26 | /// 27 | /// 字节数组 28 | T PrintImage(byte[] bytes); 29 | 30 | /// 31 | /// 打印图片 32 | /// 33 | /// 图片 34 | T PrintImage(Image image); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IInitializePrint.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Operations 2 | { 3 | /// 4 | /// 初始化打印操作 5 | /// 6 | /// 类型 7 | public interface IInitializePrint 8 | { 9 | /// 10 | /// 初始化 11 | /// 12 | T Initialize(); 13 | 14 | /// 15 | /// 启用 16 | /// 17 | T Enable(); 18 | 19 | /// 20 | /// 禁用 21 | /// 22 | T Disable(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IPagerCut.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Operations 2 | { 3 | /// 4 | /// 页面截断操作 5 | /// 6 | /// 类型 7 | public interface IPagerCut 8 | { 9 | /// 10 | /// 全页截断 11 | /// 12 | T Full(); 13 | 14 | /// 15 | /// 部分截断 16 | /// 17 | T Partial(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IPrintLine.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Operations 2 | { 3 | /// 4 | /// 打印线操作 5 | /// 6 | /// 类型 7 | public interface IPrintLine 8 | { 9 | /// 10 | /// 设置实线 11 | /// 12 | T SolidLine(); 13 | 14 | /// 15 | /// 设置空行 16 | /// 17 | T EmptyLine(); 18 | 19 | /// 20 | /// 设置虚线 21 | /// 22 | T DottedLine(); 23 | 24 | /// 25 | /// 写入一行输出 26 | /// 27 | /// 文本1 28 | /// 文本2 29 | T WriteOneLine(string text1, string text2); 30 | 31 | /// 32 | /// 写入一行输出 33 | /// 34 | /// 文本1 35 | /// 文本2 36 | /// 文字大小 37 | T WriteOneLine(string text1, string text2, int textSize); 38 | 39 | /// 40 | /// 写入一行输出 41 | /// 42 | /// 文本1 43 | /// 文本2 44 | /// 文本3 45 | T WriteOneLine(string text1, string text2, string text3); 46 | 47 | /// 48 | /// 写入一行输出 49 | /// 50 | /// 文本1 51 | /// 文本2 52 | /// 文本3 53 | /// 文字大小 54 | T WriteOneLine(string text1, string text2, string text3, int textSize); 55 | 56 | /// 57 | /// 写入一行输出 58 | /// 59 | /// 文本1 60 | /// 文本2 61 | /// 文本3 62 | /// 文本4 63 | T WriteOneLine(string text1, string text2, string text3, string text4); 64 | 65 | /// 66 | /// 写入一行输出 67 | /// 68 | /// 文本1 69 | /// 文本2 70 | /// 文本3 71 | /// 文本4 72 | /// 文字大小 73 | T WriteOneLine(string text1, string text2, string text3, string text4, int textSize); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IPrintStyle.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Operations 2 | { 3 | /// 4 | /// 打印样式操作 5 | /// 6 | /// 类型 7 | public interface IPrintStyle 8 | { 9 | /// 10 | /// 设置左边距 11 | /// 12 | /// 值 13 | T LeftMargin(int value = 0); 14 | 15 | /// 16 | /// 设置左边距 17 | /// 18 | /// 边距值 19 | /// 高度 20 | T LeftMargin(int nL, int nH); 21 | 22 | /// 23 | /// 设置打印区域宽度 24 | /// 25 | /// 长度 26 | /// 高度 27 | T PrintWidth(int nL, int nH); 28 | 29 | /// 30 | /// 设置相对横向打印位置 31 | /// 32 | /// 长度 33 | /// 高度 34 | T RelativeHorizontalPosition(int nL, int nH); 35 | 36 | /// 37 | /// 设置绝对打印位置 38 | /// 39 | /// 长度 40 | /// 高度 41 | T AbsolutePosition(int nL, int nH); 42 | 43 | /// 44 | /// 左对齐 45 | /// 46 | T Left(); 47 | 48 | /// 49 | /// 居中 50 | /// 51 | T Center(); 52 | 53 | /// 54 | /// 右对齐 55 | /// 56 | /// 57 | T Right(); 58 | 59 | /// 60 | /// 设置默认行高 61 | /// 62 | T RowHeight(); 63 | 64 | /// 65 | /// 设置行高 66 | /// 67 | /// 高度 68 | T RowHeight(int height); 69 | 70 | /// 71 | /// 设置中文字符间距 72 | /// 73 | /// 左间距 74 | /// 右间距 75 | // ReSharper disable once InconsistentNaming 76 | T SpacingCN(int left = 0, int right = 0); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IQrCode.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | 3 | namespace Bing.Printer.Operations 4 | { 5 | /// 6 | /// 二维码操作 7 | /// 8 | /// 类型 9 | public interface IQrCode 10 | { 11 | /// 12 | /// 设置二维码 13 | /// 14 | /// 值 15 | T QrCode(string value); 16 | 17 | /// 18 | /// 设置二维码 19 | /// 20 | /// 值 21 | /// 二维码大小 22 | T QrCode(string value, QrCodeSize size); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IStyle.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | 3 | namespace Bing.Printer.Operations 4 | { 5 | /// 6 | /// 样式操作 7 | /// 8 | /// 类型 9 | public interface IStyle 10 | { 11 | /// 12 | /// 设置打印样式 13 | /// 14 | /// 打印样式 15 | T Styles(PrintStyle style); 16 | 17 | /// 18 | /// 设置字符间距 19 | /// 20 | /// 空格数 21 | T RightCharacterSpacing(int spaceCount); 22 | 23 | /// 24 | /// 设置分隔符 25 | /// 26 | T Separator(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Operations/IWriter.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Operations 2 | { 3 | /// 4 | /// 写入器操作 5 | /// 6 | /// 类型 7 | public interface IWriter 8 | { 9 | /// 10 | /// 写入 11 | /// 12 | /// 字节数组 13 | T Write(byte[] value); 14 | 15 | /// 16 | /// 写入 17 | /// 18 | /// 字符串 19 | T Write(string value); 20 | 21 | /// 22 | /// 写入并换行 23 | /// 24 | /// 字符串 25 | T WriteLine(string value); 26 | 27 | /// 28 | /// 写入并换行 29 | /// 30 | /// 字节数组 31 | T WriteLine(byte[] value); 32 | 33 | /// 34 | /// 添加行 35 | /// 36 | T NewLine(); 37 | 38 | /// 39 | /// 添加行 40 | /// 41 | /// 行数 42 | T NewLine(int liens); 43 | 44 | /// 45 | /// 清空内容 46 | /// 47 | T Clear(); 48 | 49 | /// 50 | /// 获取二进制数组 51 | /// 52 | byte[] GetBytes(); 53 | 54 | /// 55 | /// 转换为十六进制 56 | /// 57 | string ToHex(); 58 | } 59 | 60 | /// 61 | /// 写入器操作 62 | /// 63 | public interface IWriter : IWriter 64 | { 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Options/BarcodeOptions.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | 3 | namespace Bing.Printer.Options 4 | { 5 | /// 6 | /// 条形码选项 7 | /// 8 | public class BarcodeOptions 9 | { 10 | /// 11 | /// 宽度 12 | /// 13 | public BarcodeWidth? Width { get; set; } 14 | 15 | /// 16 | /// 高度 17 | /// 18 | public int? Height { get; set; } 19 | 20 | /// 21 | /// 显示位置 22 | /// 23 | public BarcodePositionType? Position { get; set; } 24 | 25 | /// 26 | /// 字体类型 27 | /// 28 | public BarcodeFontType? FontType { get; set; } 29 | 30 | /// 31 | /// 条码类型 32 | /// 33 | public BarcodeType Type { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Options/PrintOptions.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Options 2 | { 3 | /// 4 | /// 打印选项 5 | /// 6 | public class PrintOptions 7 | { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Bing.Printer.Abstractions/Options/QrCodeOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Bing.Printer.Options 6 | { 7 | class QrCodeOptions 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Bing.Printer.Core/Bing.Printer.Core.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | Bing.Printer 6 | Bing.Printer.Core是Bing应用框架的热敏打印操作核心类库。 7 | Bing是一个.net core平台下的应用框架,旨在于提升小型团队的开发能力,由常用公共操作类、架构基类、第三方组件封装、第三方业务接口封装等组成。 8 | 9 | 10 | 11 | ..\..\output\release\ 12 | ..\..\output\release\netstandard2.0\Bing.Printer.Core.xml 13 | 14 | 15 | 16 | ..\..\output\release\ 17 | ..\..\output\release\netstandard2.0\Bing.Printer.Core.xml 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Bing.Printer.Core/Exceptions/PrintException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Bing.Printer.Exceptions 4 | { 5 | /// 6 | /// 打印异常 7 | /// 8 | public class PrintException : Exception 9 | { 10 | /// 11 | /// 错误码 12 | /// 13 | public string Code { get; set; } 14 | 15 | /// 16 | /// 初始化一个类型的实例 17 | /// 18 | /// 错误消息 19 | public PrintException(string message) : this(message, null) 20 | { 21 | } 22 | 23 | /// 24 | /// 初始化一个类型的实例 25 | /// 26 | /// 异常 27 | public PrintException(Exception exception) : this(null, null, exception) 28 | { 29 | } 30 | 31 | /// 32 | /// 初始化一个类型的实例 33 | /// 34 | /// 错误消息 35 | /// 错误码 36 | public PrintException(string message, string code) : this(message, code, null) 37 | { 38 | } 39 | 40 | /// 41 | /// 初始化一个类型的实例 42 | /// 43 | /// 错误消息 44 | /// 错误码 45 | /// 异常 46 | public PrintException(string message, string code, Exception exception):base(message??"",exception) 47 | { 48 | Code = code; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Bing.Printer.Core/Extensions/PrinterExtensions.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | 3 | namespace Bing.Printer.Extensions 4 | { 5 | /// 6 | /// 打印机扩展 7 | /// 8 | public static class PrinterExtensions 9 | { 10 | /// 11 | /// 设置 Code39 类型条码 12 | /// 13 | /// 打印机类型 14 | /// 打印机 15 | /// 值 16 | public static TPrinter Code39(this TPrinter printer, string value) where TPrinter : IPrinter 17 | { 18 | return printer.Code39(value, BarcodePositionType.None, BarcodeWidth.Default, 100, true); 19 | } 20 | 21 | /// 22 | /// 设置 Code128 类型条码 23 | /// 24 | /// 打印机类型 25 | /// 打印机 26 | /// 值 27 | public static TPrinter Code128(this TPrinter printer,string value) where TPrinter : IPrinter 28 | { 29 | return printer.Code128(value, BarcodePositionType.None, BarcodeWidth.Default, 100, true); 30 | } 31 | 32 | /// 33 | /// 设置 Ean13 类型条码 34 | /// 35 | /// 打印机类型 36 | /// 打印机 37 | /// 值 38 | public static TPrinter Ean13(this TPrinter printer, string value) where TPrinter : IPrinter 39 | { 40 | return printer.Ean13(value, BarcodePositionType.None, BarcodeWidth.Default, 100, true); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Bing.Printer.Core/Factories/PrintPaperFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using Bing.Printer.Enums; 5 | using Bing.Printer.Pagers; 6 | 7 | namespace Bing.Printer.Factories 8 | { 9 | /// 10 | /// 打印纸工厂 11 | /// 12 | public static class PrintPaperFactory 13 | { 14 | /// 15 | /// 打印纸字典 16 | /// 17 | private static readonly IDictionary PrintPaperDict = 18 | new ConcurrentDictionary(); 19 | 20 | /// 21 | /// 创建打印纸 22 | /// 23 | /// 打印纸类型 24 | private static IPrintPaper Create(PrintPaperType type) 25 | { 26 | switch (type) 27 | { 28 | case PrintPaperType.Paper58: 29 | return new PrintPaper58mm(); 30 | case PrintPaperType.Paper80: 31 | return new PrintPaper80mm(); 32 | default: 33 | throw new NotImplementedException($"尚未实现指定 {type} 类型的打印纸"); 34 | } 35 | } 36 | 37 | /// 38 | /// 获取或创建打印纸 39 | /// 40 | /// 打印纸类型 41 | public static IPrintPaper GetOrCreate(PrintPaperType type) 42 | { 43 | if (PrintPaperDict.ContainsKey(type)) 44 | return PrintPaperDict[type]; 45 | PrintPaperDict[type] = Create(type); 46 | return PrintPaperDict[type]; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Bing.Printer.Core/Pagers/PrintPaper58mm.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Pagers 2 | { 3 | /// 4 | /// 58mm 打印纸 5 | /// 6 | internal class PrintPaper58mm:IPrintPaper 7 | { 8 | public int GetLineWidth() => 16; 9 | 10 | public int GetLineStringWidth(int textSize) 11 | { 12 | switch (textSize) 13 | { 14 | case 0: 15 | return 31; 16 | case 1: 17 | return 15; 18 | case 2: 19 | return 60; 20 | default: 21 | return 31; 22 | } 23 | } 24 | 25 | public int GetDrawableMaxWidth() => 300; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Bing.Printer.Core/Pagers/PrintPaper80mm.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.Pagers 2 | { 3 | /// 4 | /// 80mm 打印纸 5 | /// 6 | internal class PrintPaper80mm:IPrintPaper 7 | { 8 | public int GetLineWidth() => 24; 9 | 10 | public int GetLineStringWidth(int textSize) 11 | { 12 | switch (textSize) 13 | { 14 | case 0: 15 | return 47; 16 | case 1: 17 | return 23; 18 | case 2: 19 | return 72; 20 | default: 21 | return 47; 22 | } 23 | } 24 | 25 | public int GetDrawableMaxWidth() => 500; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Bing.Printer.Core/PrinterBase.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using System.IO; 3 | using Bing.Printer.Enums; 4 | using Bing.Printer.Options; 5 | 6 | namespace Bing.Printer 7 | { 8 | /// 9 | /// 打印机基类 10 | /// 11 | /// 打印机类型 12 | public abstract class PrinterBase : IPrinter where TPrinter : IPrinter 13 | { 14 | /// 15 | /// 打印命令 16 | /// 17 | private IPrintCommand _command; 18 | 19 | /// 20 | /// 打印命令 21 | /// 22 | protected IPrintCommand Command => _command ?? (_command = CreatePrintCommand()); 23 | 24 | /// 25 | /// 打印纸类型 26 | /// 27 | public PrintPaperType PrintPaper { get; set; } = PrintPaperType.Paper80; 28 | 29 | #region Writer(写入器操作) 30 | 31 | /// 32 | /// 写入 33 | /// 34 | /// 字节数组 35 | public virtual TPrinter Write(byte[] value) 36 | { 37 | Command.Writer.Write(value); 38 | return This(); 39 | } 40 | 41 | /// 42 | /// 写入 43 | /// 44 | /// 字符串 45 | public virtual TPrinter Write(string value) 46 | { 47 | Command.Writer.Write(value); 48 | return This(); 49 | } 50 | 51 | /// 52 | /// 写入并换行 53 | /// 54 | /// 字符串 55 | public TPrinter WriteLine(string value) 56 | { 57 | Command.Writer.WriteLine(value); 58 | return This(); 59 | } 60 | 61 | /// 62 | /// 写入并换行 63 | /// 64 | /// 字节数组 65 | public TPrinter WriteLine(byte[] value) 66 | { 67 | Command.Writer.WriteLine(value); 68 | return This(); 69 | } 70 | 71 | /// 72 | /// 添加行 73 | /// 74 | public virtual TPrinter NewLine() 75 | { 76 | Command.Writer.NewLine(); 77 | return This(); 78 | } 79 | 80 | /// 81 | /// 添加行 82 | /// 83 | /// 行数 84 | public virtual TPrinter NewLine(int liens) 85 | { 86 | Command.Writer.NewLine(liens); 87 | return This(); 88 | } 89 | 90 | /// 91 | /// 清空 92 | /// 93 | public virtual TPrinter Clear() 94 | { 95 | Command.Writer.Clear(); 96 | return This(); 97 | } 98 | 99 | /// 100 | /// 获取二进制数组 101 | /// 102 | public virtual byte[] GetBytes() => Command.Writer.GetBytes(); 103 | 104 | /// 105 | /// 转换成十六进制字符串 106 | /// 107 | public virtual string ToHex() => Command.Writer.ToHex(); 108 | 109 | /// 110 | /// 创建打印命令 111 | /// 112 | /// 113 | protected abstract IPrintCommand CreatePrintCommand(); 114 | 115 | /// 116 | /// 返回自身 117 | /// 118 | private TPrinter This() => (TPrinter)(object)this; 119 | 120 | #endregion 121 | 122 | #region FontStyle(字体样式) 123 | 124 | /// 125 | /// 加粗。将文字加粗 126 | /// 127 | /// 值 128 | public virtual TPrinter Bold(string value) => Write(Command.FontStyle.Bold(value)); 129 | 130 | /// 131 | /// 加粗-开。将文字加粗 132 | /// 133 | public virtual TPrinter BoldOn() => Write(Command.FontStyle.BoldOn()); 134 | 135 | /// 136 | /// 加粗-关。将文字加粗 137 | /// 138 | public virtual TPrinter BoldOff() => Write(Command.FontStyle.BoldOff()); 139 | 140 | /// 141 | /// 倍宽 142 | /// 143 | /// 值 144 | public virtual TPrinter DoubleWidth(string value) => Write(Command.FontStyle.DoubleWidth(value)); 145 | 146 | /// 147 | /// 倍宽-开 148 | /// 149 | public virtual TPrinter DoubleWidthOn() => Write(Command.FontStyle.DoubleWidthOn()); 150 | 151 | /// 152 | /// 倍宽-关 153 | /// 154 | public virtual TPrinter DoubleWidthOff() => Write(Command.FontStyle.DoubleWidthOff()); 155 | 156 | /// 157 | /// 倍高 158 | /// 159 | /// 值 160 | public virtual TPrinter DoubleHeight(string value) => Write(Command.FontStyle.DoubleHeight(value)); 161 | 162 | /// 163 | /// 倍高-开 164 | /// 165 | public virtual TPrinter DoubleHeightOn() => Write(Command.FontStyle.DoubleHeightOn()); 166 | 167 | /// 168 | /// 倍高-关 169 | /// 170 | public virtual TPrinter DoubleHeightOff() => Write(Command.FontStyle.DoubleHeightOff()); 171 | 172 | /// 173 | /// 倍宽高 174 | /// 175 | /// 值 176 | public TPrinter DoubleWidthHeight(string value) => Write(Command.FontStyle.DoubleWidthHeight(value)); 177 | 178 | /// 179 | /// 倍宽高-开 180 | /// 181 | public virtual TPrinter DoubleWidthHeightOn() => Write(Command.FontStyle.DoubleWidthHeightOn()); 182 | 183 | /// 184 | /// 倍宽高-关 185 | /// 186 | public virtual TPrinter DoubleWidthHeightOff() => Write(Command.FontStyle.DoubleWidthHeightOff()); 187 | 188 | /// 189 | /// 下划线(1点宽)。为文字添加下划线 190 | /// 191 | /// 值 192 | public virtual TPrinter Underline(string value) => Write(Command.FontStyle.Underline(value)); 193 | 194 | /// 195 | /// 下划线(2点宽)。为文字添加下划线 196 | /// 197 | /// 值 198 | public virtual TPrinter Underline2(string value) => Write(Command.FontStyle.Underline2(value)); 199 | 200 | /// 201 | /// 下划线(1点宽)。为文字添加下划线 202 | /// 203 | public virtual TPrinter UnderlineOn() => Write(Command.FontStyle.UnderlineOn()); 204 | 205 | /// 206 | /// 下划线(2点宽)。为文字添加下划线 207 | /// 208 | public virtual TPrinter Underline2On() => Write(Command.FontStyle.Underline2On()); 209 | 210 | /// 211 | /// 下划线。为文字添加下划线 212 | /// 213 | public virtual TPrinter UnderlineOff() => Write(Command.FontStyle.UnderlineOff()); 214 | 215 | /// 216 | /// 黑白反显 217 | /// 218 | /// 值 219 | public virtual TPrinter BlackWhite(string value) => Write(Command.FontStyle.BlackWhite(value)); 220 | 221 | /// 222 | /// 黑白反显-开 223 | /// 224 | public virtual TPrinter BlackWhiteOn() => Write(Command.FontStyle.BlackWhiteOn()); 225 | 226 | /// 227 | /// 黑白反显-关 228 | /// 229 | public virtual TPrinter BlackWhiteOff() => Write(Command.FontStyle.BlackWhiteOff()); 230 | 231 | /// 232 | /// 顺时针90度旋转 233 | /// 234 | /// 值 235 | public virtual TPrinter Rotate90(string value) => Write(Command.FontStyle.Rotate90(value)); 236 | 237 | /// 238 | /// 顺时针180度旋转 239 | /// 240 | /// 值 241 | public virtual TPrinter Rotate180(string value) => Write(Command.FontStyle.Rotate180(value)); 242 | 243 | /// 244 | /// 顺时针270度旋转 245 | /// 246 | /// 值 247 | public virtual TPrinter Rotate270(string value) => Write(Command.FontStyle.Rotate270(value)); 248 | 249 | /// 250 | /// 顺时针90度旋转-开 251 | /// 252 | public virtual TPrinter Rotate90On() => Write(Command.FontStyle.Rotate90On()); 253 | 254 | /// 255 | /// 顺时针180度旋转-开 256 | /// 257 | public virtual TPrinter Rotate180On() => Write(Command.FontStyle.Rotate180On()); 258 | 259 | /// 260 | /// 顺时针270度旋转-开 261 | /// 262 | public virtual TPrinter Rotate270On() => Write(Command.FontStyle.Rotate270On()); 263 | 264 | /// 265 | /// 顺时针旋转-关 266 | /// 267 | public virtual TPrinter RotateOff() => Write(Command.FontStyle.RotateOff()); 268 | 269 | /// 270 | /// 设置字体大小 271 | /// 272 | /// 字体大小 273 | public virtual TPrinter FontSize(FontSize size) => Write(Command.FontStyle.FontSize(size)); 274 | 275 | /// 276 | /// 设置字体大小 277 | /// 278 | /// 字体大小 279 | public virtual TPrinter FontSize(int size) => Write(Command.FontStyle.FontSize(size)); 280 | 281 | /// 282 | /// 设置字体大小 283 | /// 284 | /// 宽度 285 | /// 高度 286 | public virtual TPrinter FontSize(int width, int height) => Write(Command.FontStyle.FontSize(width, height)); 287 | 288 | /// 289 | /// 设置字体类型 290 | /// 291 | /// 字体类型 292 | public virtual TPrinter FontType(FontType type) => Write(Command.FontStyle.FontType(type)); 293 | 294 | /// 295 | /// 设置倍宽。仅支持4个级别 296 | /// 297 | /// 字体大小 298 | public virtual TPrinter DoubleWidth(FontSize size) => Write(Command.FontStyle.DoubleWidth(size)); 299 | 300 | /// 301 | /// 设置倍高。仅支持4个级别 302 | /// 303 | /// 字体大小 304 | public virtual TPrinter DoubleHeight(FontSize size) => Write(Command.FontStyle.DoubleHeight(size)); 305 | 306 | /// 307 | /// 设置字符代码页 308 | /// 309 | /// 字符代码表 310 | public virtual TPrinter FontCode(CodeTable table) => Write(Command.FontStyle.FontCode(table)); 311 | 312 | #endregion 313 | 314 | #region PrintStyle(打印样式) 315 | 316 | /// 317 | /// 设置左边距 318 | /// 319 | /// 值 320 | public virtual TPrinter LeftMargin(int value = 0) => Write(Command.PrintStyle.LeftMargin(value)); 321 | 322 | /// 323 | /// 设置左边距 324 | /// 325 | /// 边距值 326 | /// 高度 327 | public virtual TPrinter LeftMargin(int nL, int nH) => Write(Command.PrintStyle.LeftMargin(nL, nH)); 328 | 329 | /// 330 | /// 设置打印区域宽度 331 | /// 332 | /// 长度 333 | /// 高度 334 | public TPrinter PrintWidth(int nL, int nH) => Write(Command.PrintStyle.PrintWidth(nL, nH)); 335 | 336 | /// 337 | /// 设置相对横向打印位置 338 | /// 339 | /// 长度 340 | /// 高度 341 | public TPrinter RelativeHorizontalPosition(int nL, int nH) => Write(Command.PrintStyle.PrintWidth(nL, nH)); 342 | 343 | /// 344 | /// 设置绝对打印位置 345 | /// 346 | /// 长度 347 | /// 高度 348 | public TPrinter AbsolutePosition(int nL, int nH) => Write(Command.PrintStyle.PrintWidth(nL, nH)); 349 | 350 | /// 351 | /// 左对齐 352 | /// 353 | public virtual TPrinter Left() => Write(Command.PrintStyle.Left()); 354 | 355 | /// 356 | /// 右对齐 357 | /// 358 | public virtual TPrinter Right() => Write(Command.PrintStyle.Right()); 359 | 360 | /// 361 | /// 设置默认行高 362 | /// 363 | public virtual TPrinter RowHeight() => Write(Command.PrintStyle.RowHeight()); 364 | 365 | /// 366 | /// 设置行高 367 | /// 368 | /// 高度 369 | public virtual TPrinter RowHeight(int height) => Write(Command.PrintStyle.RowHeight(height)); 370 | 371 | /// 372 | /// 设置中文字符间距 373 | /// 374 | /// 左间距 375 | /// 右间距 376 | // ReSharper disable once InconsistentNaming 377 | public virtual TPrinter SpacingCN(int left = 0, int right = 0) => Write(Command.PrintStyle.SpacingCN(left, right)); 378 | 379 | /// 380 | /// 居中 381 | /// 382 | public virtual TPrinter Center() => Write(Command.PrintStyle.Center()); 383 | 384 | #endregion 385 | 386 | #region PagerCut(页面截断) 387 | 388 | /// 389 | /// 全页截断 390 | /// 391 | public virtual TPrinter Full() => Write(Command.PagerCut.Full()); 392 | 393 | /// 394 | /// 部分截断 395 | /// 396 | public virtual TPrinter Partial() => Write(Command.PagerCut.Partial()); 397 | 398 | #endregion 399 | 400 | #region Drawer(绘制器) 401 | 402 | /// 403 | /// 打开绘制器 404 | /// 405 | public virtual TPrinter OpenDrawer() => Write(Command.Drawer.OpenDrawer()); 406 | 407 | #endregion 408 | 409 | #region QrCode(二维码) 410 | 411 | /// 412 | /// 设置二维码 413 | /// 414 | /// 值 415 | public virtual TPrinter QrCode(string value) => Write(Command.QrCode.QrCode(value)); 416 | 417 | /// 418 | /// 设置二维码 419 | /// 420 | /// 值 421 | /// 二维码大小 422 | public virtual TPrinter QrCode(string value, QrCodeSize size) => Write(Command.QrCode.QrCode(value, size)); 423 | 424 | #endregion 425 | 426 | #region Barcode(条形码) 427 | 428 | /// 429 | /// 设置 Code39 类型条形码 430 | /// 431 | /// 值 432 | /// 标签显示位置 433 | /// 宽度 434 | /// 高度 435 | /// 是否使用字体B 436 | public TPrinter 437 | Code39(string value, BarcodePositionType position, BarcodeWidth width, int height, bool fontB) => 438 | Write(Command.Barcode.Code39(value, position, width, height, fontB)); 439 | 440 | /// 441 | /// 设置 Code128 类型条形码 442 | /// 443 | /// 值 444 | /// 标签显示位置 445 | /// 宽度 446 | /// 高度 447 | /// 是否使用字体B 448 | public TPrinter Code128(string value, BarcodePositionType position, BarcodeWidth width, int height, 449 | bool fontB) => 450 | Write(Command.Barcode.Code128(value, position, width, height, fontB)); 451 | 452 | /// 453 | /// 设置 Ean13 类型条形码 454 | /// 455 | /// 值 456 | /// 标签显示位置 457 | /// 宽度 458 | /// 高度 459 | /// 是否使用字体B 460 | public TPrinter Ean13(string value, BarcodePositionType position, BarcodeWidth width, int height, bool fontB) => 461 | Write(Command.Barcode.Ean13(value, position, width, height, fontB)); 462 | 463 | /// 464 | /// 设置条形码 465 | /// 466 | /// 值 467 | /// 条形码选项 468 | public TPrinter Barcode(string value, BarcodeOptions options) => Write(Command.Barcode.Barcode(value, options)); 469 | 470 | #endregion 471 | 472 | #region Style(样式) 473 | 474 | /// 475 | /// 设置打印样式 476 | /// 477 | /// 打印样式 478 | public TPrinter Styles(PrintStyle style) => Write(Command.Style.Styles(style)); 479 | 480 | /// 481 | /// 设置字符间距 482 | /// 483 | /// 空格数 484 | public TPrinter RightCharacterSpacing(int spaceCount) => Write(Command.Style.RightCharacterSpacing(spaceCount)); 485 | 486 | /// 487 | /// 设置分隔符 488 | /// 489 | public virtual TPrinter Separator() 490 | { 491 | FontType(Enums.FontType.Compress0); 492 | Write(Command.Style.Separator()); 493 | FontType(Enums.FontType.Normal); 494 | NewLine(); 495 | return This(); 496 | } 497 | 498 | #endregion 499 | 500 | #region InitializePrint(初始化打印) 501 | 502 | /// 503 | /// 初始化 504 | /// 505 | public TPrinter Initialize() => Write(Command.InitializePrint.Initialize()); 506 | 507 | /// 508 | /// 启用 509 | /// 510 | public TPrinter Enable() => Write(Command.InitializePrint.Enable()); 511 | 512 | /// 513 | /// 禁用 514 | /// 515 | public TPrinter Disable() => Write(Command.InitializePrint.Disable()); 516 | 517 | #endregion 518 | 519 | #region PrintLine(打印行) 520 | 521 | /// 522 | /// 设置实线 523 | /// 524 | public virtual TPrinter SolidLine() => Write(Command.PrintLine.SolidLine()); 525 | 526 | /// 527 | /// 设置空行 528 | /// 529 | public virtual TPrinter EmptyLine() => Write(Command.PrintLine.EmptyLine()); 530 | 531 | /// 532 | /// 设置虚线 533 | /// 534 | public virtual TPrinter DottedLine() => Write(Command.PrintLine.DottedLine()); 535 | 536 | /// 537 | /// 写入一行输出 538 | /// 539 | /// 文本1 540 | /// 文本2 541 | public virtual TPrinter WriteOneLine(string text1, string text2) => Write(Command.PrintLine.WriteOneLine(text1, text2)); 542 | 543 | /// 544 | /// 写入一行输出 545 | /// 546 | /// 文本1 547 | /// 文本2 548 | /// 文字大小 549 | public virtual TPrinter WriteOneLine(string text1, string text2, int textSize) => Write(Command.PrintLine.WriteOneLine(text1, text2, textSize)); 550 | 551 | /// 552 | /// 写入一行输出 553 | /// 554 | /// 文本1 555 | /// 文本2 556 | /// 文本3 557 | public virtual TPrinter WriteOneLine(string text1, string text2, string text3) => Write(Command.PrintLine.WriteOneLine(text1, text2, text3)); 558 | 559 | /// 560 | /// 写入一行输出 561 | /// 562 | /// 文本1 563 | /// 文本2 564 | /// 文本3 565 | /// 文字大小 566 | public virtual TPrinter WriteOneLine(string text1, string text2, string text3, int textSize) => Write(Command.PrintLine.WriteOneLine(text1, text2, text3, textSize)); 567 | 568 | /// 569 | /// 写入一行输出 570 | /// 571 | /// 文本1 572 | /// 文本2 573 | /// 文本3 574 | /// 文本4 575 | public virtual TPrinter WriteOneLine(string text1, string text2, string text3, string text4) => Write(Command.PrintLine.WriteOneLine(text1, text2, text3, text4)); 576 | 577 | /// 578 | /// 写入一行输出 579 | /// 580 | /// 文本1 581 | /// 文本2 582 | /// 文本3 583 | /// 文本4 584 | /// 文字大小 585 | public virtual TPrinter WriteOneLine(string text1, string text2, string text3, string text4, int textSize) => Write(Command.PrintLine.WriteOneLine(text1, text2, text3, text4, textSize)); 586 | 587 | #endregion 588 | 589 | #region Image(图片) 590 | 591 | /// 592 | /// 打印图片 593 | /// 594 | /// 图片路径 595 | public virtual TPrinter PrintImage(string imgPath) => Write(Command.Image.PrintImage(imgPath)); 596 | 597 | /// 598 | /// 打印图片 599 | /// 600 | /// 流 601 | public virtual TPrinter PrintImage(Stream stream) => Write(Command.Image.PrintImage(stream)); 602 | 603 | /// 604 | /// 打印图片 605 | /// 606 | /// 字节数组 607 | public virtual TPrinter PrintImage(byte[] bytes) => Write(Command.Image.PrintImage(bytes)); 608 | 609 | /// 610 | /// 打印图片 611 | /// 612 | /// 图片 613 | public virtual TPrinter PrintImage(Image image) => Write(Command.Image.PrintImage(image)); 614 | 615 | #endregion 616 | 617 | } 618 | } 619 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/ASCIIControlConst.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.EscPos 2 | { 3 | /// 4 | /// ASCII控制常量 5 | /// 6 | // ReSharper disable once InconsistentNaming 7 | internal static class ASCIIControlConst 8 | { 9 | /// 10 | /// 空字符(Null)。 11 | /// 二进制 : 0000 0000; 12 | /// 十进制 : 0; 13 | /// 十六进制 : 0x00; 14 | /// 15 | // ReSharper disable once InconsistentNaming 16 | public const byte NULL = 0x00; 17 | 18 | /// 19 | /// 标题开始。 20 | /// 二进制 : 0000 0001; 21 | /// 十进制 : 1; 22 | /// 十六进制 : 0x01; 23 | /// 24 | // ReSharper disable once InconsistentNaming 25 | public const byte SOH = 0x01; 26 | 27 | /// 28 | /// 本文开始。 29 | /// 二进制 : 0000 0010; 30 | /// 十进制 : 2; 31 | /// 十六进制 : 0x02; 32 | /// 33 | // ReSharper disable once InconsistentNaming 34 | public const byte STX = 0x02; 35 | 36 | /// 37 | /// 本文结束。 38 | /// 二进制 : 0000 0011; 39 | /// 十进制 : 3; 40 | /// 十六进制 : 0x03; 41 | /// 42 | // ReSharper disable once InconsistentNaming 43 | public const byte ETX = 0x03; 44 | 45 | /// 46 | /// 传输结束。 47 | /// 二进制 : 0000 0100; 48 | /// 十进制 : 4; 49 | /// 十六进制 : 0x04; 50 | /// 51 | // ReSharper disable once InconsistentNaming 52 | public const byte EOT = 0x04; 53 | 54 | /// 55 | /// 请求。 56 | /// 二进制 : 0000 0101; 57 | /// 十进制 : 5; 58 | /// 十六进制 : 0x05; 59 | /// 60 | // ReSharper disable once InconsistentNaming 61 | public const byte ENQ = 0x05; 62 | 63 | /// 64 | /// 确认回应。 65 | /// 二进制 : 0000 0110; 66 | /// 十进制 : 6; 67 | /// 十六进制 : 0x06; 68 | /// 69 | // ReSharper disable once InconsistentNaming 70 | public const byte ACK = 0x06; 71 | 72 | /// 73 | /// 响铃。 74 | /// 二进制 : 0000 0111; 75 | /// 十进制 : 7; 76 | /// 十六进制 : 0x07; 77 | /// 78 | // ReSharper disable once InconsistentNaming 79 | public const byte BEL = 0x07; 80 | 81 | /// 82 | /// 退格。 83 | /// 二进制 : 0000 1000; 84 | /// 十进制 : 8; 85 | /// 十六进制 : 0x08; 86 | /// 87 | // ReSharper disable once InconsistentNaming 88 | public const byte BS = 0x08; 89 | 90 | /// 91 | /// 水平定位符号。 92 | /// 二进制 : 0000 1001; 93 | /// 十进制 : 9; 94 | /// 十六进制 : 0x09; 95 | /// 96 | // ReSharper disable once InconsistentNaming 97 | public const byte HT = 0x09; 98 | 99 | /// 100 | /// 换行键。 101 | /// 二进制 : 0000 1010; 102 | /// 十进制 : 10; 103 | /// 十六进制 : 0x0A; 104 | /// 105 | // ReSharper disable once InconsistentNaming 106 | public const byte LF = 0x0A; 107 | 108 | /// 109 | /// 垂直定位符号。 110 | /// 二进制 : 0000 1011; 111 | /// 十进制 : 11; 112 | /// 十六进制 : 0x0B; 113 | /// 114 | // ReSharper disable once InconsistentNaming 115 | public const byte VT = 0x0B; 116 | 117 | /// 118 | /// 换页键。 119 | /// 二进制 : 0000 1100; 120 | /// 十进制 : 12; 121 | /// 十六进制 : 0x0C; 122 | /// 123 | // ReSharper disable once InconsistentNaming 124 | public const byte FF = 0x0C; 125 | 126 | /// 127 | /// 归位键。 128 | /// 二进制 : 0000 1101; 129 | /// 十进制 : 13; 130 | /// 十六进制 : 0x0D; 131 | /// 132 | // ReSharper disable once InconsistentNaming 133 | public const byte CR = 0x0D; 134 | 135 | /// 136 | /// 取消变换(Shift out)。 137 | /// 二进制 : 0000 1110; 138 | /// 十进制 : 14; 139 | /// 十六进制 : 0x0E; 140 | /// 141 | // ReSharper disable once InconsistentNaming 142 | public const byte SO = 0x0E; 143 | 144 | /// 145 | /// 启用变换(Shift In)。 146 | /// 二进制 : 0000 1111; 147 | /// 十进制 : 15; 148 | /// 十六进制 : 0x0F; 149 | /// 150 | // ReSharper disable once InconsistentNaming 151 | public const byte SI = 0x0F; 152 | 153 | /// 154 | /// 跳出数据通讯。 155 | /// 二进制 : 0001 0000; 156 | /// 十进制 : 16; 157 | /// 十六进制 : 0x10; 158 | /// 159 | // ReSharper disable once InconsistentNaming 160 | public const byte DLE = 0x10; 161 | 162 | /// 163 | /// 设备控制一(XON 启用软件速度控制)。 164 | /// 二进制 : 0001 0001; 165 | /// 十进制 : 17; 166 | /// 十六进制 : 0x11; 167 | /// 168 | // ReSharper disable once InconsistentNaming 169 | public const byte DC1 = 0x11; 170 | 171 | /// 172 | /// 设备控制二。 173 | /// 二进制 : 0001 0010; 174 | /// 十进制 : 18; 175 | /// 十六进制 : 0x12; 176 | /// 177 | // ReSharper disable once InconsistentNaming 178 | public const byte DC2 = 0x12; 179 | 180 | /// 181 | /// 设备控制三(XOFF 停用软件速度控制)。 182 | /// 二进制 : 0001 0011; 183 | /// 十进制 : 19; 184 | /// 十六进制 : 0x13; 185 | /// 186 | // ReSharper disable once InconsistentNaming 187 | public const byte DC3 = 0x13; 188 | 189 | /// 190 | /// 设备控制四。 191 | /// 二进制 : 0001 0100; 192 | /// 十进制 : 20; 193 | /// 十六进制 : 0x14; 194 | /// 195 | // ReSharper disable once InconsistentNaming 196 | public const byte DC4 = 0x14; 197 | 198 | /// 199 | /// 确认失败回应。 200 | /// 二进制 : 0001 0101; 201 | /// 十进制 : 21; 202 | /// 十六进制 : 0x15; 203 | /// 204 | // ReSharper disable once InconsistentNaming 205 | public const byte NAK = 0x15; 206 | 207 | /// 208 | /// 同步用暂停。 209 | /// 二进制 : 0001 0110; 210 | /// 十进制 : 22; 211 | /// 十六进制 : 0x16; 212 | /// 213 | // ReSharper disable once InconsistentNaming 214 | public const byte SYN = 0x16; 215 | 216 | /// 217 | /// 区块传输结束。 218 | /// 二进制 : 0001 0111; 219 | /// 十进制 : 23; 220 | /// 十六进制 : 0x17; 221 | /// 222 | // ReSharper disable once InconsistentNaming 223 | public const byte ETB = 0x17; 224 | 225 | /// 226 | /// 取消。 227 | /// 二进制 : 0001 1000; 228 | /// 十进制 : 24; 229 | /// 十六进制 : 0x18; 230 | /// 231 | // ReSharper disable once InconsistentNaming 232 | public const byte CAN = 0x18; 233 | 234 | /// 235 | /// 连接介质中断。 236 | /// 二进制 : 0001 1001; 237 | /// 十进制 : 25; 238 | /// 十六进制 : 0x19; 239 | /// 240 | // ReSharper disable once InconsistentNaming 241 | public const byte EM = 0x19; 242 | 243 | /// 244 | /// 替换。 245 | /// 二进制 : 0001 1010; 246 | /// 十进制 : 26; 247 | /// 十六进制 : 0x1A; 248 | /// 249 | // ReSharper disable once InconsistentNaming 250 | public const byte SUB = 0x1A; 251 | 252 | /// 253 | /// 跳出。 254 | /// 二进制 : 0001 1011; 255 | /// 十进制 : 27; 256 | /// 十六进制 : 0x1B; 257 | /// 258 | // ReSharper disable once InconsistentNaming 259 | public const byte ESC = 0x1B; 260 | 261 | /// 262 | /// 文件分分割符。 263 | /// 二进制 : 0001 1100; 264 | /// 十进制 : 28; 265 | /// 十六进制 : 0x1C; 266 | /// 267 | // ReSharper disable once InconsistentNaming 268 | public const byte FS = 0x1C; 269 | 270 | /// 271 | /// 组群分隔符。 272 | /// 二进制 : 0001 1101; 273 | /// 十进制 : 29; 274 | /// 十六进制 : 0x1D; 275 | /// 276 | // ReSharper disable once InconsistentNaming 277 | public const byte GS = 0x1D; 278 | 279 | /// 280 | /// 记录分隔符。 281 | /// 二进制 : 0001 1110; 282 | /// 十进制 : 30; 283 | /// 十六进制 : 0x1E; 284 | /// 285 | // ReSharper disable once InconsistentNaming 286 | public const byte RS = 0x1E; 287 | 288 | /// 289 | /// 单元分隔符。 290 | /// 二进制 : 0001 1111; 291 | /// 十进制 : 31; 292 | /// 十六进制 : 0x1F; 293 | /// 294 | // ReSharper disable once InconsistentNaming 295 | public const byte US = 0x1F; 296 | 297 | /// 298 | /// 删除。 299 | /// 二进制 : 0111 1111; 300 | /// 十进制 : 127; 301 | /// 十六进制 : 0x7F; 302 | /// 303 | // ReSharper disable once InconsistentNaming 304 | public const byte DEL = 0x7F; 305 | 306 | } 307 | } 308 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/ASCIIShowConst.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.EscPos 2 | { 3 | /// 4 | /// ASCII可显示字符常量 5 | /// 6 | // ReSharper disable once InconsistentNaming 7 | internal static class ASCIIShowConst 8 | { 9 | /// 10 | /// 空格。 11 | /// 显示图形 : " "; 12 | /// 二进制 : 0010 0000; 13 | /// 十进制 : 32; 14 | /// 十六进制 : 0x20; 15 | /// 16 | public const byte Space = 0x20; 17 | 18 | /// 19 | /// 叹号。 20 | /// 显示图形 : !; 21 | /// 二进制 : 0010 0001; 22 | /// 十进制 : 33; 23 | /// 十六进制 : 0x21; 24 | /// 25 | public const byte Bang = 0x21; 26 | 27 | /// 28 | /// 双引号。 29 | /// 显示图形 : "; 30 | /// 二进制 : 0010 0010; 31 | /// 十进制 : 34; 32 | /// 十六进制 : 0x22; 33 | /// 34 | public const byte DoubleQuote = 0x22; 35 | 36 | /// 37 | /// 井号。 38 | /// 显示图形 : #; 39 | /// 二进制 : 0010 0011; 40 | /// 十进制 : 35; 41 | /// 十六进制 : 0x23; 42 | /// 43 | public const byte Sharp = 0x23; 44 | 45 | /// 46 | /// 美元符号。 47 | /// 显示图形 : $; 48 | /// 二进制 : 0010 0100; 49 | /// 十进制 : 36; 50 | /// 十六进制 : 0x24; 51 | /// 52 | public const byte DollarSign = 0x24; 53 | 54 | /// 55 | /// 百分号。 56 | /// 显示图形 : %; 57 | /// 二进制 : 0010 0101; 58 | /// 十进制 : 37; 59 | /// 十六进制 : 0x25; 60 | /// 61 | public const byte Mod = 0x25; 62 | 63 | /// 64 | /// 和。 65 | /// 显示图形 : &; 66 | /// 二进制 : 0010 0110; 67 | /// 十进制 : 38; 68 | /// 十六进制 : 0x26; 69 | /// 70 | public const byte And = 0x26; 71 | 72 | /// 73 | /// 单引号。 74 | /// 显示图形 : '; 75 | /// 二进制 : 0010 0111; 76 | /// 十进制 : 39; 77 | /// 十六进制 : 0x27; 78 | /// 79 | public const byte SingleQuote= 0x27; 80 | 81 | /// 82 | /// 左小括号。 83 | /// 显示图形 : (; 84 | /// 二进制 : 0010 1000; 85 | /// 十进制 : 40; 86 | /// 十六进制 : 0x28; 87 | /// 88 | public const byte LeftParentheses = 0x28; 89 | 90 | /// 91 | /// 右小括号。 92 | /// 显示图形 : ); 93 | /// 二进制 : 0010 1001; 94 | /// 十进制 : 41; 95 | /// 十六进制 : 0x29; 96 | /// 97 | public const byte RightParentheses = 0x29; 98 | 99 | /// 100 | /// 星号。 101 | /// 显示图形 : *; 102 | /// 二进制 : 0010 1010; 103 | /// 十进制 : 42; 104 | /// 十六进制 : 0x2A; 105 | /// 106 | public const byte Star = 0x2A; 107 | 108 | /// 109 | /// 加号。 110 | /// 显示图形 : +; 111 | /// 二进制 : 0010 1011; 112 | /// 十进制 : 43; 113 | /// 十六进制 : 0x2B; 114 | /// 115 | public const byte PlusSign = 0x2B; 116 | 117 | /// 118 | /// 逗号。 119 | /// 显示图形 : ,; 120 | /// 二进制 : 0010 1100; 121 | /// 十进制 : 44; 122 | /// 十六进制 : 0x2C; 123 | /// 124 | public const byte Comma = 0x2C; 125 | 126 | /// 127 | /// 减号。 128 | /// 显示图形 : -; 129 | /// 二进制 : 0010 1101; 130 | /// 十进制 : 45; 131 | /// 十六进制 : 0x2D; 132 | /// 133 | public const byte MinusSign = 0x2D; 134 | 135 | /// 136 | /// 点号。 137 | /// 显示图形 : .; 138 | /// 二进制 : 0010 1110; 139 | /// 十进制 : 46; 140 | /// 十六进制 : 0x2E; 141 | /// 142 | public const byte Dot = 0x2E; 143 | 144 | /// 145 | /// 斜线。 146 | /// 显示图形 : /; 147 | /// 二进制 : 0010 1111; 148 | /// 十进制 : 47; 149 | /// 十六进制 : 0x2F; 150 | /// 151 | public const byte Slash = 0x2F; 152 | 153 | /// 154 | /// 0。 155 | /// 显示图形 : 0; 156 | /// 二进制 : 0011 0000; 157 | /// 十进制 : 48; 158 | /// 十六进制 : 0x30; 159 | /// 160 | public const byte Zero = 0x30; 161 | 162 | /// 163 | /// 1。 164 | /// 显示图形 : 1; 165 | /// 二进制 : 0011 0001; 166 | /// 十进制 : 49; 167 | /// 十六进制 : 0x31; 168 | /// 169 | public const byte One = 0x31; 170 | 171 | /// 172 | /// 2。 173 | /// 显示图形 : 2; 174 | /// 二进制 : 0011 0010; 175 | /// 十进制 : 50; 176 | /// 十六进制 : 0x32; 177 | /// 178 | public const byte Two = 0x32; 179 | 180 | /// 181 | /// 3。 182 | /// 显示图形 : 3; 183 | /// 二进制 : 0011 0011; 184 | /// 十进制 : 51; 185 | /// 十六进制 : 0x33; 186 | /// 187 | public const byte Three = 0x33; 188 | 189 | /// 190 | /// 4。 191 | /// 显示图形 : 4; 192 | /// 二进制 : 0011 0100; 193 | /// 十进制 : 52; 194 | /// 十六进制 : 0x34; 195 | /// 196 | public const byte Four = 0x34; 197 | 198 | /// 199 | /// 5。 200 | /// 显示图形 : 5; 201 | /// 二进制 : 0011 0101; 202 | /// 十进制 : 53; 203 | /// 十六进制 : 0x35; 204 | /// 205 | public const byte Five = 0x35; 206 | 207 | /// 208 | /// 6。 209 | /// 显示图形 : 6; 210 | /// 二进制 : 0011 0110; 211 | /// 十进制 : 54; 212 | /// 十六进制 : 0x36; 213 | /// 214 | public const byte Six = 0x36; 215 | 216 | /// 217 | /// 7。 218 | /// 显示图形 : 7; 219 | /// 二进制 : 0011 0111; 220 | /// 十进制 : 55; 221 | /// 十六进制 : 0x37; 222 | /// 223 | public const byte Seven = 0x37; 224 | 225 | /// 226 | /// 8。 227 | /// 显示图形 : 8; 228 | /// 二进制 : 0011 1000; 229 | /// 十进制 : 56; 230 | /// 十六进制 : 0x38; 231 | /// 232 | public const byte Eight= 0x38; 233 | 234 | /// 235 | /// 9。 236 | /// 显示图形 : 9; 237 | /// 二进制 : 0011 1001; 238 | /// 十进制 : 57; 239 | /// 十六进制 : 0x39; 240 | /// 241 | public const byte Nine = 0x39; 242 | 243 | /// 244 | /// 冒号。 245 | /// 显示图形 : :; 246 | /// 二进制 : 0011 1010; 247 | /// 十进制 : 58; 248 | /// 十六进制 : 0x3A; 249 | /// 250 | public const byte Colon = 0x3A; 251 | 252 | /// 253 | /// 分号。 254 | /// 显示图形 : ;; 255 | /// 二进制 : 0011 1011; 256 | /// 十进制 : 59; 257 | /// 十六进制 : 0x3B; 258 | /// 259 | public const byte Semicolon = 0x3B; 260 | 261 | /// 262 | /// 小于号。 263 | /// 显示图形 : <; 264 | /// 二进制 : 0011 1100; 265 | /// 十进制 : 60; 266 | /// 十六进制 : 0x3C; 267 | /// 268 | public const byte LessThan = 0x3C; 269 | 270 | /// 271 | /// 等号。 272 | /// 显示图形 : =; 273 | /// 二进制 : 0011 1101; 274 | /// 十进制 : 61; 275 | /// 十六进制 : 0x3D; 276 | /// 277 | public const byte EqualSign = 0x3D; 278 | 279 | /// 280 | /// 大于号。 281 | /// 显示图形 : >; 282 | /// 二进制 : 0011 1110; 283 | /// 十进制 : 62; 284 | /// 十六进制 : 0x3E; 285 | /// 286 | public const byte GreaterThan = 0x3E; 287 | 288 | /// 289 | /// 问号。 290 | /// 显示图形 : ?; 291 | /// 二进制 : 0011 1111; 292 | /// 十进制 : 63; 293 | /// 十六进制 : 0x3F; 294 | /// 295 | public const byte QuestionMark = 0x3F; 296 | 297 | /// 298 | /// @。 299 | /// 显示图形 : @; 300 | /// 二进制 : 0100 0000; 301 | /// 十进制 : 64; 302 | /// 十六进制 : 0x40; 303 | /// 304 | public const byte AtSign = 0x40; 305 | 306 | /// 307 | /// A。 308 | /// 显示图形 : A; 309 | /// 二进制 : 0100 0001; 310 | /// 十进制 : 65; 311 | /// 十六进制 : 0x41; 312 | /// 313 | public const byte A = 0x41; 314 | 315 | /// 316 | /// B。 317 | /// 显示图形 : B; 318 | /// 二进制 : 0100 0010; 319 | /// 十进制 : 66; 320 | /// 十六进制 : 0x42; 321 | /// 322 | public const byte B = 0x42; 323 | 324 | /// 325 | /// C。 326 | /// 显示图形 : C; 327 | /// 二进制 : 0100 0011; 328 | /// 十进制 : 67; 329 | /// 十六进制 : 0x43; 330 | /// 331 | public const byte C = 0x43; 332 | 333 | /// 334 | /// E。 335 | /// 显示图形 : E; 336 | /// 二进制 : 0100 0101; 337 | /// 十进制 : 69; 338 | /// 十六进制 : 0x45; 339 | /// 340 | public const byte E = 0x45; 341 | 342 | /// 343 | /// G。 344 | /// 显示图形 : G; 345 | /// 二进制 : 0100 0111; 346 | /// 十进制 : 71; 347 | /// 十六进制 : 0x47; 348 | /// 349 | public const byte G = 0x47; 350 | 351 | /// 352 | /// H。 353 | /// 显示图形 : H; 354 | /// 二进制 : 0100 1000; 355 | /// 十进制 : 72; 356 | /// 十六进制 : 0x48; 357 | /// 358 | public const byte H = 0x48; 359 | 360 | /// 361 | /// L。 362 | /// 显示图形 : L; 363 | /// 二进制 : 0100 1100; 364 | /// 十进制 : 76; 365 | /// 十六进制 : 0x4C; 366 | /// 367 | public const byte L = 0x4C; 368 | 369 | /// 370 | /// M。 371 | /// 显示图形 : M; 372 | /// 二进制 : 0100 1101; 373 | /// 十进制 : 77; 374 | /// 十六进制 : 0x4D; 375 | /// 376 | public const byte M = 0x4D; 377 | 378 | /// 379 | /// P。 380 | /// 显示图形 : P; 381 | /// 二进制 : 0101 0000; 382 | /// 十进制 : 80; 383 | /// 十六进制 : 0x50; 384 | /// 385 | public const byte P = 0x50; 386 | 387 | /// 388 | /// R。 389 | /// 显示图形 : R; 390 | /// 二进制 : 0101 0010; 391 | /// 十进制 : 82; 392 | /// 十六进制 : 0x52; 393 | /// 394 | public const byte R = 0x52; 395 | 396 | /// 397 | /// S。 398 | /// 显示图形 : S; 399 | /// 二进制 : 0101 0011; 400 | /// 十进制 : 83; 401 | /// 十六进制 : 0x53; 402 | /// 403 | public const byte S = 0x53; 404 | 405 | /// 406 | /// V。 407 | /// 显示图形 : V; 408 | /// 二进制 : 0101 0110; 409 | /// 十进制 : 86; 410 | /// 十六进制 : 0x56; 411 | /// 412 | public const byte V = 0x56; 413 | 414 | /// 415 | /// w。 416 | /// 显示图形 : w; 417 | /// 二进制 : 0101 0111; 418 | /// 十进制 : 87; 419 | /// 十六进制 : 0x57; 420 | /// 421 | public const byte W = 0x57; 422 | 423 | /// 424 | /// 反斜线。 425 | /// 显示图形 : \; 426 | /// 二进制 : 0101 1100; 427 | /// 十进制 : 92; 428 | /// 十六进制 : 0x5C; 429 | /// 430 | public const byte Backslash = 0x5C; 431 | 432 | /// 433 | /// a。 434 | /// 显示图形 : a; 435 | /// 二进制 : 0110 0001; 436 | /// 十进制 : 97; 437 | /// 十六进制 : 0x61; 438 | /// 439 | // ReSharper disable once InconsistentNaming 440 | public const byte a = 0x61; 441 | 442 | /// 443 | /// f。 444 | /// 显示图形 : f; 445 | /// 二进制 : 0110 0110; 446 | /// 十进制 : 102; 447 | /// 十六进制 : 0x66; 448 | /// 449 | // ReSharper disable once InconsistentNaming 450 | public const byte f = 0x66; 451 | 452 | /// 453 | /// h。 454 | /// 显示图形 : h; 455 | /// 二进制 : 0110 1000; 456 | /// 十进制 : 104; 457 | /// 十六进制 : 0x68; 458 | /// 459 | // ReSharper disable once InconsistentNaming 460 | public const byte h = 0x68; 461 | 462 | /// 463 | /// k。 464 | /// 显示图形 : k; 465 | /// 二进制 : 0110 1011; 466 | /// 十进制 : 107; 467 | /// 十六进制 : 0x6B; 468 | /// 469 | // ReSharper disable once InconsistentNaming 470 | public const byte k = 0x6B; 471 | 472 | /// 473 | /// o。 474 | /// 显示图形 : o; 475 | /// 二进制 : 0111 1111; 476 | /// 十进制 : 111; 477 | /// 十六进制 : 0x6F; 478 | /// 479 | // ReSharper disable once InconsistentNaming 480 | public const byte o = 0x6F; 481 | 482 | /// 483 | /// p。 484 | /// 显示图形 : p; 485 | /// 二进制 : 0111 0000; 486 | /// 十进制 : 112; 487 | /// 十六进制 : 0x70; 488 | /// 489 | // ReSharper disable once InconsistentNaming 490 | public const byte p = 0x70; 491 | 492 | /// 493 | /// q。 494 | /// 显示图形 : q; 495 | /// 二进制 : 0111 0001; 496 | /// 十进制 : 113; 497 | /// 十六进制 : 0x71; 498 | /// 499 | // ReSharper disable once InconsistentNaming 500 | public const byte q = 0x71; 501 | 502 | /// 503 | /// t。 504 | /// 显示图形 : t; 505 | /// 二进制 : 0111 0100; 506 | /// 十进制 : 116; 507 | /// 十六进制 : 0x74; 508 | /// 509 | // ReSharper disable once InconsistentNaming 510 | public const byte t = 0x74; 511 | 512 | /// 513 | /// w。 514 | /// 显示图形 : w; 515 | /// 二进制 : 0111 0111; 516 | /// 十进制 : 119; 517 | /// 十六进制 : 0x77; 518 | /// 519 | // ReSharper disable once InconsistentNaming 520 | public const byte w = 0x77; 521 | } 522 | } 523 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Bing.Printer.EscPos.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | Bing.Printer.EscPos是Bing应用框架的ESC/POS热敏打印操作核心类库。 6 | Bing是一个.net core平台下的应用框架,旨在于提升小型团队的开发能力,由常用公共操作类、架构基类、第三方组件封装、第三方业务接口封装等组成。 7 | 8 | 9 | 10 | ..\..\output\release\ 11 | ..\..\output\release\netstandard2.0\Bing.Printer.EscPos.xml 12 | 13 | 14 | 15 | ..\..\output\release\ 16 | ..\..\output\release\netstandard2.0\Bing.Printer.EscPos.xml 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Builders/BarcodeBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | using Bing.Printer.Builders; 4 | using Bing.Printer.Enums; 5 | using Bing.Printer.Extensions; 6 | 7 | namespace Bing.Printer.EscPos.Builders 8 | { 9 | /// 10 | /// 条码生成器 11 | /// 12 | internal class BarcodeBuilder : IBarcodeBuilder 13 | { 14 | /// 15 | /// 缓存流 16 | /// 17 | private byte[] _buffer; 18 | 19 | /// 20 | /// 字符编码 21 | /// 22 | private readonly Encoding _encoding; 23 | 24 | /// 25 | /// 初始化一个类型的实例 26 | /// 27 | /// 字符编码 28 | public BarcodeBuilder(Encoding encoding) 29 | { 30 | _encoding = encoding; 31 | } 32 | 33 | /// 34 | /// 初始化 35 | /// 36 | public void Init() => _buffer = null; 37 | 38 | /// 39 | /// 设置宽度 40 | /// 41 | /// 宽度 42 | public IBarcodeBuilder Width(BarcodeWidth width) => 43 | Append(Command.BarcodeWidth.AddBytes(new[] {width.ToByte()})); 44 | 45 | /// 46 | /// 设置高度 47 | /// 48 | /// 高度 49 | public IBarcodeBuilder Height(int height) => Append(Command.BarcodeHeight.AddBytes(new[] {height.ToByte()})); 50 | 51 | /// 52 | /// 设置标签显示位置 53 | /// 54 | /// 位置 55 | public IBarcodeBuilder LabelPosition(BarcodePositionType position) => 56 | Append(Command.BarcodeLabelPosition.AddBytes(new[] {position.ToByte()})); 57 | 58 | /// 59 | /// 设置标签字体 60 | /// 61 | /// 类型 62 | public IBarcodeBuilder LabelFontB(BarcodeFontType type) => Append(type == BarcodeFontType.B ? Command.BarcodeLabelFontB : Command.BarcodeLabelFontA); 63 | 64 | /// 65 | /// 生成条形码 66 | /// 67 | /// 条形码类型 68 | /// 值 69 | public byte[] Build(BarcodeType type, string value) 70 | { 71 | 72 | // 设置条形码类型 73 | Append(Command.BarcodeType.AddBytes(new[] {type.ToByte()})); 74 | Append(new[] {(byte) (value.Length + 2)}); 75 | Append(_encoding.GetBytes(value)); 76 | Append(new byte[] {0}); 77 | return _buffer; 78 | } 79 | 80 | /// 81 | /// 追加内容 82 | /// 83 | /// 二进制数组 84 | private IBarcodeBuilder Append(byte[] value) 85 | { 86 | if (value == null) 87 | return this; 88 | var list = new List(); 89 | if (_buffer != null) 90 | list.AddRange(_buffer); 91 | list.AddRange(value); 92 | _buffer = list.ToArray(); 93 | return this; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/CommandConst.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.EscPos 2 | { 3 | /// 4 | /// 命令常量 5 | /// 6 | internal static class CommandConst 7 | { 8 | /// 9 | /// 操作 10 | /// 11 | public static class Operations 12 | { 13 | /// 14 | /// 初始化。 15 | /// 显示图形 : @; 16 | /// 二进制 : 0100 0000; 17 | /// 十进制 : 64; 18 | /// 十六进制 : 0x40; 19 | /// 20 | public const byte Initialize = 0x40; 21 | 22 | /// 23 | /// 启用禁用。 24 | /// 显示图形 : =; 25 | /// 二进制 : 0011 1101; 26 | /// 十进制 : 61; 27 | /// 十六进制 : 0x3D; 28 | /// 29 | public const byte EnableDisable = 0x3D; 30 | 31 | /// 32 | /// 切纸。 33 | /// 显示图形 : V; 34 | /// 二进制 : 0101 0110; 35 | /// 十进制 : 86; 36 | /// 十六进制 : 0x56; 37 | /// 38 | public const byte PaperCut = 0x56; 39 | } 40 | 41 | /// 42 | /// 字符 43 | /// 44 | public static class Chars 45 | { 46 | /// 47 | /// 样式模式。 48 | /// 显示图形 : !; 49 | /// 二进制 : 0010 0001; 50 | /// 十进制 : 33; 51 | /// 十六进制 : 0x21; 52 | /// 53 | public const byte StyleMode = 0x21; 54 | 55 | /// 56 | /// 对齐方式。 57 | /// 显示图形 : a; 58 | /// 二进制 : 0110 0001; 59 | /// 十进制 : 97; 60 | /// 十六进制 : 0x61; 61 | /// 62 | public const byte Alignment = 0x61; 63 | 64 | /// 65 | /// 字符间距。 66 | /// 显示图形 : a; 67 | /// 二进制 : 0110 0001; 68 | /// 十进制 : 97; 69 | /// 十六进制 : 0x61; 70 | /// 71 | public const byte RightCharacterSpacing = 0x20; 72 | } 73 | 74 | /// 75 | /// 空白 76 | /// 77 | public static class Whitespace 78 | { 79 | 80 | } 81 | 82 | /// 83 | /// 状态 84 | /// 85 | public static class Status 86 | { 87 | 88 | } 89 | 90 | /// 91 | /// 函数 92 | /// 93 | public static class Functions 94 | { 95 | 96 | } 97 | 98 | /// 99 | /// 条形码 100 | /// 101 | public static class Barcodes 102 | { 103 | /// 104 | /// 打印。 105 | /// 显示图形 : k; 106 | /// 二进制 : 0110 1011; 107 | /// 十进制 : 107; 108 | /// 十六进制 : 0x6B; 109 | /// 110 | public const byte Print = 0x6B; 111 | 112 | /// 113 | /// 高度。 114 | /// 显示图形 : h; 115 | /// 二进制 : 0110 1000 ; 116 | /// 十进制 : 104; 117 | /// 十六进制 : 0x68; 118 | /// 119 | public const byte Height = 0x68; 120 | 121 | /// 122 | /// 宽度。 123 | /// 显示图形 : w; 124 | /// 二进制 : 0111 0111; 125 | /// 十进制 : 119; 126 | /// 十六进制 : 0x77; 127 | /// 128 | public const byte Width = 0x77; 129 | 130 | /// 131 | /// 标签显示位置。 132 | /// 显示图形 : H; 133 | /// 二进制 : 0100 1000; 134 | /// 十进制 : 72; 135 | /// 十六进制 : 0x48; 136 | /// 137 | public const byte LabelPosition = 0x48; 138 | 139 | /// 140 | /// 标签字体。 141 | /// 显示图形 : f; 142 | /// 二进制 : 0110 0110; 143 | /// 十进制 : 102; 144 | /// 十六进制 : 0x66; 145 | /// 146 | public const byte LabelFont = 0x66; 147 | } 148 | 149 | /// 150 | /// 二维码 151 | /// 152 | public static class QrCode 153 | { 154 | 155 | } 156 | 157 | /// 158 | /// 图片 159 | /// 160 | public static class Images 161 | { 162 | 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/BarcodeCommand.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Builders; 2 | using Bing.Printer.Enums; 3 | using Bing.Printer.Extensions; 4 | using Bing.Printer.Operations; 5 | using Bing.Printer.Options; 6 | 7 | namespace Bing.Printer.EscPos.Commands 8 | { 9 | /// 10 | /// 条形码命令 11 | /// 12 | internal class BarcodeCommand : IBarcode 13 | { 14 | /// 15 | /// 条形码生成器 16 | /// 17 | internal IBarcodeBuilder Builder { get; set; } 18 | 19 | /// 20 | /// 初始化一个类型的实例 21 | /// 22 | /// 条形码生成器 23 | public BarcodeCommand(IBarcodeBuilder builder) 24 | { 25 | Builder = builder; 26 | } 27 | 28 | /// 29 | /// 设置 Code39 类型条形码 30 | /// 31 | /// 值 32 | public byte[] Code39(string value) 33 | { 34 | return new byte[] { ASCIIControlConst.GS, CommandConst.Barcodes.Print, 2 } // Width 35 | .AddBytes(new byte[] { 29, 104, 50 }) // Height 36 | .AddBytes(new byte[] { 29, 102, 0 }) // font hri character 37 | .AddBytes(new byte[] { 29, 72, 0 }) // If print code informed 38 | .AddBytes(new byte[] { 29, 107, 4 }) 39 | .AddBytes(value) 40 | .AddBytes(new byte[] { 0 }) 41 | .AddLf(); 42 | } 43 | 44 | /// 45 | /// 设置 Code128 类型条形码 46 | /// 47 | /// 值 48 | public byte[] Code128(string value) 49 | { 50 | //return Builder.Width(BarcodeWidth.Thinnest) 51 | // .Height(30) 52 | // .LabelFontB(BarcodeFontType.B) 53 | // .LabelPosition(BarcodePositionType.Above) 54 | // .Build(BarcodeType.Code128, value); 55 | return new byte[] { ASCIIControlConst.GS, CommandConst.Barcodes.Print, 2 } // Width 56 | .AddBytes(new byte[] { 29, 104, 50 }) // Height 57 | .AddBytes(new byte[] { 29, 102, 1 }) // font hri character 58 | .AddBytes(new byte[] { 29, 72, 0 }) // If print code informed 59 | .AddBytes(new byte[] { 29, 107, 73 }) // printCode 60 | .AddBytes(new[] { (byte)(value.Length + 2) }) 61 | .AddBytes(new[] { '{'.ToByte(), 'C'.ToByte() }) 62 | .AddBytes(value) 63 | .AddLf(); 64 | } 65 | 66 | /// 67 | /// 设置 Ean13 类型条形码 68 | /// 69 | /// 值 70 | public byte[] Ean13(string value) 71 | { 72 | if (value.Trim().Length != 13) 73 | return new byte[0]; 74 | 75 | return new byte[] { ASCIIControlConst.GS, CommandConst.Barcodes.Print, 2 } // Width 76 | .AddBytes(new byte[] { 29, 104, 50 }) // Height 77 | .AddBytes(new byte[] { 29, 72, 0 }) // If print code informed 78 | .AddBytes(new byte[] { 29, 107, 67, 12 }) 79 | .AddBytes(value.Substring(0, 12)) 80 | .AddLf(); 81 | } 82 | 83 | /// 84 | /// 设置 Code39 类型条形码 85 | /// 86 | /// 值 87 | /// 标签显示位置 88 | /// 宽度 89 | /// 高度 90 | /// 是否使用字体B 91 | public byte[] Code39(string value, BarcodePositionType position, BarcodeWidth width, int height, bool fontB) => 92 | Barcode(value, new BarcodeOptions() 93 | { 94 | Position = position, 95 | Width = width, 96 | Height = height, 97 | FontType = fontB ? BarcodeFontType.B : BarcodeFontType.A, 98 | Type = BarcodeType.Code39 99 | }); 100 | 101 | /// 102 | /// 设置 Code128 类型条形码 103 | /// 104 | /// 值 105 | /// 标签显示位置 106 | /// 宽度 107 | /// 高度 108 | /// 是否使用字体B 109 | public byte[] Code128(string value, BarcodePositionType position, BarcodeWidth width, int height, bool fontB) => 110 | Barcode(value, new BarcodeOptions 111 | { 112 | Position = position, 113 | Width = width, 114 | Height = height, 115 | FontType = fontB ? BarcodeFontType.B : BarcodeFontType.A, 116 | Type = BarcodeType.Code128 117 | }); 118 | 119 | /// 120 | /// 设置 Ean13 类型条形码 121 | /// 122 | /// 值 123 | /// 标签显示位置 124 | /// 宽度 125 | /// 高度 126 | /// 是否使用字体B 127 | public byte[] Ean13(string value, BarcodePositionType position, BarcodeWidth width, int height, bool fontB) => 128 | Barcode(value, new BarcodeOptions() 129 | { 130 | Position = position, 131 | Width = width, 132 | Height = height, 133 | FontType = fontB ? BarcodeFontType.B : BarcodeFontType.A, 134 | Type = BarcodeType.Ean13 135 | }); 136 | 137 | /// 138 | /// 设置条形码 139 | /// 140 | /// 值 141 | /// 条形码选项 142 | public byte[] Barcode(string value, BarcodeOptions options) 143 | { 144 | Builder.Init(); 145 | Builder.Width(options.Width ?? BarcodeWidth.Thinnest) 146 | .Height(options.Height ?? 50) 147 | .LabelPosition(options.Position ?? BarcodePositionType.None) 148 | .LabelFontB(options.FontType ?? BarcodeFontType.B); 149 | return Builder.Build(options.Type, value); 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/DrawerCommand.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Operations; 2 | 3 | namespace Bing.Printer.EscPos.Commands 4 | { 5 | /// 6 | /// 绘制器操作 7 | /// 8 | internal class DrawerCommand : IDrawer 9 | { 10 | /// 11 | /// 打开绘制器 12 | /// 13 | public byte[] OpenDrawer() => new byte[] {27, 112, 0, 60, 120}; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/FontStyleCommand.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | using Bing.Printer.Exceptions; 3 | using Bing.Printer.Extensions; 4 | using Bing.Printer.Operations; 5 | 6 | namespace Bing.Printer.EscPos.Commands 7 | { 8 | /// 9 | /// 字体样式命令 10 | /// 11 | internal class FontStyleCommand : IFontStyle 12 | { 13 | /// 14 | /// 加粗。将文字加粗 15 | /// 16 | /// 值 17 | public byte[] Bold(string value) => BoldOn().AddBytes(value).AddBytes(BoldOff()).AddLf(); 18 | 19 | /// 20 | /// 加粗-开。将文字加粗 21 | /// 22 | public byte[] BoldOn() => Command.TxtBoldOn; 23 | 24 | /// 25 | /// 加粗-关。将文字加粗 26 | /// 27 | public byte[] BoldOff() => Command.TxtBoldOff; 28 | 29 | /// 30 | /// 倍宽 31 | /// 32 | /// 值 33 | public byte[] DoubleWidth(string value) => DoubleWidthOn().AddBytes(value).AddBytes(DoubleWidthOff()).AddLf(); 34 | 35 | /// 36 | /// 倍宽-开 37 | /// 38 | public byte[] DoubleWidthOn() => Command.Chinese.DoubleWidthOn.AddBytes(Command.ASCII.DoubleWidth); 39 | 40 | /// 41 | /// 倍宽-关 42 | /// 43 | public byte[] DoubleWidthOff() => Command.Chinese.FontSizeReset.AddBytes(Command.ASCII.FontSizeReset); 44 | 45 | /// 46 | /// 倍高 47 | /// 48 | /// 值 49 | public byte[] DoubleHeight(string value) => DoubleHeightOn().AddBytes(value).AddBytes(DoubleHeightOff()).AddLf(); 50 | 51 | /// 52 | /// 倍高-开 53 | /// 54 | public byte[] DoubleHeightOn() => Command.Chinese.DoubleHeightOn.AddBytes(Command.ASCII.DoubleHeight); 55 | 56 | /// 57 | /// 倍高-关 58 | /// 59 | public byte[] DoubleHeightOff() => Command.Chinese.FontSizeReset.AddBytes(Command.ASCII.FontSizeReset); 60 | 61 | /// 62 | /// 倍宽高 63 | /// 64 | /// 值 65 | public byte[] DoubleWidthHeight(string value) => DoubleWidthHeightOn().AddBytes(value).AddBytes(DoubleWidthHeightOff()).AddLf(); 66 | 67 | /// 68 | /// 倍宽高-开 69 | /// 70 | public byte[] DoubleWidthHeightOn() => Command.Chinese.DoubleWidthHeightOn.AddBytes(Command.ASCII.DoubleWidthHeight); 71 | 72 | /// 73 | /// 倍宽高-关 74 | /// 75 | public byte[] DoubleWidthHeightOff() => Command.Chinese.FontSizeReset.AddBytes(Command.ASCII.FontSizeReset); 76 | 77 | /// 78 | /// 下划线(1点宽)。为文字添加下划线 79 | /// 80 | /// 值 81 | public byte[] Underline(string value) => UnderlineOn().AddBytes(value).AddBytes(UnderlineOff()).AddLf(); 82 | 83 | /// 84 | /// 下划线(2点宽)。为文字添加下划线 85 | /// 86 | /// 值 87 | public byte[] Underline2(string value) => Underline2On().AddBytes(value).AddBytes(UnderlineOff()).AddLf(); 88 | 89 | /// 90 | /// 下划线(1点宽)。为文字添加下划线 91 | /// 92 | public byte[] UnderlineOn() => Command.Chinese.UnderlineOn.AddBytes(Command.ASCII.UnderlineOn); 93 | 94 | /// 95 | /// 下划线(2点宽)。为文字添加下划线 96 | /// 97 | public byte[] Underline2On() => Command.Chinese.Underline2On.AddBytes(Command.ASCII.Underline2On); 98 | 99 | /// 100 | /// 下划线。为文字添加下划线 101 | /// 102 | public byte[] UnderlineOff() => Command.Chinese.UnderlineOff.AddBytes(Command.ASCII.UnderlineOff); 103 | 104 | /// 105 | /// 黑白反显 106 | /// 107 | /// 值 108 | public byte[] BlackWhite(string value) => BlackWhiteOn().AddBytes(value).AddBytes(BlackWhiteOff()).AddLf(); 109 | 110 | /// 111 | /// 黑白反显-开 112 | /// 113 | public byte[] BlackWhiteOn() => Command.TxtBlackWhiteReverseOn; 114 | 115 | /// 116 | /// 黑白反显-关 117 | /// 118 | public byte[] BlackWhiteOff() => Command.TxtBlackWhiteReverseOff; 119 | 120 | /// 121 | /// 顺时针90度旋转 122 | /// 123 | /// 值 124 | public byte[] Rotate90(string value) => Rotate90On().AddBytes(value).AddBytes(RotateOff()).AddLf(); 125 | 126 | /// 127 | /// 顺时针180度旋转 128 | /// 129 | /// 值 130 | public byte[] Rotate180(string value) => Rotate180On().AddBytes(value).AddBytes(RotateOff()).AddLf(); 131 | 132 | /// 133 | /// 顺时针270度旋转 134 | /// 135 | /// 值 136 | public byte[] Rotate270(string value) => Rotate270On().AddBytes(value).AddBytes(RotateOff()).AddLf(); 137 | 138 | /// 139 | /// 顺时针90度旋转-开 140 | /// 141 | public byte[] Rotate90On() => Command.TxtRotate90On; 142 | 143 | /// 144 | /// 顺时针180度旋转-开 145 | /// 146 | public byte[] Rotate180On() => Command.TxtRotate180On; 147 | 148 | /// 149 | /// 顺时针270度旋转-开 150 | /// 151 | public byte[] Rotate270On() => Command.TxtRotate270On; 152 | 153 | /// 154 | /// 顺时针旋转-关 155 | /// 156 | public byte[] RotateOff() => Command.TxtRotateOff; 157 | 158 | /// 159 | /// 设置字体大小 160 | /// 161 | /// 字体大小 162 | public byte[] FontSize(FontSize size) 163 | { 164 | byte realSize = 0; 165 | switch (size) 166 | { 167 | case Enums.FontSize.Size0: 168 | realSize = 0; 169 | break; 170 | case Enums.FontSize.Size1: 171 | realSize = 17; 172 | break; 173 | case Enums.FontSize.Size2: 174 | realSize = 34; 175 | break; 176 | case Enums.FontSize.Size3: 177 | realSize = 51; 178 | break; 179 | case Enums.FontSize.Size4: 180 | realSize = 68; 181 | break; 182 | case Enums.FontSize.Size5: 183 | realSize = 85; 184 | break; 185 | case Enums.FontSize.Size6: 186 | realSize = 102; 187 | break; 188 | case Enums.FontSize.Size7: 189 | realSize = 119; 190 | break; 191 | } 192 | 193 | return Command.Size.AddByte(realSize); 194 | } 195 | 196 | /// 197 | /// 设置字体大小 198 | /// 199 | /// 字体大小 200 | public byte[] FontSize(int size) 201 | { 202 | return Command.Size.AddByte(size.ToByte()); 203 | } 204 | 205 | /// 206 | /// 设置字体大小 207 | /// 208 | /// 宽度 209 | /// 高度 210 | public byte[] FontSize(int width, int height) 211 | { 212 | var widthSize = (width - 1) * 16; 213 | var heightSize = (height - 1); 214 | var size = widthSize + heightSize; 215 | return Command.Size.AddByte(size.ToByte()); 216 | } 217 | 218 | /// 219 | /// 设置字体类型 220 | /// 221 | /// 字体类型 222 | public byte[] FontType(FontType type) => Command.FontType.AddByte(type.ToByte()); 223 | 224 | /// 225 | /// 设置倍宽。仅支持4个级别 226 | /// 227 | /// 字体大小 228 | public byte[] DoubleWidth(FontSize size) 229 | { 230 | byte realSize = 0; 231 | switch (size) 232 | { 233 | case Enums.FontSize.Size0: 234 | realSize = 0; 235 | break; 236 | case Enums.FontSize.Size1: 237 | realSize = 16; 238 | break; 239 | case Enums.FontSize.Size2: 240 | realSize = 32; 241 | break; 242 | case Enums.FontSize.Size3: 243 | realSize = 48; 244 | break; 245 | default: 246 | throw new PrintException("仅支持 FontSize0 - FontSize3 倍宽"); 247 | } 248 | return Command.Size.AddByte(realSize); 249 | } 250 | 251 | /// 252 | /// 设置倍高。仅支持4个级别 253 | /// 254 | /// 字体大小 255 | public byte[] DoubleHeight(FontSize size) 256 | { 257 | byte realSize = 0; 258 | switch (size) 259 | { 260 | case Enums.FontSize.Size0: 261 | realSize = 0; 262 | break; 263 | case Enums.FontSize.Size1: 264 | realSize = 1; 265 | break; 266 | case Enums.FontSize.Size2: 267 | realSize = 2; 268 | break; 269 | case Enums.FontSize.Size3: 270 | realSize = 3; 271 | break; 272 | default: 273 | throw new PrintException("仅支持 FontSize0 - FontSize3 倍高"); 274 | } 275 | return Command.Size.AddByte(realSize); 276 | } 277 | 278 | /// 279 | /// 设置字符代码页 280 | /// 281 | /// 字符代码表 282 | public byte[] FontCode(CodeTable table) => Command.CharCodePage.AddByte(table.ToByte()); 283 | } 284 | } 285 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/ImageCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Drawing; 3 | using System.IO; 4 | using Bing.Printer.Operations; 5 | 6 | namespace Bing.Printer.EscPos.Commands 7 | { 8 | /// 9 | /// 图片操作命令 10 | /// 11 | internal class ImageCommand : IImage 12 | { 13 | /// 14 | /// 打印纸 15 | /// 16 | internal IPrintPaper PrintPaper { get; } 17 | 18 | /// 19 | /// 初始化一个类型的实例 20 | /// 21 | /// 打印纸 22 | public ImageCommand(IPrintPaper printPaper) 23 | { 24 | PrintPaper = printPaper; 25 | } 26 | 27 | /// 28 | /// 打印图片 29 | /// 30 | /// 图片路径 31 | public byte[] PrintImage(string imgPath) 32 | { 33 | using (var image= Image.FromFile(imgPath)) 34 | { 35 | return PrintImage(image); 36 | } 37 | } 38 | 39 | /// 40 | /// 打印图片 41 | /// 42 | /// 流 43 | public byte[] PrintImage(Stream stream) 44 | { 45 | using (var image = Image.FromStream(stream)) 46 | { 47 | return PrintImage(image); 48 | } 49 | } 50 | 51 | /// 52 | /// 打印图片 53 | /// 54 | /// 字节数组 55 | public byte[] PrintImage(byte[] bytes) 56 | { 57 | using (var ms = new MemoryStream(bytes)) 58 | { 59 | return PrintImage(Image.FromStream(ms)); 60 | } 61 | } 62 | 63 | /// 64 | /// 打印图片 65 | /// 66 | /// 图片 67 | public byte[] PrintImage(Image image) 68 | { 69 | var list = new List(); 70 | var bmp = new Bitmap(image); 71 | //设置字符行间距为n点行 72 | //byte[] data = new byte[] { 0x1B, 0x33, 0x00 }; 73 | string send = "" + (char)(27) + (char)(51) + (char)(0); 74 | byte[] data = new byte[send.Length]; 75 | for (int i = 0; i < send.Length; i++) 76 | { 77 | data[i] = (byte)send[i]; 78 | } 79 | 80 | list.AddRange(data); 81 | data[0] = (byte)'\x00'; 82 | data[1] = (byte)'\x00'; 83 | data[2] = (byte)'\x00'; // Clear to Zero. 84 | Color pixelColor; 85 | //ESC * m nL nH d1…dk 选择位图模式 86 | // ESC * m nL nH 87 | byte[] escBmp = { 0x1B, 0x2A, 0x00, 0x00, 0x00 }; 88 | escBmp[2] = (byte)'\x21'; 89 | //nL, nH 90 | escBmp[3] = (byte)(bmp.Width % 256); 91 | escBmp[4] = (byte)(bmp.Width / 256); 92 | //循环图片像素打印图片 93 | //循环高 94 | for (int i = 0; i < (bmp.Height / 24 + 1); i++) 95 | { 96 | //设置模式为位图模式 97 | list.AddRange(escBmp); 98 | //循环宽 99 | for (int j = 0; j < bmp.Width; j++) 100 | { 101 | for (int k = 0; k < 24; k++) 102 | { 103 | if (((i * 24) + k) < bmp.Height) // if within the BMP size 104 | { 105 | pixelColor = bmp.GetPixel(j, (i * 24) + k); 106 | if (!(pixelColor.R > 160 && pixelColor.G > 160 && pixelColor.B > 160)) 107 | { 108 | data[k / 8] += (byte)(128 >> (k % 8)); 109 | } 110 | //if (pixelColor.R == 0) 111 | //{ 112 | // data[k / 8] += (byte)(128 >> (k % 8)); 113 | //} 114 | } 115 | } 116 | 117 | //一次写入一个data,24个像素 118 | list.AddRange(data); 119 | 120 | data[0] = (byte)'\x00'; 121 | data[1] = (byte)'\x00'; 122 | data[2] = (byte)'\x00'; // Clear to Zero. 123 | } 124 | 125 | //换行,打印第二行 126 | byte[] data2 = { 0xA }; 127 | list.AddRange(data2); 128 | } // data 129 | 130 | return list.ToArray(); 131 | } 132 | 133 | private byte[] Draw2PxPoint(Bitmap bitmap) 134 | { 135 | // 先设置一个足够大的size,最后在用数组拷贝复制到一个精确大小的byte数组中 136 | 137 | var list = new List(); 138 | // 设置行距为0 139 | list.Add(0x1B); 140 | list.Add(0x33); 141 | list.Add(0x00); 142 | // 居中打印 143 | list.Add(0x1B); 144 | list.Add(0x61); 145 | list.Add(1); 146 | for (int i = 0; i < bitmap.Height / 24f; i++) 147 | { 148 | list.Add(0x1B); 149 | list.Add(0x2A); // 0x1B 2A 表示图片打印指令 150 | list.Add(33); // m=33时,选择24点密度打印 151 | list.Add((byte) (bitmap.Width % 256)); // nL 152 | list.Add((byte) (bitmap.Width / 256));// nH 153 | for (var j = 0; j < bitmap.Width; j++) 154 | { 155 | for (var m = 0; m < 3; m++) 156 | { 157 | byte currentK = 0; 158 | for (int n = 0; n < 8; n++) 159 | { 160 | byte b = Px2Byte(j, i * 24 + m * 8 + n, bitmap); 161 | currentK += (byte) (currentK + b); 162 | } 163 | list.Add(currentK); 164 | } 165 | } 166 | 167 | list.Add(10); 168 | } 169 | 170 | list.Add(0x1B); 171 | list.Add(0x32); 172 | 173 | return list.ToArray(); 174 | } 175 | 176 | private byte Px2Byte(int x, int y, Bitmap bitmap) 177 | { 178 | if (x < bitmap.Width && y < bitmap.Height) 179 | { 180 | byte b; 181 | var pixel = bitmap.GetPixel(x, y); 182 | var gray = Rgb2Gray(pixel.R, pixel.G, pixel.B); 183 | if (gray < 128) 184 | { 185 | b = 1; 186 | } 187 | else 188 | { 189 | b = 0; 190 | } 191 | 192 | return b; 193 | } 194 | 195 | return 0; 196 | } 197 | 198 | /// 199 | /// RGB转灰度值 200 | /// 201 | /// R 202 | /// G 203 | /// B 204 | private int Rgb2Gray(byte r, byte g, byte b) 205 | { 206 | return (int) (0.2990 * r + 0.58700 * g + 0.11400 * b);// 灰度转化公式 207 | } 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/InitializePrintCommand.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Operations; 2 | 3 | namespace Bing.Printer.EscPos.Commands 4 | { 5 | /// 6 | /// 初始化打印操作 7 | /// 8 | internal class InitializePrintCommand : IInitializePrint 9 | { 10 | /// 11 | /// 初始化 12 | /// 13 | public byte[] Initialize() => Command.HardwareInit; 14 | 15 | /// 16 | /// 启用 17 | /// 18 | public byte[] Enable() => new[] {ASCIIControlConst.ESC, CommandConst.Operations.EnableDisable, (byte) 1}; 19 | 20 | /// 21 | /// 禁用 22 | /// 23 | public byte[] Disable() => new[] {ASCIIControlConst.ESC, CommandConst.Operations.EnableDisable, (byte) 0}; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/PagerCutCommand.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Extensions; 2 | using Bing.Printer.Operations; 3 | 4 | namespace Bing.Printer.EscPos.Commands 5 | { 6 | /// 7 | /// 页面截断操作 8 | /// 9 | internal class PagerCutCommand : IPagerCut 10 | { 11 | /// 12 | /// 全页截断 13 | /// 14 | public byte[] Full() => Command.PagerFullCut; 15 | 16 | /// 17 | /// 部分截断 18 | /// 19 | public byte[] Partial() => Command.PagerPartialCut; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/PrintLineCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Text; 3 | using Bing.Printer.Operations; 4 | 5 | namespace Bing.Printer.EscPos.Commands 6 | { 7 | /// 8 | /// 打印线操作指令 9 | /// 10 | internal class PrintLineCommand:IPrintLine 11 | { 12 | /// 13 | /// 打印纸 14 | /// 15 | private IPrintPaper _printPaper; 16 | 17 | /// 18 | /// 初始化一个类型的实例 19 | /// 20 | /// 打印纸 21 | public PrintLineCommand(IPrintPaper printPaper) 22 | { 23 | _printPaper = printPaper; 24 | } 25 | 26 | /// 27 | /// 设置实线 28 | /// 29 | public string SolidLine() 30 | { 31 | var length = _printPaper.GetLineWidth() * 2; 32 | var sb = new StringBuilder(); 33 | while (length>0) 34 | { 35 | sb.Append("-"); 36 | length--; 37 | } 38 | return sb.ToString(); 39 | } 40 | 41 | /// 42 | /// 设置空行 43 | /// 44 | public string EmptyLine() 45 | { 46 | var length = _printPaper.GetLineWidth(); 47 | var sb = new StringBuilder(); 48 | while (length > 0) 49 | { 50 | sb.Append(" "); 51 | length--; 52 | } 53 | return sb.ToString(); 54 | } 55 | 56 | /// 57 | /// 设置虚线 58 | /// 59 | public string DottedLine() 60 | { 61 | var length = _printPaper.GetLineWidth(); 62 | var sb = new StringBuilder(); 63 | while (length > 0) 64 | { 65 | sb.Append("- "); 66 | length--; 67 | } 68 | return sb.ToString(); 69 | } 70 | 71 | /// 72 | /// 写入一行输出 73 | /// 74 | /// 文本1 75 | /// 文本2 76 | public string WriteOneLine(string text1, string text2) => WriteOneLine(text1, text2, 0); 77 | 78 | /// 79 | /// 写入一行输出 80 | /// 81 | /// 文本1 82 | /// 文本2 83 | /// 文字大小 84 | public string WriteOneLine(string text1, string text2, int textSize) 85 | { 86 | var lineLength = _printPaper.GetLineStringWidth(textSize); 87 | var needEmpty = (lineLength - 88 | (GetStringWidth(text1) + GetStringWidth(text2)) % lineLength) / 1; 89 | var sb = new StringBuilder(); 90 | while (needEmpty > 0) 91 | { 92 | sb.Append(" "); 93 | needEmpty--; 94 | } 95 | 96 | var empty = sb.ToString(); 97 | return $"{text1}{empty}{text2}"; 98 | } 99 | 100 | /// 101 | /// 写入一行输出 102 | /// 103 | /// 文本1 104 | /// 文本2 105 | /// 文本3 106 | public string WriteOneLine(string text1, string text2, string text3) => WriteOneLine(text1, text2, text3, 0); 107 | 108 | /// 109 | /// 写入一行输出 110 | /// 111 | /// 文本1 112 | /// 文本2 113 | /// 文本3 114 | /// 文字大小 115 | public string WriteOneLine(string text1, string text2, string text3, int textSize) 116 | { 117 | var lineLength = _printPaper.GetLineStringWidth(textSize); 118 | var needEmpty = (lineLength - 119 | (GetStringWidth(text1) + GetStringWidth(text2) + GetStringWidth(text3)) % lineLength) / 2; 120 | var sb = new StringBuilder(); 121 | while (needEmpty > 0) 122 | { 123 | sb.Append(" "); 124 | needEmpty--; 125 | } 126 | 127 | var empty = sb.ToString(); 128 | return $"{text1}{empty}{text2}{empty}{text3}"; 129 | } 130 | 131 | /// 132 | /// 写入一行输出 133 | /// 134 | /// 文本1 135 | /// 文本2 136 | /// 文本3 137 | /// 文本4 138 | public string WriteOneLine(string text1, string text2, string text3, string text4) => WriteOneLine(text1, text2, text3, text4, 0); 139 | 140 | /// 141 | /// 写入一行输出 142 | /// 143 | /// 文本1 144 | /// 文本2 145 | /// 文本3 146 | /// 文本4 147 | /// 文字大小 148 | public string WriteOneLine(string text1, string text2, string text3, string text4, int textSize) 149 | { 150 | var lineLength = _printPaper.GetLineStringWidth(textSize); 151 | var needEmpty = (lineLength - (GetStringWidth(text1) + GetStringWidth(text2) + GetStringWidth(text3) + 152 | GetStringWidth(text4)) % lineLength) / 3; 153 | var sb = new StringBuilder(); 154 | while (needEmpty>0) 155 | { 156 | sb.Append(" "); 157 | needEmpty--; 158 | } 159 | 160 | var empty = sb.ToString(); 161 | return $"{text1}{empty}{text2}{empty}{text3}{empty}{text4}"; 162 | } 163 | 164 | /// 165 | /// 获取字符串宽度 166 | /// 167 | /// 文本 168 | private static int GetStringWidth(string text) => text.ToCharArray().Sum(c => c >= 0 && c <= 128 ? 1 : 2); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/PrintStyleCommand.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Extensions; 2 | using Bing.Printer.Operations; 3 | 4 | namespace Bing.Printer.EscPos.Commands 5 | { 6 | /// 7 | /// 打印样式操作命令 8 | /// 9 | internal class PrintStyleCommand : IPrintStyle 10 | { 11 | /// 12 | /// 设置左边距 13 | /// 14 | /// 值 15 | public byte[] LeftMargin(int value = 0) 16 | { 17 | var nH = value >> 8; 18 | var nL = value - (nH << 8); 19 | return Command.StyleLeftMargin.AddBytes(new[] { nL.ToByte(), nH.ToByte() }); 20 | } 21 | 22 | /// 23 | /// 设置左边距 24 | /// 25 | /// 边距值 26 | /// 高度 27 | public byte[] LeftMargin(int nL, int nH) => Command.StyleLeftMargin.AddBytes(new[] { nL.ToByte(), nH.ToByte() }); 28 | 29 | /// 30 | /// 设置打印区域宽度 31 | /// 32 | /// 长度 33 | /// 高度 34 | public byte[] PrintWidth(int nL, int nH) => Command.StylePrintWidth.AddBytes(new[] {nL.ToByte(), nH.ToByte()}); 35 | 36 | /// 37 | /// 设置相对横向打印位置 38 | /// 39 | /// 长度 40 | /// 高度 41 | public byte[] RelativeHorizontalPosition(int nL, int nH) => Command.StyleRelativeXPosition.AddBytes(new[] {nL.ToByte(), nH.ToByte()}); 42 | 43 | /// 44 | /// 设置绝对打印位置 45 | /// 46 | /// 长度 47 | /// 高度 48 | public byte[] AbsolutePosition(int nL, int nH) => Command.StyleAbsolutePrintPosition.AddBytes(new[] { nL.ToByte(), nH.ToByte() }); 49 | 50 | /// 51 | /// 左对齐 52 | /// 53 | public byte[] Left() => Command.StyleLeftAlign; 54 | 55 | /// 56 | /// 居中 57 | /// 58 | public byte[] Center() => Command.StyleCenterAlign; 59 | 60 | /// 61 | /// 右对齐 62 | /// 63 | public byte[] Right() => Command.StyleRightAlign; 64 | 65 | /// 66 | /// 设置默认行高 67 | /// 68 | public byte[] RowHeight() => Command.StyleDefaultRowHeight; 69 | 70 | /// 71 | /// 设置行高 72 | /// 73 | /// 高度 74 | public byte[] RowHeight(int height) => Command.StyleRowHeight.AddByte(height.ToByte()); 75 | 76 | /// 77 | /// 设置中文字符间距 78 | /// 79 | /// 左间距 80 | /// 右间距 81 | // ReSharper disable once InconsistentNaming 82 | public byte[] SpacingCN(int left = 0, int right = 0) => Command.Chinese.SpaceingLeftRight.AddBytes(new[] {left.ToByte(), right.ToByte()}); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/QrCodeCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | using Bing.Printer.Enums; 4 | using Bing.Printer.Extensions; 5 | using Bing.Printer.Operations; 6 | 7 | namespace Bing.Printer.EscPos.Commands 8 | { 9 | /// 10 | /// 二维码操作 11 | /// 12 | internal class QRCodeCommand : IQrCode 13 | { 14 | /// 15 | /// 获取二维码大小二进制数组 16 | /// 17 | /// 二维码大小 18 | private static byte[] Size(QrCodeSize size) => new byte[] {29, 40, 107, 3, 0, 49, 67} 19 | .AddBytes(new[] {(size + 3).ToByte()}); 20 | 21 | /// 22 | /// 模式码 23 | /// 24 | private static IEnumerable ModelQr() => new byte[] {29, 40, 107, 4, 0, 49, 65, 50, 0}; 25 | 26 | /// 27 | /// 容错码 28 | /// 29 | private static IEnumerable ErrorQr() => new byte[] {29, 40, 107, 3, 0, 49, 69, 48}; 30 | 31 | /// 32 | /// 存储码 33 | /// 34 | /// 二维码数据 35 | private static IEnumerable StoreQr(string qrData) 36 | { 37 | var length = qrData.Length + 3; 38 | var b = (byte) (length % 256); 39 | var b2 = (byte) (length / 256); 40 | 41 | return new byte[] { 29, 40, 107 } 42 | .AddBytes(new[] { b }) 43 | .AddBytes(new[] { b2 }) 44 | .AddBytes(new byte[] { 49, 80, 48 }); 45 | } 46 | 47 | /// 48 | /// 打印码 49 | /// 50 | private static IEnumerable PrintQr() => new byte[] {29, 40, 107, 3, 0, 49, 81, 48}; 51 | 52 | /// 53 | /// 设置二维码 54 | /// 55 | /// 值 56 | public byte[] QrCode(string value) 57 | { 58 | return QrCode(value, QrCodeSize.Size0); 59 | } 60 | 61 | /// 62 | /// 设置二维码 63 | /// 64 | /// 值 65 | /// 二维码大小 66 | public byte[] QrCode(string value, QrCodeSize size) 67 | { 68 | var list = new List(); 69 | list.AddRange(ModelQr()); 70 | list.AddRange(Size(size)); 71 | list.AddRange(ErrorQr()); 72 | list.AddRange(StoreQr(value)); 73 | list.AddRange(Encoding.UTF8.GetBytes(value)); 74 | list.AddRange(PrintQr()); 75 | return list.ToArray(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/StyleCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Bing.Printer.Enums; 3 | using Bing.Printer.Extensions; 4 | using Bing.Printer.Operations; 5 | 6 | namespace Bing.Printer.EscPos.Commands 7 | { 8 | /// 9 | /// 样式操作 10 | /// 11 | internal class StyleCommand : IStyle 12 | { 13 | /// 14 | /// 打印纸 15 | /// 16 | private IPrintPaper _printPaper; 17 | 18 | /// 19 | /// 字符编码 20 | /// 21 | private Encoding _encoding; 22 | 23 | /// 24 | /// 初始化一个类型的实例 25 | /// 26 | /// 打印纸 27 | /// 字符编码 28 | public StyleCommand(IPrintPaper printPaper, Encoding encoding) 29 | { 30 | _printPaper = printPaper; 31 | _encoding = encoding; 32 | } 33 | 34 | /// 35 | /// 设置打印样式 36 | /// 37 | /// 打印样式 38 | public byte[] Styles(PrintStyle style) => new[] {ASCIIControlConst.ESC, CommandConst.Chars.StyleMode, style.ToByte()}; 39 | 40 | /// 41 | /// 设置字符间距 42 | /// 43 | /// 空格数 44 | public byte[] RightCharacterSpacing(int spaceCount) => new[] { ASCIIControlConst.ESC, CommandConst.Chars.RightCharacterSpacing, spaceCount.ToByte() }; 45 | 46 | /// 47 | /// 设置字体大小 48 | /// 49 | /// 字体大小 50 | public byte[] Size(int size) => GetFontSizeSetBig(size); 51 | 52 | /// 53 | /// 设置分隔符 54 | /// 55 | public byte[] Separator() => _encoding.GetBytes(new string('-', _printPaper.GetLineStringWidth(2))); 56 | 57 | /// 58 | /// 获取字体表达为标准的n倍 59 | /// 60 | /// 倍数 61 | private static byte[] GetFontSizeSetBig(int size) 62 | { 63 | byte realSize = 0; 64 | switch (size) 65 | { 66 | case 0: 67 | realSize = 0; 68 | break; 69 | case 1: 70 | realSize = 17; 71 | break; 72 | case 2: 73 | realSize = 34; 74 | break; 75 | case 3: 76 | realSize = 51; 77 | break; 78 | case 4: 79 | realSize = 68; 80 | break; 81 | case 5: 82 | realSize = 85; 83 | break; 84 | case 6: 85 | realSize = 102; 86 | break; 87 | case 7: 88 | realSize = 119; 89 | break; 90 | } 91 | 92 | return new[] {ASCIIControlConst.GS, ASCIIShowConst.Bang, realSize}; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/Commands/WriterCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | using Bing.Printer.Extensions; 4 | using Bing.Printer.Operations; 5 | 6 | namespace Bing.Printer.EscPos.Commands 7 | { 8 | /// 9 | /// 写入器命令 10 | /// 11 | internal class WriterCommand : IWriter 12 | { 13 | /// 14 | /// 流 15 | /// 16 | private byte[] _buffer; 17 | 18 | /// 19 | /// 字符编码 20 | /// 21 | private readonly Encoding _encoding; 22 | 23 | /// 24 | /// 初始化一个类型的实例 25 | /// 26 | /// 字符编码 27 | public WriterCommand(Encoding encoding) 28 | { 29 | _encoding = encoding; 30 | } 31 | 32 | /// 33 | /// 写入 34 | /// 35 | /// 字节数组 36 | public IWriter Write(byte[] value) 37 | { 38 | if (value == null) 39 | return this; 40 | var list = new List(); 41 | if (_buffer != null) 42 | list.AddRange(_buffer); 43 | list.AddRange(value); 44 | _buffer = list.ToArray(); 45 | return this; 46 | } 47 | 48 | /// 49 | /// 写入 50 | /// 51 | /// 字符串 52 | public IWriter Write(string value) 53 | { 54 | Write(value, false); 55 | return this; 56 | } 57 | 58 | /// 59 | /// 写入 60 | /// 61 | /// 值 62 | /// 是否换行 63 | private void Write(string value, bool useLf) 64 | { 65 | if(string.IsNullOrEmpty(value)) 66 | return; 67 | if (useLf) 68 | value += "\n"; 69 | var list = new List(); 70 | if (_buffer != null) 71 | list.AddRange(_buffer); 72 | var bytes = _encoding.GetBytes(value); 73 | list.AddRange(bytes); 74 | _buffer = list.ToArray(); 75 | } 76 | 77 | /// 78 | /// 写入并换行 79 | /// 80 | /// 字符串 81 | public IWriter WriteLine(string value) 82 | { 83 | Write(value, true); 84 | return this; 85 | } 86 | 87 | /// 88 | /// 写入并换行 89 | /// 90 | /// 字节数组 91 | public IWriter WriteLine(byte[] value) 92 | { 93 | Write(value, true); 94 | return this; 95 | } 96 | 97 | /// 98 | /// 写入 99 | /// 100 | /// 值 101 | /// 是否换行 102 | private void Write(byte[] value, bool useLf) 103 | { 104 | if(value==null) 105 | return; 106 | if (useLf) 107 | value.AddLf(); 108 | var list = new List(); 109 | if (_buffer != null) 110 | list.AddRange(_buffer); 111 | list.AddRange(value); 112 | _buffer = list.ToArray(); 113 | } 114 | 115 | /// 116 | /// 添加行 117 | /// 118 | public IWriter NewLine() 119 | { 120 | WriteLine("\r"); 121 | return this; 122 | } 123 | 124 | /// 125 | /// 添加行 126 | /// 127 | /// 行数 128 | public IWriter NewLine(int liens) 129 | { 130 | for (int i = 0; i < liens; i++) 131 | { 132 | NewLine(); 133 | } 134 | return this; 135 | } 136 | 137 | /// 138 | /// 清空内容 139 | /// 140 | public IWriter Clear() 141 | { 142 | _buffer = null; 143 | return this; 144 | } 145 | 146 | /// 147 | /// 获取二进制数组 148 | /// 149 | public byte[] GetBytes() => _buffer; 150 | 151 | /// 152 | /// 转换为十六进制 153 | /// 154 | public string ToHex() 155 | { 156 | if (_buffer == null) 157 | return string.Empty; 158 | var result = new StringBuilder(); 159 | foreach (var b in _buffer) 160 | result.AppendFormat("{0:x2}", b); 161 | return result.Replace("-", "").ToString(); 162 | } 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/EscPosPrinter.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Bing.Printer.Factories; 3 | 4 | namespace Bing.Printer.EscPos 5 | { 6 | /// 7 | /// Esc/Pos 打印机 8 | /// 9 | public class EscPosPrinter : PrinterBase, IEscPosPrinter 10 | { 11 | /// 12 | /// 创建打印命令 13 | /// 14 | protected override IPrintCommand CreatePrintCommand() => 15 | new PrintCommand(PrintPaperFactory.GetOrCreate(PrintPaper), Encoding.GetEncoding("GB18030")); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/IEscPosPrinter.cs: -------------------------------------------------------------------------------- 1 | namespace Bing.Printer.EscPos 2 | { 3 | /// 4 | /// Esc/Pos 打印机 5 | /// 6 | public interface IEscPosPrinter : IPrinter 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/Bing.Printer.EscPos/PrintCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Bing.Printer.Builders; 3 | using Bing.Printer.EscPos.Builders; 4 | using Bing.Printer.EscPos.Commands; 5 | using Bing.Printer.Operations; 6 | 7 | namespace Bing.Printer.EscPos 8 | { 9 | /// 10 | /// 打印命令 11 | /// 12 | internal class PrintCommand : IPrintCommand 13 | { 14 | /// 15 | /// 字体样式操作 16 | /// 17 | public IFontStyle FontStyle { get; set; } 18 | 19 | /// 20 | /// 页面截断操作 21 | /// 22 | public IPagerCut PagerCut { get; set; } 23 | 24 | /// 25 | /// 绘制器操作 26 | /// 27 | public IDrawer Drawer { get; set; } 28 | 29 | /// 30 | /// 二维码操作 31 | /// 32 | public IQrCode QrCode { get; set; } 33 | 34 | /// 35 | /// 条形码操作 36 | /// 37 | public IBarcode Barcode { get; set; } 38 | 39 | /// 40 | /// 样式操作 41 | /// 42 | public IStyle Style { get; set; } 43 | 44 | /// 45 | /// 条形码生成器 46 | /// 47 | internal IBarcodeBuilder BarcodeBuilder { get; set; } 48 | 49 | /// 50 | /// 初始化打印操作 51 | /// 52 | public IInitializePrint InitializePrint { get; set; } 53 | 54 | /// 55 | /// 打印样式操作 56 | /// 57 | public IPrintStyle PrintStyle { get; set; } 58 | 59 | /// 60 | /// 图片操作 61 | /// 62 | public IImage Image { get; set; } 63 | 64 | /// 65 | /// 写入器操作 66 | /// 67 | public IWriter Writer { get; set; } 68 | 69 | /// 70 | /// 打印行操作 71 | /// 72 | public IPrintLine PrintLine { get; set; } 73 | 74 | /// 75 | /// 初始化一个类型的实例 76 | /// 77 | /// 打印纸 78 | /// 字符编码 79 | public PrintCommand(IPrintPaper printPaper, Encoding encoding) 80 | { 81 | Writer = new WriterCommand(encoding); 82 | BarcodeBuilder = new BarcodeBuilder(encoding); 83 | 84 | FontStyle = new FontStyleCommand(); 85 | PagerCut = new PagerCutCommand(); 86 | Drawer = new DrawerCommand(); 87 | QrCode = new QRCodeCommand(); 88 | Barcode = new BarcodeCommand(BarcodeBuilder); 89 | Style = new StyleCommand(printPaper, encoding); 90 | InitializePrint = new InitializePrintCommand(); 91 | PrintStyle = new PrintStyleCommand(); 92 | Image = new ImageCommand(printPaper); 93 | PrintLine = new PrintLineCommand(printPaper); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/Bing.Printer.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | PreserveNewest 23 | 24 | 25 | PreserveNewest 26 | 27 | 28 | PreserveNewest 29 | 30 | 31 | PreserveNewest 32 | 33 | 34 | PreserveNewest 35 | 36 | 37 | PreserveNewest 38 | 39 | 40 | PreserveNewest 41 | 42 | 43 | PreserveNewest 44 | 45 | 46 | PreserveNewest 47 | 48 | 49 | PreserveNewest 50 | 51 | 52 | PreserveNewest 53 | 54 | 55 | PreserveNewest 56 | 57 | 58 | PreserveNewest 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/BusinessTest.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.Enums; 2 | using Bing.Printer.EscPos; 3 | using Bing.Printer.Extensions; 4 | using Xunit; 5 | using Xunit.Abstractions; 6 | 7 | namespace Bing.Printer.Tests 8 | { 9 | /// 10 | /// 业务测试 11 | /// 12 | public class BusinessTest:TestBase 13 | { 14 | public BusinessTest(ITestOutputHelper output) : base(output) 15 | { 16 | } 17 | 18 | /// 19 | /// 测试 - 打印物流订单 20 | /// 21 | [Fact] 22 | public void Test_PrintDeliveryOrder() 23 | { 24 | Printer.Initialize(); 25 | Printer.Center(); 26 | Printer.Code128("b0201902134", BarcodePositionType.Below, BarcodeWidth.Default, 100, true); 27 | Printer.NewLine(); 28 | 29 | Printer.Initialize(); 30 | Printer.Left(); 31 | 32 | var order = "Y20190618000001"; 33 | 34 | Printer.FontType(FontType.Compress2); 35 | Printer.FontSize(FontSize.Size1); 36 | Printer.LeftMargin(30); 37 | Printer.Write("运单号"); 38 | Printer.LeftMargin(160); 39 | Printer.Write(order.Substring(0, order.Length - 4)); 40 | Printer.FontType(FontType.Normal); 41 | Printer.FontSize(FontSize.Size1); 42 | Printer.Write(order.Substring(order.Length - 4, 4)); 43 | Printer.RowHeight(30); 44 | Printer.NewLine(); 45 | 46 | Printer.Initialize(); 47 | Printer.Left(); 48 | Printer.FontType(FontType.Compress2); 49 | Printer.FontSize(FontSize.Size1); 50 | Printer.RowHeight(30); 51 | //PrintItem(Printer, 30, 160, "运单号", "Y20190618000001"); 52 | PrintItem(Printer, 0, 160, "配送中心", "天河高志体验店",30); 53 | PrintItem(Printer, 0, 160, "配送划区", "隔壁老王", 30); 54 | PrintItem(Printer, 0, 160, "配送时段", "2019-06-24 14:00-18:00", 30); 55 | PrintItem(Printer, 30, 160, "收货人", "来自隔壁老王的新手大礼包", 30); 56 | PrintItem(Printer, 0, 160, "联系电话", "18975927788", 30); 57 | var content = "广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大广州市天河区黄埔大"; 58 | //var content = "广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大"; 59 | //var content = "广州市天河区黄埔大道西1201号高志大厦B1层"; 60 | //var content = "广州市天河区黄埔大道"; 61 | PrintItem(Printer, 0, 160, "收货地址", content, 30); 62 | 63 | var line = GetLines(content, 26); 64 | Printer.Initialize(); 65 | //Printer.DottedLine(); 66 | //Printer.NewLine(); 67 | //if (7 - line > 0) 68 | //{ 69 | // Printer.NewLine(7 - line); 70 | //} 71 | //Printer.DottedLine(); 72 | //Printer.NewLine(); 73 | 74 | switch (line) 75 | { 76 | case 1: 77 | Printer.Write(new byte[] { 0x1B, 0x4A, 222.ToByte() }); 78 | break; 79 | case 2: 80 | Printer.Write(new byte[] { 0x1B, 0x4A, 155.ToByte() }); 81 | break; 82 | case 3: 83 | Printer.Write(new byte[] { 0x1B, 0x4A, 100.ToByte() }); 84 | break; 85 | case 4: 86 | Printer.Write(new byte[] { 0x1B, 0x4A, 40.ToByte() }); 87 | break; 88 | } 89 | 90 | //Printer.DottedLine(); 91 | //Printer.NewLine(); 92 | 93 | var result = Printer.ToHex(); 94 | Output.WriteLine(result); 95 | } 96 | 97 | /// 98 | /// 测试 - 打印物流订单详情 99 | /// 100 | [Fact] 101 | public void Test_PrintDeliveryOrderDetail() 102 | { 103 | //var logoPath = "D:\\utopa.tms_logo_1.png"; 104 | //var logoPath = "D:\\utopa.tms_logo.png"; 105 | var logoPath = "D:\\test_image4.jpg"; 106 | //var logoPath = "D:\\utb_logo.png"; 107 | Printer.Initialize(); 108 | Printer.Center(); 109 | //Printer.WriteLine("预留Logo位置"); 110 | Printer.PrintImage(logoPath); 111 | Printer.NewLine(); 112 | Printer.FontType(FontType.Compress2); 113 | Printer.FontSize(FontSize.Size1); 114 | Printer.WriteLine("联结你我 传送欢笑"); 115 | Printer.NewLine(); 116 | Printer.Initialize(); 117 | Printer.Center(); 118 | Printer.Code128("b0201902134", BarcodePositionType.Below, BarcodeWidth.Default, 100, true); 119 | Printer.NewLine(); 120 | 121 | Printer.Initialize(); 122 | Printer.Left(); 123 | Printer.FontType(FontType.Compress2); 124 | Printer.FontSize(FontSize.Size1); 125 | PrintItem(Printer, 30, 160, "订单号", "30122019071000001741266205"); 126 | PrintItem(Printer, 30, 160, "运单号", "Y20190618000001"); 127 | PrintItem(Printer, 0, 160, "配送中心", "天河高志体验店"); 128 | PrintItem(Printer, 0, 160, "配送区域", "隔壁老王"); 129 | PrintItem(Printer, 0, 160, "配送时段", "2019-06-24 14:00-18:00"); 130 | 131 | Printer.Initialize(); 132 | PrintItem(Printer, 52, 160, "收货人", "来自隔壁老王的新手大礼包"); 133 | PrintItem(Printer, 30, 160, "联系电话", "18975927788"); 134 | PrintItem(Printer, 30, 160, "收货地址", "广州市天河区黄埔大道西120号高志大厦B1层"); 135 | 136 | Printer.Initialize(); 137 | Printer.DottedLine(); 138 | Printer.NewLine(); 139 | Printer.WriteOneLine("商品名称", "数量", "单价", "合计 "); 140 | Printer.NewLine(); 141 | Printer.DottedLine(); 142 | Printer.NewLine(); 143 | 144 | for (int i = 0; i < 3; i++) 145 | { 146 | Printer.WriteLine($"10023332 白苋菜白苋菜白苋菜白苋菜白苋菜白苋菜白苋菜白苋菜白苋菜白苋菜白苋菜白苋菜白苋菜-{i}"); 147 | 148 | Printer.LeftMargin(180, 0); 149 | Printer.PrintWidth(128, 0); 150 | Printer.Write("1"); 151 | 152 | Printer.LeftMargin(54, 1); 153 | Printer.PrintWidth(130, 0); 154 | Printer.Write("222.50"); 155 | 156 | Printer.LeftMargin(190, 1); 157 | Printer.PrintWidth(180, 0); 158 | Printer.Write("6666.00"); 159 | 160 | Printer.NewLine(); 161 | Printer.Initialize(); 162 | } 163 | 164 | Printer.DottedLine(); 165 | Printer.NewLine(); 166 | Printer.WriteOneLine("合计", "30", "", "2010.00"); 167 | Printer.NewLine(); 168 | Printer.DottedLine(); 169 | Printer.NewLine(2); 170 | 171 | var result = Printer.ToHex(); 172 | Output.WriteLine(result); 173 | } 174 | 175 | private void PrintItem(IEscPosPrinter printer, string left, string right) 176 | { 177 | printer.LeftMargin(50); 178 | printer.Write(left); 179 | printer.LeftMargin(168); 180 | printer.Write(right); 181 | printer.NewLine(1); 182 | } 183 | 184 | private void PrintItem(IEscPosPrinter printer, int leftMargin, int rightMargin, string left, string right,int rowHeigth = 15) 185 | { 186 | printer.LeftMargin(leftMargin); 187 | printer.Write(left); 188 | printer.LeftMargin(rightMargin); 189 | printer.Write(right); 190 | printer.NewLine(); 191 | printer.RowHeight(rowHeigth); 192 | } 193 | 194 | [Fact] 195 | public void Test_ContentLength() 196 | { 197 | var line1 = GetLines("广州市天河区黄埔大道西1201号高志大厦B1层", 26); 198 | var line2 = GetLines("广州市天河区黄埔大道", 26); 199 | var line3 = GetLines("广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大", 26); 200 | var line4 = GetLines( 201 | "广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道", 26); 202 | Output.WriteLine($"line1 : {line1}, line2 : {line2}, line3 : {line3}, line4 : {line4}"); 203 | } 204 | 205 | /// 206 | /// 获取行数 207 | /// 208 | /// 内容 209 | /// 最大长度 210 | /// 211 | private int GetLines(string content, int maxLength) 212 | { 213 | var line = 1; 214 | var currentLength = 0; 215 | var index = -1; 216 | foreach (var c in content.ToCharArray()) 217 | { 218 | index++; 219 | // 判断是否Ascii值 220 | var isAscii = c >= 0 && c <= 128; 221 | var length = isAscii ? 1 : 2; 222 | if (currentLength + length == maxLength) 223 | { 224 | currentLength = 0; 225 | if (index < content.Length-1) 226 | { 227 | line++; 228 | } 229 | continue; 230 | } 231 | 232 | if (currentLength + length > maxLength) 233 | { 234 | currentLength = 1; 235 | line++; 236 | continue; 237 | } 238 | 239 | currentLength += length; 240 | } 241 | 242 | return line; 243 | } 244 | 245 | /// 246 | /// 测试 - 循环打印条码 247 | /// 248 | [Fact] 249 | public void Test_CyclePrint_Barcode() 250 | { 251 | for (var i = 1; i <= 3; i++) 252 | { 253 | CyclePrintItem(Printer, 3, i); 254 | } 255 | Output.WriteLine(Printer.ToHex()); 256 | } 257 | 258 | /// 259 | /// 循环打印项 260 | /// 261 | /// 打印 262 | /// 总页数 263 | /// 当前页 264 | private void CyclePrintItem(IEscPosPrinter printer, int totalPage,int currentPage) 265 | { 266 | printer.Initialize(); 267 | printer.Left(); 268 | printer.Write($"{currentPage}/{totalPage}"); 269 | printer.NewLine(); 270 | 271 | printer.Initialize(); 272 | printer.Center(); 273 | printer.Code128($"b0201902134-{currentPage}", BarcodePositionType.Below, BarcodeWidth.Default, 100, true); 274 | printer.NewLine(); 275 | 276 | printer.Initialize(); 277 | printer.Left(); 278 | 279 | var order = "Y20190618000001"; 280 | 281 | printer.FontType(FontType.Compress2); 282 | printer.FontSize(FontSize.Size1); 283 | printer.LeftMargin(30); 284 | printer.Write("运单号"); 285 | printer.LeftMargin(160); 286 | printer.Write(order.Substring(0, order.Length - 4)); 287 | printer.FontType(FontType.Normal); 288 | printer.FontSize(FontSize.Size1); 289 | printer.Write(order.Substring(order.Length - 4, 4)); 290 | printer.RowHeight(30); 291 | printer.NewLine(); 292 | 293 | printer.Initialize(); 294 | printer.Left(); 295 | printer.FontType(FontType.Compress2); 296 | printer.FontSize(FontSize.Size1); 297 | printer.RowHeight(30); 298 | PrintItem(printer, 0, 160, "配送中心", "天河高志体验店", 30); 299 | PrintItem(printer, 0, 160, "配送划区", "隔壁老王", 30); 300 | PrintItem(printer, 0, 160, "配送时段", "2019-06-24 14:00-18:00", 30); 301 | PrintItem(printer, 30, 160, "收货人", "来自隔壁老王的新手大礼包", 30); 302 | PrintItem(printer, 0, 160, "联系电话", "18975927788", 30); 303 | var content = "广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大道广州市天河区黄埔大广州市天河区黄埔大"; 304 | PrintItem(printer, 0, 160, "收货地址", content, 30); 305 | 306 | var line = GetLines(content, 26); 307 | printer.Initialize(); 308 | 309 | switch (line) 310 | { 311 | case 1: 312 | printer.Write(new byte[] { 0x1B, 0x4A, 222.ToByte() }); 313 | break; 314 | case 2: 315 | printer.Write(new byte[] { 0x1B, 0x4A, 155.ToByte() }); 316 | break; 317 | case 3: 318 | printer.Write(new byte[] { 0x1B, 0x4A, 100.ToByte() }); 319 | break; 320 | case 4: 321 | printer.Write(new byte[] { 0x1B, 0x4A, 40.ToByte() }); 322 | break; 323 | } 324 | } 325 | } 326 | } 327 | -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/Commands/PagerCutCommandTest.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using Xunit.Abstractions; 3 | 4 | namespace Bing.Printer.Tests.Commands 5 | { 6 | /// 7 | /// 页面截断命令测试 8 | /// 9 | public class PagerCutCommandTest : TestBase 10 | { 11 | public PagerCutCommandTest(ITestOutputHelper output) : base(output) 12 | { 13 | } 14 | 15 | /// 16 | /// 测试 - 全页切断 17 | /// 18 | [Fact] 19 | public void Test_Full() 20 | { 21 | Printer.Initialize(); 22 | Printer.WriteLine("Test Full Cut"); 23 | Printer.WriteLine("测试全页切断"); 24 | 25 | Printer.Full(); 26 | Printer.WriteLine("Test Full Cut"); 27 | Printer.WriteLine("测试全页切断"); 28 | Printer.Full(); 29 | 30 | Printer.Initialize(); 31 | Printer.WriteLine("Test Full Cut"); 32 | Printer.WriteLine("测试全页切断"); 33 | 34 | Printer.NewLine(2); 35 | 36 | Output.WriteLine(Printer.ToHex()); 37 | } 38 | 39 | /// 40 | /// 测试 - 部分切断 41 | /// 42 | [Fact] 43 | public void Test_Partial() 44 | { 45 | Printer.Initialize(); 46 | Printer.WriteLine("Test Partial Cut"); 47 | Printer.WriteLine("测试部分切断"); 48 | 49 | Printer.Full(); 50 | Printer.WriteLine("Test Partial Cut"); 51 | Printer.WriteLine("测试部分切断"); 52 | Printer.Full(); 53 | 54 | Printer.Initialize(); 55 | Printer.WriteLine("Test Partial Cut"); 56 | Printer.WriteLine("测试部分切断"); 57 | 58 | Printer.NewLine(2); 59 | 60 | Output.WriteLine(Printer.ToHex()); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/Commands/PrintStyleCommandTest.cs: -------------------------------------------------------------------------------- 1 | using Bing.Printer.EscPos; 2 | using Bing.Printer.Extensions; 3 | using Xunit; 4 | using Xunit.Abstractions; 5 | 6 | namespace Bing.Printer.Tests.Commands 7 | { 8 | /// 9 | /// 打印样式命令测试 10 | /// 11 | public class PrintStyleCommandTest : TestBase 12 | { 13 | /// 14 | /// 初始化一个类型的实例 15 | /// 16 | /// 输出 17 | public PrintStyleCommandTest(ITestOutputHelper output) : base(output) 18 | { 19 | } 20 | 21 | /// 22 | /// 测试 - Beep 23 | /// 24 | [Fact] 25 | public void Test_Beep() 26 | { 27 | Printer.Initialize(); 28 | Printer.WriteLine("Test Print Style Beep"); 29 | Printer.WriteLine("测试打印样式底边距"); 30 | 31 | Printer.Write(new byte[] {Command.Esc, 0x28, 0x41, 4, 0, 48, 51, 3, 15}); 32 | Printer.WriteLine("Test Print Style Beep"); 33 | Printer.WriteLine("测试打印样式底边距"); 34 | 35 | Printer.Initialize(); 36 | Printer.WriteLine("Test Print Style Beep"); 37 | Printer.WriteLine("测试打印样式底边距"); 38 | 39 | Printer.NewLine(2); 40 | 41 | Output.WriteLine(Printer.ToHex()); 42 | } 43 | 44 | /// 45 | /// 测试 - 设置底边距 46 | /// 47 | [Fact] 48 | public void Test_BottomMargin() 49 | { 50 | Printer.Initialize(); 51 | Printer.WriteLine("Test Print Style Bottom Margin"); 52 | Printer.WriteLine("测试打印样式底边距测试打印样式底边距测试打印样式底边距测试打印样式底边距"); 53 | 54 | Printer.Write(new byte[] { Command.Esc, 0x51, 0.ToByte() }); 55 | Printer.WriteLine("Test Print Style Bottom Margin"); 56 | Printer.WriteLine("测试打印样式底边距测试打印样式底边距测试打印样式底边距测试打印样式底边距"); 57 | Printer.Write(new byte[] { Command.Esc, 0x51, 1.ToByte() }); 58 | Printer.WriteLine("Test Print Style Bottom Margin"); 59 | Printer.WriteLine("测试打印样式底边距测试打印样式底边距测试打印样式底边距测试打印样式底边距"); 60 | Printer.Write(new byte[] { Command.Esc, 0x51, 10.ToByte() }); 61 | Printer.WriteLine("Test Print Style Bottom Margin"); 62 | Printer.WriteLine("测试打印样式底边距测试打印样式底边距测试打印样式底边距测试打印样式底边距"); 63 | Printer.Write(new byte[] { Command.Esc, 0x51, 20.ToByte() }); 64 | Printer.WriteLine("Test Print Style Bottom Margin"); 65 | Printer.WriteLine("测试打印样式底边距测试打印样式底边距测试打印样式底边距测试打印样式底边距"); 66 | 67 | Printer.Initialize(); 68 | Printer.WriteLine("Test Print Style Bottom Margin"); 69 | Printer.WriteLine("测试打印样式底边距"); 70 | 71 | Printer.NewLine(2); 72 | 73 | Output.WriteLine(Printer.ToHex()); 74 | } 75 | 76 | /// 77 | /// 测试 - 设置行高 78 | /// 79 | [Fact] 80 | public void Test_RowHeight() 81 | { 82 | Printer.Initialize(); 83 | Printer.WriteLine("Test Print Style Row Height"); 84 | Printer.WriteLine("测试打印样式行高"); 85 | 86 | for (int i = 0; i < 255; i+=10) 87 | { 88 | Printer.RowHeight(i); 89 | Printer.WriteLine($"{i}px Test Print Style Row Height"); 90 | Printer.WriteLine($"{i}px 测试打印样式行高"); 91 | } 92 | 93 | Printer.Initialize(); 94 | Printer.WriteLine("Test Print Style Row Height"); 95 | Printer.WriteLine("测试打印样式行高"); 96 | 97 | Printer.NewLine(2); 98 | 99 | Output.WriteLine(Printer.ToHex()); 100 | } 101 | 102 | /// 103 | /// 测试 - 设置中文字符间距 104 | /// 105 | [Fact] 106 | public void Test_SpacingCN() 107 | { 108 | Printer.Initialize(); 109 | Printer.WriteLine("Test Print Style SpacingCN"); 110 | Printer.WriteLine("测试打印样式中文字符间距"); 111 | 112 | Printer.SpacingCN(); 113 | Printer.WriteLine("Test Print Style SpacingCN"); 114 | Printer.WriteLine("测试打印样式中文字符间距"); 115 | 116 | Printer.SpacingCN(5, 5); 117 | Printer.WriteLine("Test Print Style SpacingCN"); 118 | Printer.WriteLine("测试打印样式中文字符间距"); 119 | 120 | Printer.SpacingCN(10, 10); 121 | Printer.WriteLine("Test Print Style SpacingCN"); 122 | Printer.WriteLine("测试打印样式中文字符间距"); 123 | 124 | Printer.SpacingCN(20, 20); 125 | Printer.WriteLine("Test Print Style SpacingCN"); 126 | Printer.WriteLine("测试打印样式中文字符间距"); 127 | 128 | Printer.SpacingCN(30, 30); 129 | Printer.WriteLine("Test Print Style SpacingCN"); 130 | Printer.WriteLine("测试打印样式中文字符间距"); 131 | 132 | Printer.Initialize(); 133 | Printer.WriteLine("Test Print Style SpacingCN"); 134 | Printer.WriteLine("测试打印样式中文字符间距"); 135 | 136 | Printer.NewLine(2); 137 | 138 | Output.WriteLine(Printer.ToHex()); 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/Commands/WriterCommandTest.cs: -------------------------------------------------------------------------------- 1 | using Xunit.Abstractions; 2 | 3 | namespace Bing.Printer.Tests.Commands 4 | { 5 | /// 6 | /// 写入器命令测试 7 | /// 8 | public class WriterCommandTest:TestBase 9 | { 10 | /// 11 | /// 初始化一个类型的实例 12 | /// 13 | /// 输出 14 | public WriterCommandTest(ITestOutputHelper output) : base(output) 15 | { 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/TestBase.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/TestBase.cs -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/abe-lincoln.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/abe-lincoln.png -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/kitten.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/kitten.jpg -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-100.png -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-200.png -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-300.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-300.bmp -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-300.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-300.gif -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-300.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-300.jpg -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-300.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-300.png -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-400.png -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-500.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-500.png -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo-600.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo-600.png -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bing-framework/Bing.Printer/85de794154868b03a4d7f4ef69b536890faa153c/tests/Bing.Printer.Tests/images/pd-logo.png -------------------------------------------------------------------------------- /tests/Bing.Printer.Tests/images/pd-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 47 | image/svg+xmlOpenclipart 173 | --------------------------------------------------------------------------------