I'm trying to define pdf document structure accordingly to offical documentation of pdfMake in Angular 11 application. But receiving an error:
error TS2345: Argument of type '{ pageSize: string; pageOrientation: string; content: ({ text: string; style: string; fontSize?: undefined; } | { text: string; fontSize: number; style?: undefined; })[]; }' is not assignable to parameter of type 'TDocumentDefinitions'.
Types of property 'pageOrientation' are incompatible.
Type 'string' is not assignable to type '"landscape" | "portrait" | undefined'.
75 pdfMake.createPdf(docDefinition).open();
I have installed all the staff:
npm install --save pdfmake
npm i --save-dev @types/pdfmake
and imported them:
import * as pdfMake from "pdfmake/build/pdfmake";
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
(<any>pdfMake).vfs = pdfFonts.pdfMake.vfs;
Code:
getPdf() {
let docDefinition = {
pageSize: 'A5',
pageOrientation: 'landscape',
content: [
{
text: 'Some data',
style: 'header'
},
{
text: 'some data 2', fontSize: 15
}
]
}
pdfMake.createPdf(docDefinition).open();
}
When I removing from the method properties definition pageSize and pageOrientation - error dissappear. What else I'm missing?