var fonts = { Roboto: { normal: 'fonts/Roboto-Regular.ttf', bold: 'fonts/Roboto-Medium.ttf', italics: 'fonts/Roboto-Italic.ttf', bolditalics: 'fonts/Roboto-.ttf', } }; var pdfMake = require('pdfmake/build/pdfmake.js'); var pdfFonts = require('pdfmake/build/vfs_fonts.js'); pdfMake.vfs = pdfFonts.pdfMake.vfs; function table(course) { return { widths: [100, 300], headerRows: 2, body: [ [{text: `${course.code} ${course.title}`, bold: true, colSpan: 2, alignment: 'center'}, {}], ['Seccion', 'Profesor'], ].concat( course.sections.map( function(section) { if (section.hasOwnProperty('professors')) { return [section.code, section.professors.map( function (professor) { return professor.first_name + ' ' + professor.last_name; })]; } else { return [section.code, '']; } })) } } var docDef = { content: [ {text: `Horario BIOL ${data.alpha}`, style: 'header'}, {text: 'sujeto a cambios', style: 'header', fontSize: 18}, ].concat( data.courses.map( function(course) { return { style: 'tableStyle', alignment: 'center', table: table(course) } })), styles: { header: { fontSize: 22, bold: true, alignment: 'center', }, tableStyle: { margin: [50,10,0,15] }, } }; pdfMake.createPdf(docDef).download(); window.location.replace("/dashboard");