jsPDF icon indicating copy to clipboard operation
jsPDF copied to clipboard

Black blocks on pages converted from HTML by addHTML

Open bhavik4748 opened this issue 10 years ago • 3 comments

I am having a pop up where users will click on next button and will be displaying some 7 pages of html. On each next tab I am using below code to capture the HTML to PDF. (divID is each page's parent div)

$scope.addHtmlToPdf = function (divID) {
 var deferred = $q.defer();
 if (divID != 'P1') {
        $scope.doc.addPage();
    }
    try {
        $scope.doc.addHTML($('#' + divID).get(0), 25, 0, {
            pagesplit: true,
            'elementHandlers': specialElementHandlers
        }, function () {
            $scope.isNextDisable = false;
            deferred.resolve();
        });
    } catch (e) {
        deferred.resolve();
    }
    return deferred.promise;
}

`

Calling function

          $scope.Next = function () {
         if ($scope.template < 10) {
           try {
            $('div').animate({ scrollTop: 0 }, 700);  //To scroll up to top if user click bottom next button
            var currentElement = 'P' + $scope.template.toString(); //P1, P2 , P3 etc.
            if (!(~$.inArray(currentElement, $scope.preViewPdf))) { //Check is page converted to pdf
                $scope.preViewPdf.push(currentElement);  //
                $scope.isNextDisable = true;  //disable next button till pdf added
                if ($scope.addHtmlToPdf(currentElement).then(function () {     //create pdf of current page                            
                    $scope.incrementPage();  //once done increment page
                      $scope.isNextDisable = false; //enable next button
                }), function (data) {
                        $scope.isNextDisable = false;
                        modalpopup.alert(COMMONCONSTANT.REQUEST_FAILED);
                });
            } else {
                $scope.incrementPage();
            }
        }
        catch (err) {
            $scope.isFileDisable = false;
        }
    }
}

On the last page calling below method

$scope.generatPdf = function () { $scope.doc.save("MyPdf" + '.pdf'); }

First page is 3 page long, some time it's adding correct data and no black patch. But sometime adding 2 or 1 and 1/2 page and then black patch.

Please help me with this the functionality need to go live on 25th July 2016.

I will attach the correct version of pdf generated along with the pdf with issues of black patch.

Regards,

bhavik4748 avatar Jul 08 '16 13:07 bhavik4748

I need help over here ! Someone please help !

bhavik4748 avatar Jul 22 '16 13:07 bhavik4748

Hi there,

There's now a html2pdf example which much better supports generating documents from HTML.

Get the latest master and try:

npm install
npm start

Then visit localhost:8000/examples/html2pdf/showcase.html

Hope this works well for you :)

Many thanks, James

MrRio avatar Sep 28 '16 20:09 MrRio