Compare commits
1 Commits
hierarch-d
...
pdf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b03529a4c |
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user