title: Convert HTML to pdf in AngularJs
body: <p>I want to convert a simple html code to pdf and download it as pdf file,
  I code this with angularJs,
  here is my code :</p>
  
  <pre><code>.directive('exportToPdf',function(){
      return {
          restrict: 'A',
          link: function (scope, element, attrs) {
              var el = element[0];
              element.bind('click', function(e){
                  var table = e.target.nextElementSibling;
                  var pdfString = '&lt;html&gt;&lt;table&gt;&lt;/table&gt;&lt;/html&gt;';
  
                  var a = $('&lt;a/&gt;', {
                      style:'display:none',
                      href:'data:application/pdf;base64,' + btoa(pdfString ),
                      download:'planning.pdf'
                  }).appendTo('body')
                  a[0].click()
                  a.remove();
              });
          }
      }
  });
  </code></pre>
  
  <p>and here is my html code :</p>
  
  <pre><code>&lt;button class="btn btn-default btn-sm" type="button" ng-disabled="TransferCtrl.transfersFiltrated.length == 0" export-to-pdf&gt;Export PDF&lt;/button&gt;
  </code></pre>
  
  <p>now when I click on the export button I got a pdf file but the file is corrupted and not in a good format.
  can I know whats wrong in my code ?</p>