Class QRBill

java.lang.Object
net.codecrete.qrbill.generator.QRBill

public class QRBill extends 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 Details

  • Method Details

    • 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
    • generate

      public static byte[] generate(Bill bill)
      Generates a QR bill (payment part and receipt) or QR code as an SVG image or PDF document.

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

      The graphics format is specified with bill.getFormat().setGraphicsFormat(...). This method only supports the generation of SVG images and PDF files. For other graphics formats (in particular PNG), use draw(net.codecrete.qrbill.generator.Bill, net.codecrete.qrbill.canvas.Canvas)

      Parameters:
      bill - the bill data
      Returns:
      the generated QR bill (as a byte array encoded in the specified graphics format)
      Throws:
      QRBillValidationError - thrown if the bill data does not validate
      See Also:
    • 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 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(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. If 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