Jspdf: jsPdf fromHTML not working with angular

Created on 28 Jun 2015  路  5Comments  路  Source: MrRio/jsPDF

Hi,

I'm trying to use jsPdf addHtml within an angular directive but It returns an error.

I'm using Version 1.1.135-git

<script type="text/javascript" src="../js/plugins/jsPDF/libs/html2canvas/dist/html2canvas.js"></script>
<script type="text/javascript" src="../js/plugins/jsPDF/dist/jspdf.debug.js"></script>

tecomaApp.directive('exportHtml', function(){
    return {
        restrict: 'A',
        link: function($scope, elm, attr){
            var pdf = new jsPDF('p', 'pt', 'letter');

            var specialElementHandlers = {
                '#exclude-from-print-1': function(element, renderer){
                    return true;
                },
                '#exclude-from-print-2': function(element, renderer){
                    return true;
                }
            };
            $scope.$on('export-pdf', function(e, d){

                var source = $(elm).get(0);

                var  margins = {
                    top: 15,
                    bottom: 20,
                    left: 15,
                    width: 750
                };


                 pdf.fromHTML(source, 15, 15, {
                    'width': margins.with,
                    'margin': 1,
                    'pagesplit': true,
                    'elementHandlers': specialElementHandlers
                });

                pdf.save('test.pdf');

            });


        }
    }
});

I'm getting this errir:

TypeError: pdf is undefined
var canvas = pdf.canvas; jspdf.debug.js (line 15637, col 5)

Can you tell me what is wrong with my method

Thanks

Most helpful comment

stupid library ... all the people having the same issues, and no body know what is happening... 卢卢

All 5 comments

See #529 and pull the latest merge. That might fix your problem.

Thanks for replaying. I tried this merge in jsPdf.debug.js but now I'm getting this error:

Error: Mismatched anonymous define() module: function (){return Mt}
http://requirejs.org/docs/errors.html#mismatch

var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);

Thanks for your help

stupid library ... all the people having the same issues, and no body know what is happening... 卢卢

mine works only with simple materliaze grid layout with text
it doesn't work with images (complete black pdf).
it also shows a border i don't want and the text is a bit blurry as jsPDF just takes a screenshot (with html2canvas)
pdfMake is an alternative but seems alot of work styling the layout of those reports manually

Hi everbody, look at #600, it may fix your issues too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mackersD picture mackersD  路  4Comments

BarathArivazhagan picture BarathArivazhagan  路  4Comments

MaxCodeDE picture MaxCodeDE  路  4Comments

baluMallisetty picture baluMallisetty  路  4Comments

arulmb0136 picture arulmb0136  路  4Comments