Class ViewPrintJob

  • All Implemented Interfaces:
    Direct Known Subclasses:

    public class ViewPrintJob
    extends PrintJob
    implements Parcelable
    Create a PrintJob from a given View. The performs blocking IO so it must be invoked on a background thread.

    The View used need not be displayed on screen but it must be laid out and measured first beforehand. For that reason ViewPrintJob.Builder.view(View, int) is now the preferred method to build an instance of this job since that method ensures layout and measurement happens.

    The width of the view should almost always be equal to the printer head width which can be obtained like so:

     PrinterConnector pc = new PrinterConnector(context, CloverAccount.getAccount(context), null);
     List printerList = pc.getPrinters(Category.RECEIPT);
     if (printerList.size() > 0) {
          Printer preferredPrinter = printerList.get(0);
          TypeDetails typeDetails = pc.getPrinterTypeDetails(preferredPrinter);
          int width = typeDetails.getNumDotsWidth();