1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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: [50, 100, 50, 50],
- headerRows: 2,
- body: [
- [{text: `${course.code} ${course.title}`, bold: true, colSpan: 4, alignment: 'center'}, {}, {}, {}],
- ['Seccion', 'Profesor', 'Lugar', 'Horas'],
- ].concat( course.sections.map( function(section) {
- var res = [section.code];
- if (section.hasOwnProperty('professors') && !section.professors.length) {
- res = res.concat( section.professors.reduce( function (acc, professor) {
- return acc + '\n' + professor.first_name + ' ' + professor.last_name;
- }));
- } else {
- res = res.concat('');
- }
- if (section.hasOwnProperty('schedules') && !section.professors.length) {
- res = res.concat( section.schedules.reduce( function (acc, schedule) {
- return acc + '\n' + schedule.building + ' ' + schedule.room;
- }));
- res = res.concat( section.schedules.reduce( function (acc, schedule) {
- return acc + '\n' + schedule.time_start + '-' + schedule.time_end;
- }));
- } else {
- res = res.concat(['', '']);
- }
- return res;
- }))
- }
- }
-
- var docDef = {
- content: [
- {text: `Horario ${data.dept.name} ${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]
- },
- }
-
- };
-
- console.log(docDef);
- pdfMake.createPdf(docDef).download();
- // window.location.replace("/dashboard");
|