Compare commits

..

2 Commits

Author SHA1 Message Date
Christian Georgi
2b03529a4c PDF export PoC 2023-03-14 15:28:26 +01:00
dependabot[bot]
bed293f1b2 Bump @sap/cds from 6.6.0 to 6.6.1
Bumps [@sap/cds](https://cap.cloud.sap/) from 6.6.0 to 6.6.1.

---
updated-dependencies:
- dependency-name: "@sap/cds"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-10 14:23:03 +01:00
4 changed files with 61 additions and 3 deletions

View File

@@ -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

View File

@@ -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
View 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;
};

6
package-lock.json generated
View File

@@ -446,9 +446,9 @@
}
},
"node_modules/@sap/cds": {
"version": "6.6.0",
"resolved": "https://registry.npmjs.org/@sap/cds/-/cds-6.6.0.tgz",
"integrity": "sha512-+rJQIsirbHNVpzZQsTpHzzbcxPM8Y5gEAQtK8blxlukluvyk6IqrwA1eoJH8grab+DtXqcUqT8c0ooGfnCrbPw==",
"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"