0

I am having an angular Modal and I want a button on the Modal named export to pdf which will export my modal content to the pdf file.

I have searched through but did not get any solution.

I have 5 modals and I want only one generic function to be used. Please help me with this. Thanks in advance

Sameer Khan
  • 147
  • 2
  • 18
  • [this](https://parall.ax/products/jspdf) may be of help. If you don't want to use a library you could at least look at their source.EDIT: Looking more into it that doesn't seem to be a open source project so may not be any goof – ste2425 Apr 15 '16 at 11:46
  • Maybe your question is answered here: http://stackoverflow.com/questions/34049956/generate-pdf-from-html-using-pdfmake-in-angularjs. – Bruno João Apr 15 '16 at 11:48

1 Answers1

0

Here is what I came accross,

HTML Modal:

<div  class="modal-body" id="pdfPrakrutiId"  style="height:480px;overflow: auto;">
                     <div ng-include="'../prakrutiVP.html'"></div>
                </div>
                <div class="modal-footer" style="margin-bottom:5px;margin-right:10px;">
                    <button type="button" class="btn btn-default" ng-click="closeSecond()">{{'prakruti.common.close' | translate}}</button>
                  <button type="button" id="btn" class="btn btn-default" ng-click="exportToPdf()">Export to pdf</button>
                </div>

JS Code

$scope.exportToPdf = function (value) {
/*Code to generate pdf*/
var pdf = new jsPDF('p', 'pt', 'letter');
var specialElementHandlers = {
    '#bypassme': function(element, renderer) {
      return true;
    }
  };
  var margins = {
    top: 50,
    bottom: 60,
    left: 60,
    right:20,
    width: 522,
  };
  pdf.fromHTML(
    $("#pdfPrakrutiId").html(),
      margins.left, 
      margins.top, 
      {
        'width': margins.width,
        'elementHandlers': specialElementHandlers
      },
    margins
  );
  pdf.save('my_prakruti.pdf');
/*Code to generate pdf ends here*/  

};

Sameer Khan
  • 147
  • 2
  • 18