CryptoSys Home > FirmaSAT > Changing the font and code page for the Windows console

FirmaSAT command-line: Changing the font and code page for the Windows console


The text output by FirmaSAT on the Windows console is UTF-8 encoded. This will display "funny" characters on the default console. The text below should read "Juanito Pérez Niño", but the accented characters é and ñ each appear as two funny characters.

Funny characters on default console

To fix, you need to do two things:

  1. change the font in the console to a TrueType font
  2. change the active code page to 65001 for UTF-8 characters

Similarly when using Java on the Windows console, you need to change the active code page to 1252 - see Java on the command line below.

Instructions

  1. Right-click in the title bar of the console (the top bar with the title and minimize/maximize/close buttons in it).

    Right click in the top bar and select properties

  2. Select Properties
  3. In the Font menu on the Font tab, select one of the TrueType fonts, for example Lucida Console.

    Select a TrueType font and click on OK

  4. Click on OK
  5. The console should now display a thinner font. But it will still display the characters incorrectly. Typing chcp will show the active code page, on our system it is 850.

    Right click in the top bar and select properties

  6. Type chcp 65001. This changes the Active code page to UTF-8. Now the characters appear correctly.

Java on the command line

The default encoding for Java on the Windows console is typically Cp1252. You can check by examining the file.encoding property:

System.out.println("file.encoding=" + System.getProperty("file.encoding"));
On our system this displays
file.encoding=Cp1252

To display the output from a Java program correctly in the console follow the instructions above except type chcp 1252 in step 6.

Example in Java

`FirmasatAttribute.java` is a simple Java program to read an attribute from a CFDi XML file. This is equivalent to the FirmaSAT command-line example above.

/* FirmasatAttribute.java */

import net.cryptosys.firmasat.*;

public class FirmasatAttribute {
    public static void main(String[] args) {
        System.out.println("file.encoding=" + System.getProperty("file.encoding"));
        String fname = "venta11.xml";
        String elementName = "Receptor";
        String attributeName = "nombre";
        String s = Sat.getXmlAttribute(fname, attributeName, elementName);
        System.out.println("Sat.getXmlAttribute('"+ fname +"',"+ elementName + "/@" + attributeName +")=\n"+ s );
    }
}

The image below shows the result of running this Java program with the default code page 850 (funny characters in the output) and after changing the code page to 1252 by typing chcp 1252 (characters appear correctly).

Use code page 1252 for a Java program

(The font in the above image is Consolas size 16 Bold)

For more information about using Java with FirmaSAT, see the Java Interface to FirmaSAT page.

Contact

To comment on this page, or for further information, please send us a message.

This page last updated 12 August 2020