Class QRBill


  • public class QRBill
    extends java.lang.Object
    Generates Swiss QR bill payment part.

    Can also validate the bill data and encode and decode the text embedded in the QR code.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double A4_PORTRAIT_HEIGHT
      The height of an A4 sheet in portrait orientation, in mm
      static double A4_PORTRAIT_WIDTH
      The width of an A4 sheet in portrait orientation, in mm
      static double QR_BILL_HEIGHT
      The height of a QR bill (payment part and receipt), in mm
      static double QR_BILL_WIDTH
      The width of a QR bill (payment part and receipt), in mm
      static double QR_BILL_WITH_HORI_LINE_HEIGHT
      The height of a QR bill with horizontal separator line (payment part and receipt plus space for line and scissors), in mm
      static double QR_BILL_WITH_HORI_LINE_WIDTH
      The width of a QR bill with horizontal separator line (payment part and receipt plus space for line and scissors), in mm
      static double QR_CODE_HEIGHT
      The height of the QR code, in mm
      static double QR_CODE_WIDTH
      The width of the QR code, in mm
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Bill decodeQrCodeText​(java.lang.String text)
      Decodes the text embedded in the QR code and fills it into a Bill data structure.
      static void draw​(Bill bill, Canvas canvas)
      Draws the QR bill (payment part and receipt) or QR code for the specified bill data onto the specified canvas.
      static void drawSeparators​(SeparatorType separatorType, boolean withHorizontalLine, Canvas canvas)
      Draws the separator line(s) to the specified canvas.
      static java.lang.String encodeQrCodeText​(Bill bill)
      Encodes the text embedded in the QR code from the specified bill data.
      static byte[] generate​(Bill bill)
      Generates a QR bill (payment part and receipt) or QR code as an SVG image or PDF document.
      static ValidationResult validate​(Bill bill)
      Validates and cleans the bill data.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • A4_PORTRAIT_WIDTH

        public static final double A4_PORTRAIT_WIDTH
        The width of an A4 sheet in portrait orientation, in mm
        See Also:
        Constant Field Values
      • A4_PORTRAIT_HEIGHT

        public static final double A4_PORTRAIT_HEIGHT
        The height of an A4 sheet in portrait orientation, in mm
        See Also:
        Constant Field Values
      • QR_BILL_WIDTH

        public static final double QR_BILL_WIDTH
        The width of a QR bill (payment part and receipt), in mm
        See Also:
        Constant Field Values
      • QR_BILL_HEIGHT

        public static final double QR_BILL_HEIGHT
        The height of a QR bill (payment part and receipt), in mm
        See Also:
        Constant Field Values
      • QR_BILL_WITH_HORI_LINE_WIDTH

        public static final double QR_BILL_WITH_HORI_LINE_WIDTH
        The width of a QR bill with horizontal separator line (payment part and receipt plus space for line and scissors), in mm
        See Also:
        Constant Field Values
      • QR_BILL_WITH_HORI_LINE_HEIGHT

        public static final double QR_BILL_WITH_HORI_LINE_HEIGHT
        The height of a QR bill with horizontal separator line (payment part and receipt plus space for line and scissors), in mm
        See Also:
        Constant Field Values
      • QR_CODE_WIDTH

        public static final double QR_CODE_WIDTH
        The width of the QR code, in mm
        See Also:
        Constant Field Values
      • QR_CODE_HEIGHT

        public static final double QR_CODE_HEIGHT
        The height of the QR code, in mm
        See Also:
        Constant Field Values
    • Method Detail

      • validate

        public static ValidationResult validate​(Bill bill)
        Validates and cleans the bill data.

        The validation result contains the error and warning messages (if any) and the cleaned bill data.

        For details about the validation result, see Bill data validation

        Parameters:
        bill - bill data
        Returns:
        validation result
      • draw

        public static void draw​(Bill bill,
                                Canvas canvas)
        Draws the QR bill (payment part and receipt) or QR code for the specified bill data onto the specified canvas.

        The QR bill or code are drawn at position (0, 0) extending to the top and to the right. Typically, the position (0, 0) is the bottom left corner of the canvas.

        This methods ignores the formatting properties bill.getFormat().getFontFamily() and bill.getFormat().getGraphicsFormat(). They can be set when the canvas instance passed to this method is created.

        If the bill data does not validate, a QRBillValidationError is thrown, which contains the validation result. For details about the validation result, see Bill data validation

        The canvas will be initialized with Canvas#setupPage and it will be closed before returning the generated QR bill

        Parameters:
        bill - the bill data
        canvas - the canvas to draw to
        Throws:
        QRBillValidationError - thrown if the bill data does not validate
      • drawSeparators

        public static void drawSeparators​(SeparatorType separatorType,
                                          boolean withHorizontalLine,
                                          Canvas canvas)
        Draws the separator line(s) to the specified canvas.

        The separator lines are drawn assuming that the QR bill starts at position (0, 0) and extends the top and right. So position (0, 0) should be in the bottom left corner.

        This method allows to add separator lines to an existing QR bill, e.g. on to an archived QR bill document.

        Parameters:
        separatorType - type of separator lines
        withHorizontalLine - true if both the horizontal or vertical separator should be drawn, false for the vertical separator only
        canvas - the canvas to draw to
      • encodeQrCodeText

        public static java.lang.String encodeQrCodeText​(Bill bill)
        Encodes the text embedded in the QR code from the specified bill data.

        The specified bill data is first validated and cleaned.

        If the bill data does not validate, a QRBillValidationError is thrown, which contains the validation result. For details about the validation result, see Bill data validation

        Parameters:
        bill - the bill data to encode
        Returns:
        the QR code text
        Throws:
        QRBillValidationError - thrown if the bill data does not validate
      • decodeQrCodeText

        public static Bill decodeQrCodeText​(java.lang.String text)
        Decodes the text embedded in the QR code and fills it into a Bill data structure.

        A subset of the validations related to embedded QR code text is run. It the validation fails, a QRBillValidationError is thrown, which contains the validation result. See the error messages marked with a dagger in Bill data validation.

        Parameters:
        text - the text to decode
        Returns:
        the decoded bill data
        Throws:
        QRBillValidationError - thrown if the bill data does not validate