0

To download the div element but my download button is not working according to the following code:

This div element creates a card, so I have to download that card using as the pdf after clicking on the download button.

<div id="voterdesign">
    <table width="100%">
    <tr>
        <th><img src="emblem.png" width="75" height="85" /></th>
        <th><img src="AAYOG.png"  width="145" height="85"/></th>
    </tr>
     <tr>
     <th colspan="2"><hr></th>
     </tr>
    <tr>
    <th colspan="2">
    <img src="<?php if(isset($pic)) echo $pic; ?>" width="200" height = '200'>


        <td>VOTER ID</td>
        <td><input type="text" name="roll" value="<?php if(isset($id)) echo $id?>"  readonly></td>
    </tr>
    <tr>
    </tr><tr>
    </tr>
    <tr>
        <td>ELECTOR'S NAME</td>
        <td><input type="text" name="roll" value="<?php if(isset($name)) echo $name?>" readonly></td>
    </tr>   
    <tr>
    </tr><tr>
    </tr>
    <tr>
        <td>FATHER'S NAME</td>
        <td><input type="text" name="roll" value="<?php if(isset($fname)) echo $fname?>"readonly></td>
    </tr>   
    <tr>
    </tr><tr>
    </tr>
    <tr>
        <td>GENDER</td>
        <td><input type="text" name="roll" value="<?php if(isset($gender)) echo $gender?>" readonly></td>
    </tr>   
    <tr>
    </tr><tr>
    </tr>
    <tr>
        <td>DATE OF BIRTH</td>
        <td><input type="text" name="roll" value="<?php if(isset($dob)) echo $dob?>" readonly></td>
    </tr>
    </table>
</div>
    <div id="editor"></div>
    <button id="cmd">Download Card</button>

    <script>
    var doc = new jsPDF();
var specialElementHandlers = {
    '#editor': function (element, renderer) {
        return true;
    }
};

$('#cmd').click(function () {
    doc.fromHTML($('#voterdesign').html(), 50, 50, {
        'width': 1700,
            'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
});
</script>

Please help that the click on download button starts the downloading as pdf

I have already tried the following code

tanerkay
  • 3,819
  • 1
  • 19
  • 28
  • "Not working" isn't an error message or problem statement. We can't fix "not working" in code, any more than a mechanic can fix a car that is "not working", without any other information about the problem. How is it not working? What exactly happens when you run the code? Do you get a console error? Or some other unexpected behaviour? And what debugging have you done? – ADyson Sep 20 '19 at 11:18
  • It is not giving any error but when I click on it, nothing is happening it is not starting for download. – Utkarsh Goyal Sep 20 '19 at 11:44
  • Have you opened the browser's console to actually see what is shown? Have you tried to use the JS debugger to step through each line of your code and see what path it takes? – ADyson Sep 20 '19 at 11:52

0 Answers0