Geen omschrijving

createPDF.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var fonts = {
  2. Roboto: {
  3. normal: 'fonts/Roboto-Regular.ttf',
  4. bold: 'fonts/Roboto-Medium.ttf',
  5. italics: 'fonts/Roboto-Italic.ttf',
  6. bolditalics: 'fonts/Roboto-.ttf',
  7. }
  8. };
  9. var pdfMake = require('pdfmake/build/pdfmake.js');
  10. var pdfFonts = require('pdfmake/build/vfs_fonts.js');
  11. pdfMake.vfs = pdfFonts.pdfMake.vfs;
  12. function table(course) {
  13. return {
  14. widths: [100, 300],
  15. headerRows: 2,
  16. body: [
  17. [{text: `${course.code} ${course.title}`, bold: true, colSpan: 2, alignment: 'center'}, {}],
  18. ['Seccion', 'Profesor'],
  19. ].concat( course.sections.map( function(section) {
  20. if (section.hasOwnProperty('professors')) {
  21. return [section.code, section.professors.map( function (professor) {
  22. return professor.first_name + ' ' + professor.last_name;
  23. })];
  24. } else {
  25. return [section.code, ''];
  26. }
  27. }))
  28. }
  29. }
  30. var docDef = {
  31. content: [
  32. {text: `Horario BIOL ${data.alpha}`, style: 'header'},
  33. {text: 'sujeto a cambios', style: 'header', fontSize: 18},
  34. ].concat( data.courses.map( function(course) {
  35. return {
  36. style: 'tableStyle',
  37. alignment: 'center',
  38. table: table(course)
  39. }
  40. })),
  41. styles: {
  42. header: {
  43. fontSize: 22,
  44. bold: true,
  45. alignment: 'center',
  46. },
  47. tableStyle: {
  48. margin: [50,10,0,15]
  49. },
  50. }
  51. };
  52. pdfMake.createPdf(docDef).download();
  53. window.location.replace("/dashboard");