Class QRBill
- java.lang.Object
-
- net.codecrete.qrbill.generator.QRBill
-
public class QRBill extends java.lang.ObjectGenerates 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 doubleA4_PORTRAIT_HEIGHTThe height of an A4 sheet in portrait orientation, in mmstatic doubleA4_PORTRAIT_WIDTHThe width of an A4 sheet in portrait orientation, in mmstatic doubleQR_BILL_HEIGHTThe height of a QR bill (payment part and receipt), in mmstatic doubleQR_BILL_WIDTHThe width of a QR bill (payment part and receipt), in mmstatic doubleQR_BILL_WITH_HORI_LINE_HEIGHTThe height of the output format with extra space for horizontal separator line (payment part and receipt plus space for line and scissors), in mmstatic doubleQR_BILL_WITH_HORI_LINE_WIDTHThe width of the output format with extra space for horizontal separator line (payment part and receipt plus space for line and scissors), in mmstatic doubleQR_CODE_HEIGHTThe height of the QR code, in mmstatic doubleQR_CODE_WIDTHThe width of the QR code, in mm
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BilldecodeQrCodeText(java.lang.String text)Decodes the text embedded in the QR code and fills it into aBilldata structure.static voiddraw(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 voiddrawSeparators(SeparatorType separatorType, boolean withHorizontalLine, Canvas canvas)Draws the separator line(s) to the specified canvas.static java.lang.StringencodeQrCodeText(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 java.lang.StringgetLibraryVersion()Returns this library's versionstatic ValidationResultvalidate(Bill bill)Validates and cleans the bill data.
-
-
-
Field Detail
-
A4_PORTRAIT_WIDTH
public static final double A4_PORTRAIT_WIDTH
The width of an A4 sheet in portrait orientation, in mm
-
A4_PORTRAIT_HEIGHT
public static final double A4_PORTRAIT_HEIGHT
The height of an A4 sheet in portrait orientation, in mm
-
QR_BILL_WIDTH
public static final double QR_BILL_WIDTH
The width of a QR bill (payment part and receipt), in mm- See Also:
OutputSize.QR_BILL_ONLY, 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:
OutputSize.QR_BILL_ONLY, Constant Field Values
-
QR_BILL_WITH_HORI_LINE_WIDTH
public static final double QR_BILL_WITH_HORI_LINE_WIDTH
The width of the output format with extra space for horizontal separator line (payment part and receipt plus space for line and scissors), in mm
-
QR_BILL_WITH_HORI_LINE_HEIGHT
public static final double QR_BILL_WITH_HORI_LINE_HEIGHT
The height of the output format with extra space for horizontal separator line (payment part and receipt plus space for line and scissors), in mm
-
QR_CODE_WIDTH
public static final double QR_CODE_WIDTH
The width of the QR code, in mm- See Also:
OutputSize.QR_CODE_ONLY, Constant Field Values
-
QR_CODE_HEIGHT
public static final double QR_CODE_HEIGHT
The height of the QR code, in mm- See Also:
OutputSize.QR_CODE_ONLY, 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
-
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
QRBillValidationErroris thrown, which contains the validation result. For details about the validation result, see Bill data validationThe 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), usedraw(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(net.codecrete.qrbill.generator.Bill, net.codecrete.qrbill.canvas.Canvas)
-
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()andbill.getFormat().getGraphicsFormat(). They can be set when the canvas instance passed to this method is created.If the bill data does not validate, a
QRBillValidationErroris thrown, which contains the validation result. For details about the validation result, see Bill data validationThe canvas will be initialized with
Canvas#setupPageand it will be closed before returning the generated QR bill- Parameters:
bill- the bill datacanvas- 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 lineswithHorizontalLine-trueif both the horizontal or vertical separator should be drawn,falsefor the vertical separator onlycanvas- 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
QRBillValidationErroris 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 aBilldata structure.A subset of the validations related to embedded QR code text is run. It the validation fails, a
QRBillValidationErroris 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
-
getLibraryVersion
public static java.lang.String getLibraryVersion()
Returns this library's version- Returns:
- version in semantic versioning format (major.minor.patch).
-
-