4

I have tried many methods but either they have limitation of Number of columns in pdf or they have height limitation. And for excel, when I open in MAC, it shows HTML. Can anyone suggest any way from which I can export pdf with More than 4 columns and does not have limitation on number of rows.

1 Answer 1

2

You could try to use jsPDF library to do this

HTML

  <table id="table">
     <thead>
     <tr>
       <th>Column 1</th>
       <th>Column 2</th>
       <th>Column 3</th>
       <th>Column 4</th>
       <th>Column 5</th>
       <th>Column 6</th>
     </tr>

     </thead>
    <tbody>
      <tr>
         ... 
      </tr>

    </tbody>

  </table>

  <export-to-pdf elem-id="table"></export-to-pdf>

JS

  app.directive('exportToPdf', function(){

   return {
       restrict: 'E',
       scope: {
            elemId: '@'
       },
       template: '<button data-ng-click="exportToPdf()">Export to PDF</button>',
       link: function(scope, elem, attr){

          scope.exportToPdf = function() {

              var doc = new jsPDF();

              console.log('elemId 12312321', scope.elemId);

              doc.fromHTML(
              document.getElementById(scope.elemId).innerHTML, 15, 15, {
                     'width': 170
              });

              doc.save('a4.pdf')

           }
       }                   
   }

});    

In my JSFiddle example I didnt reach limit for columns, but I did not find solution about adding css, so you have to do inline styling for html code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.