Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black blocks on pages converted from HTML by addHTML #793

Closed
bhavik4748 opened this issue Jul 8, 2016 · 3 comments
Closed

Black blocks on pages converted from HTML by addHTML #793

bhavik4748 opened this issue Jul 8, 2016 · 3 comments

Comments

@bhavik4748
Copy link

bhavik4748 commented Jul 8, 2016

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
Copy link
Author

@bhavik4748
Copy link
Author

I need help over here ! Someone please help !

@MrRio
Copy link
Member

MrRio commented Sep 28, 2016

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 MrRio closed this as completed Sep 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants