Compare commits
7 Commits
addCustomR
...
pdf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b03529a4c | ||
|
|
bed293f1b2 | ||
|
|
50b13f60ce | ||
|
|
f889c27338 | ||
|
|
624c6c5c72 | ||
|
|
12fd91ca4f | ||
|
|
535981dc7e |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@sap/cds/recommended"
|
||||
"plugin:@sap/cds/recommended",
|
||||
"eslint:recommended"
|
||||
],
|
||||
"env": {
|
||||
"browser": true,
|
||||
@@ -18,6 +18,8 @@
|
||||
"DELETE": true,
|
||||
"CREATE": true,
|
||||
"DROP": true,
|
||||
"CDL": true,
|
||||
"CQL": true,
|
||||
"cds": true
|
||||
},
|
||||
"rules": {
|
||||
|
||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -16,12 +16,12 @@
|
||||
},
|
||||
"mochaExplorer.debuggerConfig": "Debug Mocha Tests",
|
||||
"mochaExplorer.parallel": true,
|
||||
"eslint.validate": [
|
||||
"eslint.probe": [
|
||||
"cds",
|
||||
"csn",
|
||||
"csv",
|
||||
"csv (semicolon)",
|
||||
"tsv",
|
||||
"tab"
|
||||
],
|
||||
]
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
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"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@sap/eslint-plugin-cds": "^2.6.1",
|
||||
"axios": "^1",
|
||||
"chai": "^4.3.4",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
|
||||
Reference in New Issue
Block a user