...
...
...
...
HTML Comment | ||
---|---|---|
| ||
REMEMBER! A template can not currently be reapplied. If you want to start over, you'll need to create a new page. Not everything in this template will be used for every API page, it's meant to be a quick format setup. Content can be added and removed as needed after filling out what you want of the form and clicking 'Next', which takes you to the editor. Be aware of where you are putting the page! If you put it in the wrong place, you can go to http://www.profoundlogic.com/docs/pages/listpages-dirview.action?key=PUI and drag'n'drop it at the proper place in the tree. Some of the columns have odd widths, widths are just suggestions in confluence for some reason. If two columns have the same width, they will take up equal-ish space. Any questions on how to use a template, feel free to ask Megan. All HTML notes can be deleted or changed as needed. Everything can be copied and pasted as needed. EXAMPLE OF FINISHED PAGE: pjs.query() |
...
width | 60% |
---|
API Overview
The pjs.definePrinter() API defines a printer file in the calling scope, defines the file's record formats and fields, and creates a file instance that can be used to perform operations on the file.
When output is specified as "pdf", the report is generated using the pdfmake npm package. When output is specified as "html", and HTML document is generated. Otherwise, an IBM i printer file is used and the report is written to a spooled file.
Note |
---|
This API serves the same purpose as an RPG printer file specification and/or output specifications (for program described printer files). |
...
width | 40% |
---|
Contents
Info | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||
|
HTML Comment | ||
---|---|---|
| ||
This column is for a table of contents or notice. If neither are needed, delete this column. If only one is needed, delete the other. If more are needed, you can add what you like, remember to check how long it becomes by clicking "Preview" in the bottom right corner. While preview, the page should be checked at half page and maximize to check that the formatting is not distorted. You may need to make some adjustments to compensate. An example of good Table of Contents usage is the pjs.query page. |
RPG Equivalent
PRINTER file specification
Warning | ||
---|---|---|
| ||
This API requires the Profound.js Connector module. |
Parameters
- Internal name - A String containing the desired internal file name. A variable of this name will be defined in the calling script and will be populated with a record file instance. I/O operations are then performed by calling file-specific API.
- External name (optional) - A String specifying the external name of the file object. The name can optionally be qualified with a library. If the library is not specified, then the library list is used to resolve the file. If the external name is not specified, then the internal name is used instead. This parameter can be omitted; in this case, the file configuration is passed for parameter 2. This parameter can also be specified as an Object with the following properties in order to implement dynamic external file names:
- field - The name of a declared character field that hold the external file object name
- extDesc (optional) - The name of the file object to use for file discovery before the file is opened and before the field is declared. If omitted, the internal name is used.
- File configuration (optional) - An Object that sets file options using the property names / values shown below. If the external file name parameter is omitted, then the configuration should be passed as parameter 2. The file configuration can be passed inline or stored in an external JSON file and retrieved using the pjs.require() API.
...
...
...
...
Set to True to enable user-controlled file open / close using the file.open() and file.close() methods. Otherwise the file will be opened automatically before this method returns and closed automatically when the calling function ends.
...
Defines a prefix that will be used to partially rename all the fields of the externally defined printer file. This property can be defined in 2 different ways.
- As an object of the following format:
{
"numberOfCharsToReplace": nn, //numeric value indicating the number of characters, if any, in the existing field names to replace with the prefix
"prefix": "xxxx" //string prefix value. If numberOfCharsToReplace is not defined or is 0, then the prefix is appended to the beginning of the field names
} As a string value that will be appended to the beginning of the field names.
...
Object containing field names to rename. The field names are given as properties of this object and their new names as values of these properties.
For example:
{
"field1": "newField1",
"field2": "newField2"
}
If a prefix is defined, the renameFields object properties must be defined with the prefix in place in order for those fields to be renamed.
For example, if the property prefix is defined as string "EX", then renameFields might look like this:
{
"EXfield1": "newField1",
"EXfield2": "newField2"
}
...
Set to the name of an indicator that will be set on when the printer file's overflow line has been printed on. For example, '*inoa', or '*in01', or 'overflow'.
...
...
RPG Equivalent
PRINTER file specification
Warning |
---|
Important! This API requires the Profound.js Connector module. |
Parameters
Internal name - A String containing the desired internal file name. A variable of this name will be defined in the calling script and will be populated with a record file instance. I/O operations are then performed by calling file-specific API.
External name (optional) - A String specifying the external name of the file object. The name can optionally be qualified with a library. If the library is not specified, then the library list is used to resolve the file. If the external name is not specified, then the internal name is used instead. This parameter can be omitted; in this case, the file configuration is passed for parameter 2. This parameter can also be specified as an Object with the following properties in order to implement dynamic external file names:
field - The name of a declared character field that hold the external file object name
extDesc (optional) - The name of the file object to use for file discovery before the file is opened and before the field is declared. If omitted, the internal name is used.
File configuration (optional) - An Object that sets file options using the property names / values shown below. If the external file name parameter is omitted, then the configuration should be passed as parameter 2. The file configuration can be passed inline or stored in an external JSON file and retrieved using the pjs.require() API.
Element name | Element type | Description | ||||
---|---|---|---|---|---|---|
userOpen | Boolean | Set to True to enable user-controlled file open / close using the file.open() and file.close() methods. Otherwise the file will be opened automatically before this method returns and closed automatically when the calling function ends. | ||||
infDS | String | Name of a File Information data structure which will be populated with feedback information after each file method call. The data structure must be defined in the calling scope using pjs.define(). | ||||
qualified | Boolean | Set to True to qualify field names with the internal file and record format names | ||||
include | Array | A list of record formats to define in the calling scope. If omitted, all record format names are included. | ||||
ignore | Array | A list of record formats to ignore. If omitted, all record format names are included. | ||||
rename | Object | A list of record formats to rename. The record format name given by each object property is set to the name given in the corresponding value. | ||||
likeFile | String | The internal name of another file defined using this method in the calling scope. This defines another instance of the file using the same configuration options. | ||||
levelIds | Array | A list of level identifiers for each record format in the file. If specified, record format level checks are performed before opening the file. Otherwise, no level checks are done. | ||||
prefix | Object / String | Defines a prefix that will be used to partially rename all the fields of the externally defined printer file. This property can be defined in 2 different ways.
| ||||
template | Boolean | If set to True, the the declared file cannot be opened and used for I/O, but its record formats and fields can be used as templates for field definitions by using the options 'like', 'likeRec', and 'extName' with pjs.define(). | ||||
static | Boolean | If set to True, the file will hold its state across calls to the function. If the file is open when the function, then the file will still be open on the next call to the function. | ||||
alias | Boolean | If set to True, the alias (alternate) names will be used, if present, for the fields associated with the file and also for subfield names in data structures defined with the 'likeRec' option. | ||||
renameFields | String | Object containing field names to rename. The field names are given as properties of this object and their new names as values of these properties. For example:
If a prefix is defined, the renameFields object properties must be defined with the prefix in place in order for those fields to be renamed. For example, if the property prefix is defined as string "EX", then renameFields might look like this:
| ||||
overflowIndicator | String | Set to the name of an indicator that will be set on when the printer file's overflow line has been printed on. For example, '*inoa', or '*in01', or 'overflow'. | ||||
recordLength | Number | Record length, for program described printer files. | ||||
output | String | Specifies whether the output is written to a PDF file, and HTML file, or a spooled file on IBM i. Specify "pdf", "html", or omit the property for spooled file output. Generated PDF and HTML go into the “reports” directory in the profoundjs installation directory. | ||||
outputFileName | String | Specifies the desired name of the resulting PDF or HTML file | ||||
orientation | String | For PDF output, specifies the file orientation. Valid values are "landscape" and "portrait". | ||||
pageMargin (optional) | Object / Number | Specify page margins to be used for the resulting pdf according to the “unitOfMeasurement” option used. When not defined, the page margins default to 0.55 inches (1.4 cm) on all sides. Accepts the following values or properties:
This element corresponds to IBMI’s FRONTMGN setting for the CRTPRTF command. | ||||
printControl | String | Name of Print Control (PRTCTL) compatible (*COMPAT) data structure. The data structure must be defined in the calling scope using pjs.define(). | ||||
printControlExtended | String | Name of Print Control (PRTCTL) extended data structure. The data structure must be defined in the calling scope using pjs.define(). |
...
defaultLinesPerInch | Number | For PDF output, specifies the number of lines which will fill an inch. |
unitOfMeasurement | String |
...
Specifies the unit of measurement that should be used. Set to either “inch“ or “cm”. Defaults to “inch” | ||
records | Array | Array of record definition objects, for program described printer files. Record definition objects can have the following properties:
|
...
|
...
|
...
|
...
|
...
|
...
|
...
For PDF output, fields can also implement the following properties:
...
For PDF output, fields can also implement the following properties:
| ||||||||
preciseDecimal | Boolean/Number | Overrides the global preciseDecimal configuration option for packed/zoned fields defined by this printer file definition. |
Exception Handling
An Error instance will be thrown with the following properties:
message - The IBM i message text.
error - The message id.
help - The message help text.
Examples
...
...
Using a Program Described Printer File
Code Block | ||
---|---|---|
| ||
function print() {
pjs.definePrinter("print", { overflowIndicator: '*inoa',
recordLength: 80,
records:
[ { name: 'header',
skipBefore: 1,
spaceAfter: 2,
fields:
[ { pos: 44, text: 'Products' },
{ pos: 74, text: 'Page:' },
{ pos: 79, name: 'page' } ] },
{ name: 'header',
fields:
[ { pos: 10, text: 'Product Id' },
{ pos: 24, text: 'Product Name' },
{ pos: 52, text: 'Price' } ] },
{ name: 'detail',
fields:
[ { pos: 10, name: 'prid', editCode: '4' },
{ pos: 42, name: 'pname' },
{ pos: 52, name: 'pprice', editCode: 'N' } ] } ] });
pjs.defineTable("prodp", { read: true, levelIds: [ '5013DF66AFB6C' ] });
print.header.write();
prodp.fetchNext();
while (!pjs.endOfData()) {
if (flags["OA"]) {
print.header.write();
}
print.detail.write();
prodp.fetchNext();
}
flags["LR"] = true;
}
exports.run = print; |
...
...
Using an externally described printer file
Code Block | ||
---|---|---|
| ||
function prog022() {
pjs.defineTable("csinvp", { read: true, levelIds: [ '489DD34AB5BB7' ] });
pjs.definePrinter("prog022p", { overflowIndicator: 'overflow', levelIds: [ '0090601C4E281', '1AF341D602698' ] });
prog022p.heads.write();
csinvp.fetchNext();
while (!csinvp.endOfData()) {
if (overflow) {
prog022p.heads.write();
}
prog022p.detail.write();
csinvp.fetchNext();
}
flags["LR"] = true;
}
exports.run = prog022; |
Using pjs.definePrinter() to generate a PDF
Download the example files below. Specify the "output": "pdf" property. The report definitions are in a separate JSON file for your convenience. This allows you to open it in the Visual Designer using Preview Mode, as shown in the screenshot below.
...
...
title | example files |
---|
...
Example Files
Attachments | ||||||
---|---|---|---|---|---|---|
|