Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'name' of undefined #516

Closed
OhScee opened this issue Jun 2, 2015 · 18 comments
Closed

Uncaught TypeError: Cannot read property 'name' of undefined #516

OhScee opened this issue Jun 2, 2015 · 18 comments

Comments

@OhScee
Copy link

OhScee commented Jun 2, 2015

Seem to consistently be getting an error on this line in from_html and jspdf.debug.
Tried to work through it, though I'm not sure this part

rowData[headers[j].name]

I might just be doing something wrong though.

var doc = new jsPDF();
var area = document.getElementById("pdf");
var specialElementHandlers = {
    '#ignore1': function(element, renderer){
        return true;
    },
        '#ignore2': function(element, renderer){
            return true;
        },
        '#ignore3': function(element, renderer){
            return true;
        },
        '#ignore4':function(element, renderer){
            return true;
        }
};
doc.fromHTML($('#bill-display').get(0), 15, 15, {
    'width': 170, 
    'elementHandlers': specialElementHandlers,
});

otherwise this has been a troublesome bug

@OhScee OhScee changed the title rowData[headers[j].name] = tableRow.cells[j].textContent.replace(/\r?\n/g, ''); Uncaught TypeError: Cannot read property 'name' of undefined Jun 2, 2015
@harsh-a1
Copy link

harsh-a1 commented Jun 9, 2015

I have got a similar error -
Uncaught TypeError: Cannot read property 'name' of undefinedtableToJson @ from_html.js:297DrillForContent @ from_html.js:450(anonymous function) @ from_html.js:647done @ from_html.js:517img.onerror.img.onload @ from_html.js:540

This is the code -

var doc = new jsPDF('p', 'pt', 'letter');
debugger
// We'll make our own renderer to skip this editor
var specialElementHandlers = {
    '#questionare': function(element, renderer){
        return true;
    }
};

// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML($('#printArea').get(0), 15, 15, {
    'width': 170, 
    'elementHandlers': specialElementHandlers
});
debugger
doc.output('dataurlnewwindow', {})`

using these libraries -

    <script type="text/javascript" src="assets/js/jspdf/jspdf.js"></script>
    <script type="text/javascript" src="assets/js/jspdf/standard_fonts_metrics.js"></script>
    <script type="text/javascript" src="assets/js/jspdf/split_text_to_size.js"></script>
    <script type="text/javascript" src="assets/js/jspdf/from_html.js"></script>
        <script type="text/javascript" src="assets/js/jspdf/cell.js"></script>

@MrRio MrRio self-assigned this Jun 9, 2015
@pranshuagrawal
Copy link

Any workaround for this?

@azeemvl
Copy link

azeemvl commented Oct 14, 2015

i got the same issue because of i have used colspan. removed that and everything fine for me..

@neerajlad
Copy link

Hi I am also, getting same error,

Any solution ?

@azeemvl
Copy link

azeemvl commented Dec 18, 2015

that error occurred to me as because i applied col-span to the header.
removing that solved my problem

hope this helps

On Tue, Dec 15, 2015 at 11:24 PM, Neeraj notifications@github.com wrote:

Hi I am also, getting same error,

Any solution ?


Reply to this email directly or view it on GitHub
#516 (comment).

@rohit-web
Copy link

Getting same error :
var htmlString = $.trim($("#overviewpage_rating_r").html());
var doc = new jsPDF('landscape','pt');
doc.fromHTML(htmlString);
doc.output('datauri');
doc.save('newh.pdf');

@oninross
Copy link

That issue has been there for some time now. Apparently the plugin doenst work for any colspan or rowspan

@jeremywizy
Copy link

Any news on this issue ?

@eldyvoon
Copy link

+1

@lukemorrill
Copy link

I was able to fix this by modifying line 6203 of jspdf.debug.js (on version 1.2.61) to this:

while (j < tableRow.cells.length && headers[j] != undefined) {

Which was originally:

while (j < tableRow.cells.length) {

Alternatively, I could make it go away by adding another td to the tr it was processing (it only had one td, which apparently caused the problem).

@samimetoui
Copy link

samimetoui commented Dec 3, 2016

i have the same error message and when i try to fix it by replacing line 6203 with
while (j < tableRow.cells.length && headers[j] != undefined) {
in jspdf.debug.js i have this error
jspdf.debug.js:5304 Uncaught TypeError: this.splitTextToSize is not a function(…)
jsPDFAPI.calculateLineHeight @ jspdf.debug.js:5304
jsPDFAPI.table @ jspdf.debug.js:5263
DrillForContent @ jspdf.debug.js:6590
DrillForContent @ jspdf.debug.js:6616
(anonymous function) @ jspdf.debug.js:6787
done @ jspdf.debug.js:6657
loadImgs @ jspdf.debug.js:6687
process @ jspdf.debug.js:6785
jsPDFAPI.fromHTML @ jspdf.debug.js:7224
(anonymous function) @ services_chart.js:17
dispatch @ jquery-3.1.0.min.js:3
q.handle @ jquery-3.1.0.min.js:3

@JosueMartinez
Copy link

@BingeCoder that worked. Thanks!

@joshsiegl1
Copy link

I had to wrap the if statements at lines 7640 and 7663 with
if (typeof line[0] === 'object')
and it works perfectly now. Hope that helps someone

@karthikkumarphp
Copy link

im getting erro

@johnsonsamuel
Copy link

I replaced table to div because the data I was displaying was minimal and that helped to render the PDF without issues.

@tomkochi
Copy link

tomkochi commented Jun 20, 2018

I was getting this error constantly until i removed the table header element. Then it took the first row for the header, and rest, the body part.

www.coredes.io
Works fine.

@Uzlopak
Copy link
Collaborator

Uzlopak commented Sep 6, 2018

We are closing this issue, because we will not support any longer fromHTML and addHTML.

Explaination:
We are working on a new html2pdf plugin, which will be based on html2canvas and our context2d plugin. This should lead to more reliable results for your projects. And it will give us the time to focus on the core functionality of pdf-generation because we will not use our energy for writing/supporting/extending 2 html plugins. If you still want to use addHTML or fromHTML you can still use jsPDF 1.4.1.

Best Regards

@Uzlopak Uzlopak closed this as completed Sep 6, 2018
@vbsaba1992
Copy link

Unable to create pdf with this :

$(document).ready(function()
{
    $(".btn").click(function()
    {
        var contentHeight; // header + footer + number of buying items
        var doc = new jsPDF("p", "mm", [80, contentHeight]),
            source = $("#template_invoice"),
            margins = {
                top: 10,
                //bottom: 60,
                left: 5,
                width: 80    // Receipt printer width
            };
        doc.fromHTML(
            source, // HTML string or DOM elem ref.
            margins.left, // x coord
            margins.top,
            {
                // y coord
                width: margins.width // max width of content on PDF
            },
            function(dispose)
            {
                // dispose: object with X, Y of the last line add to the PDF
                // this allow the insertion of new lines after html
                doc.save("Test.pdf");
            },
            margins
        );
    });
});
<!DOCTYPE html>
<html lang="en" >
   <head>
      <meta charset="UTF-8">
      <title>Receipt PDF</title>
      <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
      <link rel="stylesheet" href="css/style.css">
      <style>
         table{
         font-family: 'Courier New', Courier, monospace;
         }
         td#aliCenter{
         text-align:center;
         }
         td#aliRight{
         text-align:right;
         }
      </style>
   </head>
   <body>
      <div class="container" id="template_invoice">
         <table>
            <!-- header -->
            <!-- buying items -->
            <tr>
               <td>1</td>
               <td colspan="4">The big tasty Pizza</td>
            </tr>
            <tr>
               <td></td>
               <td>PZ4545</td>
               <td>2.00</td>
               <td id="aliRight">150.00</td>
               <td id="aliRight">300.00</td>
            </tr>
            <tr>
               <td>2</td>
               <td colspan="4">Crunchy huge Buggers</td>
            </tr>
            <tr>
               <td></td>
               <td>BR7878</td>
               <td>5.00</td>
               <td id="aliRight">500.00</td>
               <td id="aliRight">2500.00</td>
            </tr>
            <tr>
               <td>3</td>
               <td colspan="4">1.5 l Coca-Cola pack</td>
            </tr>
            <tr>
               <td></td>
               <td>CC6523</td>
               <td>3.00</td>
               <td id="aliRight">180.00</td>
               <td id="aliRight">540.00</td>
            </tr>
            <!-- footer -->
         </table>
         <div class="row">
            <div class="col-xs-4">
               <button class="btn btn-info pull-right">Download</button>
            </div>
         </div>
      </div>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js'></script>
      <script  src="js/index.js"></script>
   </body>
</html>

@parallax parallax locked as spam and limited conversation to collaborators Nov 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests