Why euro symbol printing as Ôé¼?
Why euro symbol printing as Ôé¼?
I have an Epson tm-t20 configured with codepage 858. I did a test print of the codepage and the characters are fine. The Java class is UTF-8 encoded. I'm trying to print some text with characters like é, ç and € present in the already named codepage.
The printer is compatible with these Docflavors:
Arrays.stream(service.getSupportedDocFlavors()).forEach(f->System.out.println(f.getMediaType()+":"+f.getMimeType()+":"+f.getRepresentationClassName()));
image:image/gif:[B
image:image/gif:java.io.InputStream
image:image/gif:java.net.URL
image:image/jpeg:[B
image:image/jpeg:java.io.InputStream
image:image/jpeg:java.net.URL
image:image/png:[B
image:image/png:java.io.InputStream
image:image/png:java.net.URL
application:application/x-java-jvm-local-objectref:java.awt.print.Pageable
application:application/x-java-jvm-local-objectref:java.awt.print.Printable
application:application/octet-stream:[B
application:application/octet-stream:java.net.URL
application:application/octet-stream:java.io.InputStream
So far I tried:
Attemp 1: with InputStream
public static void print(){
InputStream bytes = new ByteArrayInputStream(("Estó ès una pruebà rn Hola qu€ tal").getBytes());
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
DocPrintJob pj = service.createPrintJob();
Doc doc = new SimpleDoc(bytes, flavor, null);
pj.print(doc, null);
}
Output:
Estó ès una pruebà
Hola quÔé¼ tal
Attept 2: with byte, same output
public static void print(){
byte bytes = new String("Estó ès una pruebà rn Hola qu€ tal").getBytes(Charset.forName("UTF-8"));
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
DocPrintJob pj = service.createPrintJob();
Doc doc = new SimpleDoc(bytes, flavor, null);
pj.print(doc, null);
}
Any idea what can be wrong?
3 Answers
3
That's enconding issue. You will have to use unicode if you want to print euro symbol and anothers symbols.
Example of printing euro symbol with unicode
System.out.println("u20ac");
However, check this question Displaying euro symbol using unicode and changing characters to uppercase and take a look of andrewdotn's answer, it's really well explained.
You should be able to use attempt 2, with one change: when using Charset.forName, you should not pass UTF-8 as the charset, but rather "Cp858" (given by the supported encodings documentation for Java). The encoding should be based on the codepage the printer expects, and the fact that the Java source is UTF-8 is not relevant to this conversion.
Charset.forName
"Cp858"
It is encoding issue.Platform's default charset must be treating euro symbol as garbage character.
You need to pass charset with these read and write operations as precautions.
Read this article:
https://www.geeksforgeeks.org/java-io-inputstreamreader-class/
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.