You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-94Lines changed: 54 additions & 94 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,118 +18,86 @@ See [Getting Started](https://cap.cloud.sap/docs/get-started) on how to jumpstar
18
18
19
19
Usage of this plugin requires a valid subscription of the [SAP Print Service](https://help.sap.com/docs/SCP_PRINT_SERVICE).
20
20
21
-
To integrate the print functionality in your application, simply annotate any action with `@print`. This annotation automatically manages the process of sending documents to the print queues, requiring no additional setup for handling print jobs.
21
+
## Usage
22
22
23
-
### Required Fields
23
+
To use this plugin to print documents there are two main steps:
24
24
25
-
The following three fields should be annotated with the corresponding `@print` annotations:
25
+
1. Add required annotations to your CDS model.
26
+
a. Entity
27
+
b. Action
28
+
2. Configure print queues to select from available options. (Optional, but recommended)
26
29
27
-
1.**`@print.queue`**: Specifies the queue to which the document should be sent for printing.
28
-
2.**`@print.numberOfCopies`**: Defines the number of copies to be printed.
29
-
3.**`@print.fileContent`**: Provides the file content to be printed. You can also specify the file name using the `fileNameField` property.
30
+
### Annotations in CDS model
30
31
31
-
#### Example
32
-
33
-
```cds
34
-
@print.fileContent: {
35
-
fileNameField: '<Field Name>',
36
-
}
37
-
```
38
-
39
-
Multiple fields can be annotated with `@print.fileContent` to send several documents to the print queue in a single action.
40
-
41
-
### Main Document
42
-
43
-
To designate a specific document as the primary document for printing, annotate it with `@print.MainDocument`:
32
+
#### Entity
44
33
45
-
```cds
46
-
@print.MainDocument
47
-
invoiceContent,
48
-
```
49
-
50
-
This ensures the specified document is treated as the main document when multiple documents are involved.
51
-
52
-
## Print Queue Configuration
34
+
First of all, the entity needs to be annotated to define the content and the name of the document to be printed.
53
35
54
-
You can retrieve all available print queues from the Print Service Application for selection by defining a `Queues` entity with **skip persistency**. This setup will offer a value help for the print queues, allowing users to select from available options.
55
-
56
-
### Define the `Queues` Entity
57
-
58
-
Define an entity like `Product` and associate it with the `Queues` entity as shown below:
-`@print.fileContent`: Annotates the field containing the document content to be printed.
47
+
-`@print.fileName`: Annotates the field containing the name of the document
74
48
75
-
Once the `Queues` entity is defined, specify it in the `@print.queue` annotation like so:
49
+
#### Annotation of actions
50
+
Sending a print request works via bound actions annotated with `@print`. The parameter of the action are used to define the print job details.
76
51
77
52
```cds
78
-
@print.queue: {
79
-
SourceEntity: 'Queues'
53
+
service IncidentService {
54
+
entity Incidents as projection on db.Incidents actions {
55
+
56
+
@print
57
+
action printIncidentFile(
58
+
@Common: {
59
+
ValueListWithFixedValues,
60
+
ValueList: {
61
+
$Type: 'Common.ValueListType',
62
+
CollectionPath: 'Queues',
63
+
Parameters: [{
64
+
$Type: 'Common.ValueListParameterInOut',
65
+
LocalDataProperty: qnameID,
66
+
ValueListProperty: 'ID'
67
+
}]
68
+
},
69
+
Label: 'Print Queues',
70
+
}
71
+
@print.queue
72
+
qnameID: String,
73
+
@print.numberOfCopies
74
+
@UI.ParameterDefaultValue : 1
75
+
copies: Integer
76
+
);
77
+
};
80
78
}
81
-
qName
82
79
```
83
80
84
-
### Parameterizing Print Queue in Actions
85
-
86
-
Alternatively, if the print queue is passed as a parameter in the action, you can annotate it directly within the action definition. This can be done as follows:
81
+
-`@print`: Annotates the action that triggers the print job.
82
+
-`@print.queue`: Annotates the parameter specifying the print queue. It is recommended to use a value help for this parameter to select from available print queues. See TOOD
83
+
-`@print.numberOfCopies`: Annotates the parameter specifying the number of copies to print
87
84
88
-
#### In Database Definition:
85
+
### Queues
86
+
Every print request needs to specify a print queue it is send to. It is recommended to provide a value help for the print queue selection. To enbale this, define an entity as projection on the `Queues` entity provided by the print service. When this projection is in place, the plugin automatically provides the available print queues coming from the print service.
89
87
90
88
```cds
91
-
entity Product {
92
-
qName : Association to one Queues;
93
-
}
89
+
using {sap.print as sp} from '@cap-js/print';
94
90
95
-
@cds.skip.persistence
96
-
entity Queues {
97
-
key ID : String;
98
-
description : String;
91
+
service IncidentService {
92
+
entity Queues as projection on sp.Queues;
99
93
}
100
94
```
101
95
102
-
#### In Service Definition:
103
-
104
-
```cds
105
-
service MyService {
106
-
@print
107
-
action print(
108
-
@print.queue: {
109
-
SourceEntity: 'Queues'
110
-
}
111
-
@Common: {
112
-
ValueListWithFixedValues,
113
-
ValueList: {
114
-
$Type: 'Common.ValueListType',
115
-
CollectionPath: 'Queues',
116
-
Parameters: [{
117
-
$Type: 'Common.ValueListParameterInOut',
118
-
LocalDataProperty: qnameID,
119
-
ValueListProperty: 'ID'
120
-
}]
121
-
},
122
-
Label: 'Print Queues',
123
-
}
124
-
qnameID: String
125
-
);
126
-
127
-
entity Queues as projection on db.Queues;
128
-
}
129
-
```
96
+
## Local Development
130
97
131
-
In this setup, the `qnameID` parameter will be used to dynamically select the print queue from the `Queues` entity. The `Common.ValueList`provides a drop-down selection for available queues during runtime.
98
+
When running the application locally, i.e. `cds watch`, the print service is mocked. This mock implementation prints the print job details to the console instead of sending it to the actual print service. It also provides a number of sample print queues for selection.
132
99
100
+
You can also run the application locally with a binding to the cloud print service with CAP profiles. For more information, see [Hybrid Testing](https://cap.cloud.sap/docs/advanced/hybrid-testing#hybrid-testing).
133
101
134
102
## Note
135
103
@@ -143,14 +111,6 @@ If you are running the application in a production way locally(E.g. adding VCAP_
143
111
}
144
112
```
145
113
146
-
If you are running the application in offline mode which is without remote connection to the online environment, you can add the environmental variable `PRINT_CONSOLE_MODE=true cds watch` in the `package.json` as shown below.
This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/cap-js/print/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md).
cds.error(`Print action ${action.name} is missing required annotations. Make sure @print.numberOfCopies, @print.queue are present in the action and @print.fileName and @print.fileContent are present in the entity.`);
0 commit comments