question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Black page after 7 pages

See original GitHub issue

Hi, I readed each post like mine but you don’t give answers so I try.

Here is my code to generate a pdf with multiple pages. Each page take the content of a div it’s class is ‘une_page’ : `$(‘#printPDF’).click(function () { var pdf = new jsPDF(‘portrait’); var pdfName = $(this).data(‘titre’);

    var options = {};

    var $divs = $('.une_page')                //jQuery object of all the myDivClass divs
    var numRecursionsNeeded = $divs.length -1;     //the number of times we need to call addHtml (once per div)
    var currentRecursion=0;

    //Found a trick for using addHtml more than once per pdf. Call addHtml in the callback function of addHtml recursively.
    function recursiveAddHtmlAndSave(currentRecursion, totalRecursions){
        //Once we have done all the divs save the pdf
        if(currentRecursion==totalRecursions){
            pdf.save(pdfName);
        }else{
            currentRecursion++;
            pdf.addPage();
            //$('.myDivClass')[currentRecursion] selects one of the divs out of the jquery collection as a html element
            //addHtml requires an html element. Not a string like fromHtml.
            pdf.addHTML($('.une_page')[currentRecursion], 0, 0, options, function(){
                console.log(currentRecursion);
                recursiveAddHtmlAndSave(currentRecursion, totalRecursions)
            });
        }
    }

    pdf.addHTML($('.une_page')[currentRecursion], 0, 0, options, function(){
    	console.log(currentRecursion);
        recursiveAddHtmlAndSave(currentRecursion, numRecursionsNeeded);
    });
});`

It works fine but after the 6th page, everything is black.

Can you please help me ?

Thanks a lot.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
yannsaintycommented, Mar 19, 2019

Problem solved.

I just hide elements when it’s added so canvas limit is never reached.

Here is my solution if it can helps someone : `$(‘#getPDF’).click(function () { var pdf = new jsPDF(‘portrait’); var pdfName = $(this).data(‘titre’); var options = {}; var $divs = $(‘.une_page’) //jQuery object of all the myDivClass divs var numRecursionsNeeded = $divs.length -1; //the number of times we need to call addHtml (once per div) var currentRecursion=0;

    function recursiveAddHtmlAndSave(currentRecursion, totalRecursions){
        if(currentRecursion==totalRecursions){ //Si c'est la dernière page
            pdf.save(pdfName); //On enregistre le pdf
            $('.une_page').show(); //On raffiche le pdf dans la page
        }else{
            currentRecursion++;
            pdf.addPage(); //On créé une nouvelle page pdf
            pdf.addHTML($('.une_page')[currentRecursion], 0, 0, options, function(){ //On ajoute la page dans le pdf
    			$('.une_page').eq(currentRecursion).hide(); //On cache la page pour éviter de dépasser la limit du canvas
                recursiveAddHtmlAndSave(currentRecursion, totalRecursions); //On rappelle la fonction pour la page suivante
            });
        }
    }

    pdf.addHTML($('.une_page')[currentRecursion], 0, 0, options, function(){
    	$('.une_page').eq(currentRecursion).hide();  //On cache la page pour éviter de dépasser la limit du canvas
        recursiveAddHtmlAndSave(currentRecursion, numRecursionsNeeded);//On appelle la fonction pour la page suivante
    });
});`
0reactions
Robson-Vasconceloscommented, Oct 17, 2020

@yannsainty you saved my day. Good solution, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Insert a blank page - Microsoft Support
To put a blank page into your Word document, place the cursor where you want the new page to begin and then click...
Read more >
How to Delete a Blank Page in Word - Lifewire
In the Navigation pane on the left, select the blank page from the list of pages. Once it's highlighted, press the delete/backspace key,...
Read more >
3 ways to delete unwanted blank page in Word [2007/2010 ...
Delete page in wordThis video also answers some of the queries below:Delete blank page in wordfind how many pages you have in wordNavigation ......
Read more >
Word Tips: Modifying Page Numbers in Word - GCF Global
Modifying page numbers with section breaks Here's an overview of the steps you need to follow. These steps should work for Word 2007,...
Read more >
Help with page numbering please! - CreativePro Network
What do I do with the blank pages or am I missing something?? ... I much prefer to put a 10 – 20%...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found