title: How to resolve the error "Cannot read property 'write' of null" in node js while working with pdfkit
body: <p>i get the above error when i use this code below.</p>
  
  <pre><code> var pdf = new PDFDocument({
          autoFirstPage: false
      });
      pdf.fontSize(10);
  
  
  var table = new PdfTable(pdf, {
          bottomMargin: 30,
      });
  for (var l = 0; l &lt; attendance.length; l++) {
  
          pdf 
          .text("Employee Name : "+attendance[l].employee_name, 
              {
                  width: 100,
                  height: 50,
                  align: 'left',
              }
          );
  
  
  
  
          pdf
          .fontSize(12)
          .text("Employee Role", {
              width: 100,
              height: 50,
              align: 'right'
          }
          );
  
          pdf.moveDown();
  
          table.addPlugin(new (require('voilab-pdf-table/plugins/fitcolumn'))({
              column: 'purpose',
              align: 'left'
          }))
              .setColumnsDefaults({
                  headerBorder: 'B',
                  align: 'center',
                  padding: [8, 5, 5, 5],
  
              })
              .addColumns([
                  {
                      id: 'sno',
                      header: '#',
                      width: 40
                  },
                  {
                      id: 'DATE',
                      header: 'DATE',
                      width: 70
                  },
                  {
                      id: 'startTime',
                      header: 'Start Time',
                      width: 70
                  },
                  {
                      id: 'endTime',
                      header: 'End Time',
                      width: 70,
                  },
                  {
                      id: 'workTime',
                      header: 'Work Time',
                      width: 100
                  },
                  {
                      id: 'breakTime',
                      header: 'Break Time',
                      width: 100
                  },
                  {
                      id: 'payable',
                      header: 'Payable',
                      width: 90,
                  }
              ])
              .onPageAdded(function (tb) {
                  tb.addHeader();
              });
              pdf.moveDown();
          pdf.addPage();
  </code></pre>
  
  <p>and i get the below error when i execute the code</p>
  
  <pre><code>TypeError: Cannot read property 'write' of null
      at PDFDocument.addContent (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:4365:15)
      at PDFDocument.save (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:1702:17)
      at PDFDocument._fragment (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:3422:10)
      at PDFDocument._line (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:3314:10)
      at LineWrapper.emit (events.js:203:15)
      at LineWrapper.EventEmitter.emit (domain.js:448:20)
      at emitLine (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:2937:12)
      at eachWord (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:2991:9)
      at LineWrapper.eachWord (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:2893:26)
      at LineWrapper.wrap (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:2943:10)
      at PDFDocument._text (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:3128:15)
      at PDFDocument.text (A:\executeapp\ppm-backend\node_modules\pdfkit\js\pdfkit.js:3141:17)
      at AttendancePdf (A:\executeapp\ppm-backend\utility\recurringTask.js:429:10)
      at A:\executeapp\ppm-backend\utility\recurringTask.js:365:48
      at A:\executeapp\ppm-backend\node_modules\mongoose\lib\model.js:4599:16
      at A:\executeapp\ppm-backend\node_modules\mongoose\lib\query.js:4351:12
      at process.nextTick (A:\executeapp\ppm-backend\node_modules\mongoose\lib\query.js:2849:28)
      at process._tickCallback (internal/process/next_tick.js:61:11)
  Emitted 'error' event at:
  </code></pre>
  
  <p>the error occurs in the code block</p>
  
  <pre><code>     pdf
      .fontSize(12)
      .text("Employee Role", {
          width: 100,
          height: 50,
          align: 'right'
      }
      );
  </code></pre>
  
  <p>I have tried in many ways to get this resolved and I am pretty sure the code which i am using is correct. But i don't know where i am going wrong.</p>
  
  <p>Please help me in resolving this error
  thanks in advance</p>