Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b03529a4c | ||
|
|
bed293f1b2 | ||
|
|
50b13f60ce | ||
|
|
f889c27338 | ||
|
|
624c6c5c72 | ||
|
|
12fd91ca4f |
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -16,7 +16,7 @@
|
||||
},
|
||||
"mochaExplorer.debuggerConfig": "Debug Mocha Tests",
|
||||
"mochaExplorer.parallel": true,
|
||||
"eslint.validate": [
|
||||
"eslint.probe": [
|
||||
"cds",
|
||||
"csn",
|
||||
"csv",
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
using CatalogService from '@capire/bookstore';
|
||||
|
||||
using from '@sap/cds-pdf-export';
|
||||
|
||||
annotate CatalogService with @(
|
||||
Capabilities: { SupportedFormats : [ 'application/pdf' ] },
|
||||
PDF.Features: {
|
||||
DocumentDescriptionReference : '/-pdf/',
|
||||
DocumentDescriptionCollection : 'createDocumentDescription'
|
||||
}
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Books Object Page
|
||||
|
||||
@@ -43,6 +43,16 @@
|
||||
"[production]": {
|
||||
"model": "db/hana"
|
||||
}
|
||||
},
|
||||
"pdf": {
|
||||
"kind": "btp-adobe-forms",
|
||||
"vcap": {
|
||||
"label": "adsrestapi"
|
||||
},
|
||||
"[pdfme]": {
|
||||
"kind": "export-pdf",
|
||||
"impl": "./pdfme.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"hana": {
|
||||
|
||||
38
fiori/pdfme.js
Normal file
38
fiori/pdfme.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const { generate, BLANK_PDF } = require("@pdfme/generator");
|
||||
|
||||
/**
|
||||
* Generate PDF with @pdfme/generator library
|
||||
*/
|
||||
module.exports = async (data, headers) => {
|
||||
|
||||
let inputs = data
|
||||
|
||||
let x = 0, y = 0;
|
||||
const width = 30;
|
||||
const height = 5;
|
||||
|
||||
const tableSchema = {}
|
||||
for (const entry of headers) {
|
||||
x += width;
|
||||
tableSchema[entry.Name] = {
|
||||
type: 'text',
|
||||
position: { x, y: 10 },
|
||||
width,
|
||||
height
|
||||
}
|
||||
}
|
||||
|
||||
for (const row of data) {
|
||||
for (const [key, value] of Object.entries(row)) {
|
||||
if (typeof value !== 'string') row[key] = ''+value // stringify
|
||||
}
|
||||
}
|
||||
|
||||
const template = {
|
||||
basePdf: BLANK_PDF,
|
||||
schemas: [tableSchema]
|
||||
};
|
||||
const pdf = await generate({ template, inputs });
|
||||
|
||||
return pdf;
|
||||
};
|
||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -446,9 +446,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@sap/cds": {
|
||||
"version": "6.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@sap/cds/-/cds-6.5.0.tgz",
|
||||
"integrity": "sha512-xzlFEgm2On2/iztS5rj6200cN+6GrszlKGEOnFXDicJYk9SjDOjWgkWX+1j75c9t7qOSi7vidRSKAKjFyALRXg==",
|
||||
"version": "6.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@sap/cds/-/cds-6.6.1.tgz",
|
||||
"integrity": "sha512-1JKiYO+N9m5UME7aejce4K5j6mDLkQC0P6BWcHoQJtDjkjsVc6LCLNd06RJqU8XcxeGd3EwIF33GJTLDyGIkUQ==",
|
||||
"dependencies": {
|
||||
"@sap/cds-compiler": "^3.2.0",
|
||||
"@sap/cds-foss": "^4"
|
||||
@@ -509,9 +509,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@sap/eslint-plugin-cds": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@sap/eslint-plugin-cds/-/eslint-plugin-cds-2.6.1.tgz",
|
||||
"integrity": "sha512-WGpK6zILEXAiRuDCfYOBO8qV2BV4+dvEPjxNBiGGmqjZgT3XRQJm4GjuNz/Wgh9SLS7B3yscVbcchpRt9QLbVw==",
|
||||
"version": "2.6.3",
|
||||
"resolved": "https://registry.npmjs.org/@sap/eslint-plugin-cds/-/eslint-plugin-cds-2.6.3.tgz",
|
||||
"integrity": "sha512-FNuzH6ckkEUxOry7C/SKMfSBzpbLCTgm8F1AZPZH/uD1xDFxdtnLeuXL6Vd+oibi4vq0oEXeucgKwxECUC/dmw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=5.6.0",
|
||||
@@ -786,9 +786,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.3.3.tgz",
|
||||
"integrity": "sha512-eYq77dYIFS77AQlhzEL937yUBSepBfPIe8FcgEDN35vMNZKMrs81pgnyrQpwfy4NF4b4XWX1Zgx7yX+25w8QJA==",
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.3.4.tgz",
|
||||
"integrity": "sha512-toYm+Bsyl6VC5wSkfkbbNB6ROv7KY93PEBBL6xyDczaIHasAiv4wPqQ/c4RjoQzipxRD2W5g21cOqQulZ7rHwQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
|
||||
Reference in New Issue
Block a user