Uncaught TypeError: Невозможно прочитать свойство 'name' из undefined в tableToJson - PullRequest
1 голос
/ 25 марта 2020

У меня есть файл шаблона, который я пытаюсь преобразовать в PDF. Немного погуглив, я нашел фреймворк под названием JSPDf. Когда я пытаюсь использовать его, он выдает ошибку Uncaught TypeError: Невозможно прочитать свойство 'name' из неопределенного jspdf.

у нас есть две кнопки 1-> printDiv, эта работает нормально. 2-> saveDiv эта кнопка, имеющая проблему. Когда мы нажимаем эту кнопку, чтобы загрузить PDF, я получаю ошибку консоли, такую ​​как Uncaught TypeError: Cannot read property 'name' of undefined at tableToJson(jspdf.debug.js).

Вот мой код, я помещаю весь код в один файл.

index. html

<!DOCTYPE html>
<html>
 <head>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js" integrity="sha384-NaWTHo/8YCBYJ59830LTz/P4aQZK1sS0SneOgAvhsIl3zBu8r9RevNg5lHCHAuQ/" crossorigin="anonymous"></script>
 <script>
 var doc = new jsPDF();

 function saveDiv(divId, title) {
 doc.fromHTML(`<html><head><title>${title}</title></head><body>` + document.getElementById(divId).innerHTML + `</body></html>`);
 doc.save('div.pdf');
}

function printDiv(divId,
  title) {

  let mywindow = window.open('', 'PRINT', 'height=650,width=900,top=100,left=150');

  mywindow.document.write(`<html><head><title>${title}</title>`);
  mywindow.document.write('</head><body >');
  mywindow.document.write(document.getElementById(divId).innerHTML);
  mywindow.document.write('</body></html>');

  mywindow.document.close(); // necessary for IE >= 10
  mywindow.focus(); // necessary for IE >= 10*/

  mywindow.print();
  mywindow.close();

  return true;
}

</script>

 <style>
tbody {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}
td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}


</style>
</head>
  <body>
    <p>&nbsp;</p>
    <div id="pdf">
  <p>
    <font size="6" color="black"></font>
<table border="1" width="600">
<tbody>
<tr>
<td width="96">
<p><strong>PROJECT TITLE</strong></p>
</td>
<td colspan="3" width="225">
<p>HYATT CENTRIC KOTA KINABALU</p>
<p>&lt;Project N ame&gt;</p>
</td>
<td colspan="3" width="97">
<p><strong>PROJ.NO</strong></p>
</td>
<td colspan="2" width="182">
<p>HCKK1904</p>
<p>&lt;Project code&gt;</p>
</td>
</tr>
<tr>
<td width="96">
<p><strong>LOCATION</strong></p>
</td>
<td colspan="8" width="504">
<p>Lot 017512533 Along Jalan Haji Saman, 88000 Kota Kinabalu, Sabah.</p>
<p>&lt;Location&gt;</p>
</td>
</tr>
<tr>
<td width="96">
<p><strong>NO</strong></p>
</td>
<td colspan="3" width="225">
<p>RFI-001 &lt;operation prefix -in sequence no&gt;</p>
</td>
<td colspan="2" width="96">
<p><strong>DATE</strong></p>
</td>
<td colspan="3" width="183">
<p>23/1/2020</p>
<p>&lt;Created date&gt;</p>
</td>
</tr>
<tr>
<td width="96">
<p><strong>TITLE</strong></p>
</td>
<td colspan="8" width="504">
<p>HCKK Blueprint Document</p>
<p>&lt;user entered title of operation title field&gt;</p>
</td>
</tr>
<tr>
<td width="96">
<p><strong>ASSIGNED TO</strong></p>
</td>
<td colspan="4" width="227">
<p>David Khor (Sunhill Ventures Sdn Bhd)</p>
<p>&lt;Assign To&gt;</p>
</td>
<td width="94">
<p><strong>PURPOSE</strong></p>
</td>
<td colspan="3" width="183">
<p>Approval</p>
<p>&lt;purpose&gt;</p>
</td>
</tr>
<tr>
<td width="96">
<p><strong>CC USERS</strong></p>
</td>
<td colspan="3" width="225">
<p>Chirs Chiew (Sunhill Ventures Sdn Bhd)<br /> Roy Chiew (Sunhill Ventures Sdn Bhd)</p>
<p>&lt;Cc user name&rsquo;s&gt;</p>
</td>
<td colspan="2" width="96">
<p><strong>REQUESTED BY</strong></p>
</td>
<td colspan="3" width="183">
<p>Manfred weber</p>
<p>(Sunhill Ventures Sdn Bhd)</p>
<p>&lt;Created by name&gt;</p>
</td>
</tr>
<tr>
<td width="96">
<p><strong>DISCIPLINE</strong></p>
</td>
<td colspan="3" width="225">
<p>Architecture</p>
<p>&lt;User selected discipline &gt;</p>
</td>
<td colspan="2" width="96">
<p><strong>DUE DATE:</strong></p>
</td>
<td colspan="3" width="183">
<p>25/1/2020</p>
<p>&lt;Action by&gt;</p>
</td>
</tr>
<tr>
<td colspan="9" width="600">&nbsp;</td>
</tr>
<tr>
<td colspan="9" width="600">
<p><strong>DESCRIPTION</strong></p>
</td>
</tr>
<tr>
<td colspan="9" width="600">
<p>Sending the blueprint of the hckk1904 document for approval</p>
<p>&lt;Initiator description&gt;</p>
</td>
</tr>
<tr>
<td colspan="9" width="600">&nbsp;</td>
</tr>
<tr>
<td colspan="9" width="600">
<p><strong>RESPONDANT COMMENT</strong></p>
</td>
</tr>
<tr>
<td colspan="9" width="600">
<p>Approving the blueprint document<strong> DATE:</strong></p>
<p><strong>&lt;&lt; the assignee comments &gt;</strong></p>
</td>
</tr>
<tr>
<td colspan="2" width="101">
<p><strong>LEAD RESPONDANT</strong></p>
</td>
<td width="122">
<p>David Khor (Sunhill Ventures Sdn Bhd)</p>
<p><strong>&lt;Assignee&gt;</strong></p>
</td>
<td width="98">
<p><strong>RESPONSE</strong></p>
</td>
<td colspan="3" width="97">
<p>Approved</p>
<p>&lt;Assignee status&gt;</p>
</td>
<td width="97">
<p><strong>RESPONDED DATE</strong></p>
</td>
<td width="85">
<p>23/1/2020</p>
<p>&lt;Assignee edited on&gt;</p>
</td>
</tr>
<tr>
<td colspan="2" width="101">
<p><strong>DOCUMENTS ATTACHED</strong></p>
</td>
<td colspan="7" width="499">
<p>Filename.pdf</p>
<p>&lt;file attachment names of the Created by / Assignee&gt;</p>
</td>
</tr>

</tbody>
</table>
<p>&nbsp;</p>
<p>This is a system generated document, no signature is required.</p>
    </p>
</div>
  </body>
 <button onclick="printDiv('pdf','New Operations Details')">print div</button>

<button onclick="saveDiv('pdf','New Operations Details')">save div as pdf</button>
</html>

пожалуйста, помогите мне ..

...