Comments (7)
And here is the proof that it is indeed the ToCharArray there that messes it up.
So having set the code page to PC861_ICELANDIC then the only way to get Print and PrintLine to work is to pre-process all I send in with to make sure it is no longer actual unicode.
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var chars = System.Text.Encoding.GetEncoding(861).GetBytes(token.Text);
string s = System.Text.Encoding.Latin1.GetString(chars);
result = Combine(result, e.PrintLine(s));
And then it works and I get Icelandic letters printed out.
So to fix the library then library should probably at very least add Print and PrintLine overides that just take byte[] since then I could send in the System.Text.Encoding.GetEncoding(861).GetBytes(token.Text) directly.
Or the Print and PrintLine would need to be fixed to take into account the selected code page for the printer, and get the bytes correctly from the string for that.
from esc-pos-.net.
The override for Print you are asking for is just Write (you can write byte arrays of whatever you want directly to the buffer).
You are correct in that conversion / compression of Unicode into printer code pages is not currently a function this library supports. I agree with you that this would be super valuable, but it requires some way to map unicode into the relevant code pages for each given language, and rejection of other unencodable unicode characters.
Another potential solution is to support these other languages in a bitmapped way, where we could render Unicode directly into an image and print it that way. It would require a clear definition of the pixel width of each printer, which could have a lookup table or could be specified manually. Then it would be a matter of properly printing and wrapping the generated image, but then we could support anything, even emojis! ๐ธ The whole concept of printer code pages would also no longer be relevant, and that would open the door to all sorts of cool layout options since at that point they're image-based and not directly related to the printer's supported layout and styling options. Heck you could even render html or PDFs to the printer at that point!
This library is MIT and we super appreciate any contributions. The work around various languages' printability (especially Kanji based languages) has come up a lot - they would seriously benefit from an image / rasterized print where the fonts are handled by the library, because the printers currently only support Katakana. If you're not familiar, languages like Japanese, Chinese, and Korean are symbolic and have a single symbol represent a whole word - meaning they have thousands of such characters. This doesn't fit into a limited memory of an embedded device and Unicode is not a standard of ESCPOS, so what they do is require an alternate character set called Katakana that is phonetically spelling out the words, which is much lengthier.
This isn't something I have the time to implement myself, but I think this would really help out our library, and I can definitely test this out for you on multiple printers if you want to tackle either of the 2 implementations above. The only thing I'd ask is to make it flexible enough to support more code pages than just Icelandic, even if you just stub out the other languages, so that as others need those languages, they can build and test out the mappings.
from esc-pos-.net.
In case it wasn't clear from my comment about directly writing the bytes - the Print function was originally intended to throw if unicode text is entered (which is what that //TODO: sanitize
block is about). All you really have to do if you use the Write directly is to do the replacement of carriage returns with newlines.
I see after re-reading your post that there's already code page conversion built into .NET, it seems? In that case, could we have an extension of the print function that takes in the desired code page and throws if characters are outside the character set?
from esc-pos-.net.
Yes, I think extension of the print method would be excellent yes....
One that takes then the code page.
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
var chars = System.Text.Encoding.GetEncoding(861).GetBytes(token.Text);
So it would be something like
void PrintLine(string line, int codepage)
from esc-pos-.net.
You game for making a PR that adds this support?
Is there an enum that maps to the 861? Or how do you know which numbers are valid code pages?
from esc-pos-.net.
I will see about doing it on the weekend. There is no enum, I imagine it will just throw, if code page is invalid.
from esc-pos-.net.
FYI @lukevp this is the second time (See #88 (comment)) someone has suggested such a change to Print()
instead of using Write()
, perhaps it's more natural for users of the library to have it both ways? I've just submitted a PR with a proposal for this. Please check #260
from esc-pos-.net.
Related Issues (20)
- Landscape Mode HOT 2
- Port get jammed after long use HOT 1
- Not getting status from SerialPrinter HOT 1
- Can't Print Greek characters HOT 2
- Windows and Linux support HOT 1
- HELP! My thermal printer printed out Chinese chars in some of ConsoleTest test HOT 3
- Error "Device or resourse busy" When I impress more the one time. HOT 5
- ESC-POS-.NET want work on MAUI Android - issue libSystem.IO.Ports.Native not loaded HOT 2
- Epson USB printer - getting "System.IO.IOException: The handle is invalid" HOT 2
- Is it possible to print in Page Mode ? (tickets with the exact same size) HOT 1
- 2 Worker Services to one thermical printer HOT 2
- is there Indian rupee sign โจโนโฉ in codepage? HOT 1
- PDF417 max 255 characters HOT 8
- Printer Stop before execution of cut command. HOT 2
- Getting rid of the constant beeping when there is no paper in the paper feeder
- Problem with appPOS80AM3
- Problem with image and printer appPOSAM3 HOT 1
- Printer stopped sending status update events HOT 1
- Interest to support CUSTOM printers? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esc-pos-.net.