Compare commits
7 Commits
addCustomR
...
pdf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b03529a4c | ||
|
|
bed293f1b2 | ||
|
|
50b13f60ce | ||
|
|
f889c27338 | ||
|
|
624c6c5c72 | ||
|
|
12fd91ca4f | ||
|
|
535981dc7e |
52
.eslintrc
52
.eslintrc
@@ -1,29 +1,31 @@
|
|||||||
{
|
{
|
||||||
"extends": [
|
"extends": [
|
||||||
"eslint:recommended",
|
"plugin:@sap/cds/recommended",
|
||||||
"plugin:@sap/cds/recommended"
|
"eslint:recommended"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"es2022": true,
|
"es2022": true,
|
||||||
"node": true,
|
"node": true,
|
||||||
"jest": true,
|
"jest": true,
|
||||||
"mocha": true
|
"mocha": true
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"SELECT": true,
|
"SELECT": true,
|
||||||
"INSERT": true,
|
"INSERT": true,
|
||||||
"UPSERT": true,
|
"UPSERT": true,
|
||||||
"UPDATE": true,
|
"UPDATE": true,
|
||||||
"DELETE": true,
|
"DELETE": true,
|
||||||
"CREATE": true,
|
"CREATE": true,
|
||||||
"DROP": true,
|
"DROP": true,
|
||||||
"cds": true
|
"CDL": true,
|
||||||
},
|
"CQL": true,
|
||||||
"rules": {
|
"cds": true
|
||||||
"no-console": "off",
|
},
|
||||||
"require-atomic-updates": "off",
|
"rules": {
|
||||||
|
"no-console": "off",
|
||||||
|
"require-atomic-updates": "off",
|
||||||
"require-await":"warn",
|
"require-await":"warn",
|
||||||
"no-unused-vars": ["warn", { "argsIgnorePattern": "_" }]
|
"no-unused-vars": ["warn", { "argsIgnorePattern": "_" }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -16,12 +16,12 @@
|
|||||||
},
|
},
|
||||||
"mochaExplorer.debuggerConfig": "Debug Mocha Tests",
|
"mochaExplorer.debuggerConfig": "Debug Mocha Tests",
|
||||||
"mochaExplorer.parallel": true,
|
"mochaExplorer.parallel": true,
|
||||||
"eslint.validate": [
|
"eslint.probe": [
|
||||||
"cds",
|
"cds",
|
||||||
"csn",
|
"csn",
|
||||||
"csv",
|
"csv",
|
||||||
"csv (semicolon)",
|
"csv (semicolon)",
|
||||||
"tsv",
|
"tsv",
|
||||||
"tab"
|
"tab"
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
using CatalogService from '@capire/bookstore';
|
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
|
// Books Object Page
|
||||||
|
|||||||
@@ -43,6 +43,16 @@
|
|||||||
"[production]": {
|
"[production]": {
|
||||||
"model": "db/hana"
|
"model": "db/hana"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"pdf": {
|
||||||
|
"kind": "btp-adobe-forms",
|
||||||
|
"vcap": {
|
||||||
|
"label": "adsrestapi"
|
||||||
|
},
|
||||||
|
"[pdfme]": {
|
||||||
|
"kind": "export-pdf",
|
||||||
|
"impl": "./pdfme.js"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hana": {
|
"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;
|
||||||
|
};
|
||||||
932
package-lock.json
generated
932
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@
|
|||||||
"./reviews"
|
"./reviews"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@sap/eslint-plugin-cds": "^2.6.1",
|
||||||
"axios": "^1",
|
"axios": "^1",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user