Show TOC Start of Content Area

This graphic is explained in the accompanying text Add/Remove a Font Using the Client API  Locate the document in its SAP Library structure

In this example, the printer is in Line mode and adds a font configuration, prints a report, and removes the font configuration. It adds and removes the Batang font to the Peripheral Input/Output Service (PIOS) infrastructure using the Client API.

Note

The font configuration added must map to an existing font in the printer.

The program performs the following steps:

...

       1.      Opens connection to the printer.

       2.      Adds the font configuration.

       3.      Sets the parameters for the font configuration and saves the changes.

       4.      Closes and reopens the connection to the printer for the font configuration to take effect.

       5.      Prints a sample text.

       6.      Deletes the font configuration and saves the changes.

       7.      Closes the connection to the printer.

Note

Ensure that you have configured the Emulator or printer accordingly.

 

package test;

 

import com.sap.ip.me.api.pios.connection.*;

import com.sap.ip.me.api.pios.printer.*;

import com.sap.ip.me.api.pios.configuration.*;

 

public class AddFont {

 

   public static void main(String[] args) {

     

      LinePrinter lP = null;

      try{

         Connector conn = Connector.getInstance();

         DriverInfo[] driverInfo = conn.listDrivers(ConnectionType.PRINTER);

         PrinterParameters params = new PrinterParameters(driverInfo[0]);

         params.setPrinterMode(PrinterParameters.LINE_MODE);

     

         //----------------------(1)--------------------

         lP = (LinePrinter) conn.open(params);

        

         //----------------------(2)--------------------

         String sFont = "Batang";

         FontConfigurationManager fCM = lP.getFontConfigurationManager();

         fCM.addFontConfiguration(sFont);

         Configuration conf = fCM.getFontConfiguration(sFont);

 

         //----------------------(3)--------------------

         conf.setParameterValue("Size", "14");

         conf.setParameterValue("Options", "0");

         conf.setParameterValue("Name", "Batang");

         conf.setParameterValue("Description", "customfont");

         conf.setParameterValue("FontType", "2");

         fCM.save();

 

         //----------------------(4)--------------------

         lP.close();

         lP = (LinePrinter) conn.open(params);

        

         String[] sFonts = lP.getFontConfigurationManager().listFontNames();

 

         //----------------------(5)--------------------         

         PrinterFont pF = lP.getFont(sFont);

         lP.printText(pF, "", LinePrinter.NO_ALIGNMENT);

         lP.printText(pF, " This is a Batang test string.", LinePrinter.NO_ALIGNMENT);

         pF = lP.getFont(sFonts[1]);

         lP.printText(pF, " This is a regular test string.", LinePrinter.NO_ALIGNMENT);

         lP.doPrint(1);

 

         //----------------------(6)--------------------

         fCM.deleteFontConfiguration(sFont);

         fCM.save();

 

      } catch (Throwable error){

         error.printStackTrace();

      } finally {

         //----------------------(7)--------------------

         try {

            lP.close();

         } catch (Exception ex) {}

      }

      return;

   }

}

 

End of Content Area