D.1. Check Format Files (*.chk)

D.1.1. Overview

The check format file is used to tell gnucash how to print a check or checks onto a page of paper. This file first describes the overall layout of a page (number of checks, orientation, etc) and then describes the layout of the specific items on a single check. The file is organized as a typical Key/Value file used by many Linux applications. Keys/values pairs are grouped into sections that begin with the group name enclosed in square brackets.

GnuCash looks for check format files in two different locations when you bring up the check printing dialog. The first location is typically /usr/share/gnucash/checks, where check files distributed with the application can be found. The second location is the user private ~/.gnucash/checks directory. Users may add check formats at any time (even while GnuCash is running) simply by dropping a new *.chk file in this directory. The next time the check printing dialog is opened the new check format will appear in the list of available check formats.

注意

Printing functions differently depending on the version of GTK that is installed on your system. When GnuCash is using a version of GTK prior to 2.10 all offsets are measured from the lower left corner of the page or check. When using GTK 2.10 or later, all offsets are measured from the upper left corner of the page or check.

D.1.2. Example file

A typical GnuCash check file is presented below. The contents of this file will be described in the next sections.

[Top]
Guid = 67b144d1-96a5-48d5-9337-0e1083bbf229
Title = Quicken/QuickBooks (tm) US-Letter
Rotation = 0.0
Translation = 0.0;4.0
Show_Grid = false
Show_Boxes = false

[Check Positions]
Height = 252.0
Names = Top;Middle;Bottom

[Check Items]
Type_1 = PAYEE
Coords_1 = 90.0;102.0;400.0;20.0

Type_2 = AMOUNT_WORDS
Coords_2 = 90.0;132.0

Type_3 = AMOUNT_NUMBER
Coords_3 = 500.0;102.0

Type_4 = DATE
Coords_4 = 500.0;67.0

Type_5 = NOTES
Coords_5 = 50.0;212.0
        

D.1.3. Field Descriptions

D.1.3.1. Top Group

This section of the check file describes the overall layout of a page of checks (or check) that goes into the printer.

表 D.1. Overall Page Description Fields

NameTypeRequiredDescription
GuidstringmandatoryThe guid is used to uniquely identify a check format to GnuCash. It must be unique across the entire set of application supplied and user supplied check formats. If you copy an application check file as the basis of your own check format, you must change this value. The uuidgen program may be used to generate these identifiers.
TitlestringmandatoryThe title is used to uniquely identify a check format to the user. This value is presented verbatim in the check format list of the check printing dialog. If you copy an application check file as the basis of your own check format, you should change this value. The title may be any utf-8 string.
FontstringoptionalIf supplied, this is the default font used to print all text items on this check. This field can contain any string that is acceptable by gtk as a font specifier. If this field is omitted, the default font is the font specified in the GnuCash preferences dialog. A typical string would be "sans 12".
RotationdoubleoptionalThis value specified the rotation of the entire page (in degrees) around the origin point. For gtk versions prior to 2.10, the origin point is in the lower left corner of the page and rotation values increase in the counter-clockwise direction. For gtk version 2.10 and later, the origin point is in the upper left corner of the page and rotation values increase in the clockwise direction. Rotation of the page is applied before translation.
Translationlist of 2 doublesoptionalThese values specify the x and y translation of the entire page (in points) relative to the origin point. For gtk versions prior to 2.10, the origin point is in the lower left corner of the page and translation values increase moving up and to the right. For gtk version 2.10 and later, the origin point is in the upper left corner of the page and translation values increase moving down and to the right. Rotation of the page is applied before translation.
Show_GridbooleanoptionalIf this value is set to true then GnuCash will draw a grid on the page, starting at the origin with the lines spaced every 50 points. This can be helpful when creating a check format file.
Show_BoxesbooleanoptionalIf this value is set to true then for each item where the width and height have been specified, GnuCash will draw a box showing location and maximum size of that item . This can be helpful when creating a check format file.

D.1.3.2. Check Positions Group

This group of items specifies how multiple checks are laid out on the same sheet of paper, and gives names to each of these check locations so that a user can specify which check location that GnuCash should print. This entire group of key/value pairs is optional, and should be omitted if the format file only specifies a single check per page of paper.

表 D.2. Multiple Checks Per Page Fields

NameTypeRequiredDescription
HeightdoublemandatoryThis field specifies the height of a single check on the page. If there are multiple checks per page then this item is mandatory. If there is only a single check per page, this entire section should be omitted.
Nameslist of stringsmandatoryThis field specifies the names of the check locations that can be printed on each page. These names represent the check positions starting from the top of the page and moving downward. The names are presented verbatim in the check position list of the check printing dialog. A typical value for this field is "Top;Middle;Bottom", but it could also be "First;Second;Third" or any other set of strings that clearly identify the check locations. If there are multiple checks per page then this item is mandatory. If there is only a single check per page, this entire section should be omitted.

D.1.3.3. Check Items Group

