0

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 :

.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 = '<html><table></table></html>';

                var a = $('<a/>', {
                    style:'display:none',
                    href:'data:application/pdf;base64,' + btoa(pdfString ),
                    download:'planning.pdf'
                }).appendTo('body')
                a[0].click()
                a.remove();
            });
        }
    }
});

and here is my html code :

<button class="btn btn-default btn-sm" type="button" ng-disabled="TransferCtrl.transfersFiltrated.length == 0" export-to-pdf>Export PDF</button>

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 ?

Sharan De Silva
  • 598
  • 1
  • 8
  • 27
majd hwas
  • 95
  • 2
  • 2
  • 10

0 Answers0