How to create Html to pdf on particular div onclick button in angularjs?

mahadev sutar

I am new to AngularJS, and I want to create a pdf of a particular div with a button click. Currently I'm having code that works on page load. If I refresh the page it will automatically download that particular div. But I need the download to happen after the click event. This is my code. Please help me. I have added necessary scripts of html2canvas etc.

html2canvas(document.getElementById('exportthis'), {
        onrendered: function (canvas) {
            var data = canvas.toDataURL();
            var docDefinition = {
                content: [{
                    image: data,
                    width: 500,
                }]
            };
            pdfMake.createPdf(docDefinition).download("Score_Details.pdf");
        }
    }); 
Wekslie

You should create a function in your controller, and add a click event to a button.

Your view:

<input type="submit" ng-click="createPdf()" value="Create PDF"/>

Your controller:

$scope.createPdf = function () {

    html2canvas(document.getElementById('exportthis'), {
        onrendered: function (canvas) {
            var data = canvas.toDataURL();
            var docDefinition = {
                content: [{
                    image: data,
                    width: 500,
                }]
            };
            pdfMake.createPdf(docDefinition).download("Score_Details.pdf");
        }
    }); 
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to create button dynamically and add the onclick event for html page

From Dev

How to create a button with onclick with JavaScript?

From Dev

How to show a div when a particular button is clicked,

From Dev

How to continue a landscape orientation for a particular div tag while converting html to pdf in itext 7?

From Dev

How to show particular div using angularjs routing?

From Dev

Javascript create button and trigger onclick function on HTML

From Dev

how to OnClick button in LinerLayout to Retreieve particular's row value?

From Dev

angularjs create/export html view as pdf

From Dev

How to add a button below div onclick

From Dev

how to show div on under button on onclick event

From Dev

How to change style under div with onclick on button

From Dev

How to append div element onclick in angularjs

From Dev

How to append div element onclick in angularjs

From Dev

how to add button onclick from a create tabcontent

From Dev

Create and download PDF using html2pdf with AngularJS

From Dev

angularjs onclick need to fetch value corresponding to particular clicked value from another data set and display on div

From Dev

angularjs onclick need to fetch value corresponding to particular clicked value from another data set and display on div

From Dev

How to have a static onclick parameter in HTML button?

From Dev

How to develop a Slack share button in HTML with onclick?

From Dev

How to hide one div and show another div using button onclick?

From Dev

Showing only a particular div in AngularJS

From Dev

AngularJs Render div onclick

From Dev

AngularJs Render div onclick

From Dev

How to add div with a button click in angularJs

From Dev

Angularjs/Bootstrap - how to create a stateless button

From Dev

How Can I Reload the Page Onclick of Submit Button in Angularjs?

From Dev

onclick event handler for elements of a particular div

From Dev

HTML button onclick event

From Dev

button and onclick - Html, javascript

Related Related

  1. 1

    how to create button dynamically and add the onclick event for html page

  2. 2

    How to create a button with onclick with JavaScript?

  3. 3

    How to show a div when a particular button is clicked,

  4. 4

    How to continue a landscape orientation for a particular div tag while converting html to pdf in itext 7?

  5. 5

    How to show particular div using angularjs routing?

  6. 6

    Javascript create button and trigger onclick function on HTML

  7. 7

    how to OnClick button in LinerLayout to Retreieve particular's row value?

  8. 8

    angularjs create/export html view as pdf

  9. 9

    How to add a button below div onclick

  10. 10

    how to show div on under button on onclick event

  11. 11

    How to change style under div with onclick on button

  12. 12

    How to append div element onclick in angularjs

  13. 13

    How to append div element onclick in angularjs

  14. 14

    how to add button onclick from a create tabcontent

  15. 15

    Create and download PDF using html2pdf with AngularJS

  16. 16

    angularjs onclick need to fetch value corresponding to particular clicked value from another data set and display on div

  17. 17

    angularjs onclick need to fetch value corresponding to particular clicked value from another data set and display on div

  18. 18

    How to have a static onclick parameter in HTML button?

  19. 19

    How to develop a Slack share button in HTML with onclick?

  20. 20

    How to hide one div and show another div using button onclick?

  21. 21

    Showing only a particular div in AngularJS

  22. 22

    AngularJs Render div onclick

  23. 23

    AngularJs Render div onclick

  24. 24

    How to add div with a button click in angularJs

  25. 25

    Angularjs/Bootstrap - how to create a stateless button

  26. 26

    How Can I Reload the Page Onclick of Submit Button in Angularjs?

  27. 27

    onclick event handler for elements of a particular div

  28. 28

    HTML button onclick event

  29. 29

    button and onclick - Html, javascript

HotTag

Archive