This section specifies the individual items that are printed on the check. There is no limit to the number of items that may be present in this section, and any given type of item can be repeated multiple times. This allows for the printing of checks that have a side stub, or for the one-per-page business checks that have both the check and multiple check stubs on the same page. For example, to print the payee name on a business check and on both stubs, simply specify three payee items with differing print coordinates.

Each key names in this section explicitly includes the item number to which it applies. E.G. The key named Type_1 applies to the first item to be printed, and the key Coords_3 applies to the third item to be printed. Item numbers start at one and increase sequentially. Any gap in the numbering sequence is interpreted by GnuCash as the end of the item list. Items are printed in the order of their item numbers, not in the order in which they appear in the file.

Each item specified must include a type declaration. The rest of the parameters for that item depend upon the particular type of that item. See 表 D.4 for a list of valid item types and their required parameters.

表 D.3. Individual Check Item Fields

NameTypeRequiredDescription
Type_nstringmandatoryThis field specifies the type of a single item to be printed on a check. See 表 D.4 for a list of valid item types.
Coords_nlist of 2 or 4 doublesmandatoryThis field specifies the coordinates where the item should be placed on a check, and optionally also specifies the width and height of the item. The numbers in order are the X and Y offset of the lower left corner of the item, and optionally the width and height of the item. If the width is supplied then the height must also be supplied, so this field will always contain two or four numbers. For gtk versions prior to 2.10, the origin point is in the lower left corner of the page and translation values increase moving up and to the right. For gtk version 2.10 and later, the origin point is in the upper left corner of the page and translation values increase moving down and to the right.
注意
Regardless of whether the origin is at the top or the bottom of the page, the coordinates always specify the lower left point of the item.
Font_nstringoptionalIf supplied, this is the font used to print this specific text item. This field can contain any string that is acceptable by gtk as a font specifier. If this field is omitted, the default font is the font specified in the Top section of the check description file, or if that was omitted the font specified in the GnuCash preferences dialog. This field is only recognized when using gtk version 2.10 or later.
Align_nstringoptionalIf supplied, this is the alignment used to print this specific text item. This field must contain one of the strings "left", "center" or "right". If this field is omitted, the text will be left aligned. This field is only recognized when using gtk version 2.10 or later.
Text_nstringoptionalThis field is only used when the item type is TEXT. It specifies the utf-8 text that should be printed on the check.
Filename_nstringoptionalThis field is only used when the item type is PICTURE. It specifies the filename of the image that should be printed on the check. The string may specify either an absolute path name or as a relative path name. If a relative path name is specified, GnuCash first looks in in the application check format folder (typically /usr/share/gnucash/checks) for the image file, and if it isn't found there then it looks in the user private ~/.gnucash/checks directory for the image. This field is only recognized when using gtk version 2.10 or later.

These are the individual items that can be printed on a check. All items require the coordinates on the page where the item should be printed. The majority of these items result in text being printed on the page, and these items may have individual font and alignments specified. For example, the numerical amount of a check could be printed right justified while everything else is printed left justified. Other types may have unique parameters.

表 D.4. Individual Check Item Types

NameRequired ValuesOptional ValuesDescription
PAYEECoordsFont, AlignThis type value tells gnucash to print the check payee name at the specified coordinates.
DATECoordsFont, AlignThis type value tells gnucash to print the check date at the specified coordinates.
NOTES.CoordsFont, AlignThis type value tells gnucash to print the transaction notes field at the specified coordinates.
CHECK_NUMBERCoordsFont, AlignThis type value tells gnucash to print the check number at the specified coordinates.
MEMOCoordsFont, AlignThis type value tells gnucash to print the split memo field at the specified coordinates.
ACTIONCoordsFont, AlignThis type value tells gnucash to print the split action field at the specified coordinates.
AMOUNT_WORDSCoordsFont, AlignThis type value tells gnucash to print the check amount in words at the specified coordinates. The amount will appear similar to the string "One thousand, two hundred thirty four and 56/100".
AMOUNT_NUMBERCoordsFont, AlignThis type value tells gnucash to print the check amount in numbers at the specified coordinates. The amount will appear similar to the number "$1,234.56".
TEXTCoords, TextFont, AlignThis type value tells gnucash to print an arbitrary string at the specified coordinates. The string to be printed is specified with the Text_n key.
PICTURECoords, Filename(none)This type value tells gnucash to print an image at the specified coordinates. The image to be printed is specified with the Filename_n key. This type is only recognized when using gtk version 2.10 or later.

D.1.4. Creating Check Format Files

Creating your own check format file is a fairly simple task. The easiest way to start is to copy an existing check format file from the application directory (typically /usr/share/gnucash/checks) to the directory ~/.gnucash/checks. Make sure to change the guid so the new file will be accepted by gnucash, and change the title to something descriptive. Then change or add individual item fields as necessary. You can also create a new check file by clicking the Save Format button on the "Custom format" page of the check printing dialog.

注意

Key names are case sensitive. If you're having problems with a check format file, ensure that all key names start with a capital letter and the rest of the name is in lower case.