Show TOC Start of Content Area

This graphic is explained in the accompanying text Print Text as Left-Justified Graphic  Locate the document in its SAP Library structure

In this example, the printer is in Graphic mode and prints the drawn text on the left side of the page. The program performs the following steps:

...

       1.      Opens the connection to the printer.

       2.      Calculates the bottom of the page using the page and font metrics.

       3.      Draws the text on the bottom left corner of the page.

       4.      Closes the connection to the printer.

 

package test;

 

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

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

 

public class TextLeftGraphicMode {

 

   public static void main(String[] args) {

      float xLeft = 0, yBottom = 0;

      String sText="This text is on the left and bottom of the page.";

        

   GraphicPrinter gP = null;

      try{

        

         Connector conn = Connector.getInstance();

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

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

         params.setPrinterMode(PrinterParameters.GRAPHIC_MODE);

     

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

         gP = (GraphicPrinter) conn.open(params);

        

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

         PrinterFont pF = gP.getFont(sFonts[0]);

 

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

         yBottom = gP.getPageMetrics().getHeight() - pF.getMetrics(sText).getHeight() - 10;

        

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

         gP.drawText(pF, xLeft, yBottom, sText, GraphicPrinter.NO_ROTATION);

         gP.doPrint(1);

        

      }

      catch (Throwable error){

         error.printStackTrace();

      } finally {

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

         try {

            gP.close();

         } catch (Exception ex) {}

   }

      return;

   }

}

 

End of Content Area