Printing Unicode

Same as with displaying unicode you need to configure support for unicode on every level

  • data (database or stream file)
  • program
  • printer file
  • device

Data

Database

Unicode is supported by DDS and SQL. In SQL it needs to be declared as GRAPHIC or VARGRAPHIC with a corresponding CCSID. In DDS unicode field needs the graphic data type (G) and a corresponding CCSID, 1200 or 13488.

Program

At the program level the variables need to be defined with a corresponding 'CCSID' keyword.

  dcl-s buffer char(1048576) ccsid(*utf8);
If the value should be moved to a graphic field in the display file then it value assignment to the display file field may result into a conversion error. A workaround for this is using a ucs2 field in the RPG program and move that value to the display file graphic type field.

Printer File

The fields in the record needs the data type GRAPHIC (G) and a corresponding CCSID, 1200 or 13488).

As the same printer file is used for multiple languages a unicode field is configure (with GRAPHIC data type) we don't want to convert the data to the CCSID of the printer file so we neet to add the parameter *NOCONVERT.

     A          R I18NEXPR1
     A            LINE          60G        3SPACEB(1)
     A                                      FONTNAME('Verdana'
     A                                      (*POINTSIZE 12.0))
     A                                      CCSID(13488 *NOCONVERT)

The printer file needs *AFPDS as the device type and for testing we want to create a PDF from it.

  CHGPRTF FILE(I18NEXP1) DEVTYPE(*AFPDS) TOSTMF('/home/mihael/unicode-test.pdf') WSCST(*PDF)

Font

And now comes the tricky part. The font also needs to have a glyph for the unicode characters we used. So first a font with unicode characters is needed and the system has some requirements to it.

There are several pages in the IBM Knowledge Center about it.

I ended up put a true type font file into a folder in the IFS , /usr/local/fonts/ttf/ , and put that path to the env var with the following command:

  ADDENVVAR ENVVAR(QIBM_FONT_RESOURCES_PATH) VALUE('/usr/local/fonts/ttf')
You can probably also put the font into /QIBM/UserData/OS400/Fonts/TTFonts/ but I like to keep my system clean and separate my stuff from the system stuff.
Not every TrueType font file can be used. There are some requirements on the file, see “Specifying a TrueType or OpenType font”.