Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

json to pdf javascript

//You can use pdfmake which support both client side and server side rendering

//import pdfmake
import pdfMake from 'pdfmake/build/pdfmake.js';
import pdfFonts from 'pdfmake/build/vfs_fonts.js';

pdfMake.vfs = pdfFonts.pdfMake.vfs;

const employees = [
    {"firstName":"John", "lastName":"Doe"}, 
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
];
const document = { content: [{text: 'Employees', fontStyle: 15, lineHeight: 2}] }
employees.forEach(employee => {
    document.content.push({
        columns: [
            { text: 'firstname', width: 60 },
            { text: ':', width: 10 },
            { text:employee.firstName, width: 50 },
            { text: 'lastName', width: 60 },
            {text: ':', width: 10 }, { text: employee.lastName, width: 50}
        ],
        lineHeight: 2
    });
});
pdfMake.createPdf(document).download();
Comment

PREVIOUS NEXT
Code Example
Javascript :: use css child selector inside js 
Javascript :: how to turn decimales into percents with javascript 
Javascript :: js array remove undefined values 
Javascript :: jquery datatable update row cell value 
Javascript :: confluent kafka nodejs 
Javascript :: JavaScript block-scoped Variable9 
Javascript :: vue js link image link in props doesnt work 
Javascript :: what does = mean in javascript 
Javascript :: get total pairs from integer array javascript 
Javascript :: react video 
Javascript :: pass data between pages react 
Javascript :: google autocomplete not returning lat long 
Javascript :: use filereader javascript 
Javascript :: list of alphabet letter english for js 
Javascript :: get downloadable link to s3 bucket object js 
Javascript :: create new nx app 
Javascript :: jquery add attribute without value 
Javascript :: parsedate javascript 
Javascript :: get keys of object js 
Javascript :: node js require file in parent directory 
Javascript :: db.json code 
Javascript :: includes not working 
Javascript :: javascript clone object 
Javascript :: circle progress bar react 
Javascript :: ckeditor inline editor example 
Javascript :: alpine js open outside div 
Javascript :: angular 8 enable routing 
Javascript :: enzyme testing 
Javascript :: react bootstrap navbar align right buttons 
Javascript :: js exclude from object 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =