0

At first I thought it is working fine but after a couple of testing, the data became large enough that it won't fit to one page. I researched some questions but it didn't help me enough

so here's my code

html2canvas(document.getElementById(id)).then(function (canvas) {
            document.body.appendChild(canvas);
            var data = canvas.toDataURL();
            var height = canvas.height;
            canvas.remove();
            var docDefinition = {
                content: [{
                    image: data,
                    width: 500,


                }]
            };
            pdfMake.createPdf(docDefinition).download(id+".pdf", function() {
                $scope.balanceSheet = false;
                $scope.mainPage = true;
            });

        });

I have at least 90 rows here but the image was cut at 46 enter image description here

any idea how to split it? I've already tried raising the height but it just fit the whole 90 rows into one page.

The page break showed because I added

 content: [{
    image: data,
    width: 500,
    pageBreak: 'after',
   }]

Here's a sample how to split it here but I can't read it because it is not angular :( can anyone explain it or convert it?

1

1 Answer 1

0

I don't think you can split images in different pages automatically in pdfmake.

But you may split the canvas beforehand using the method drawImage. Check the parameters of the function and you can split an image vertically on every point you'd like, and then set those two subimages in different pages

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

4 Comments

here's a sample gist.github.com/Balkoth/d79a520ca2a3377c15e902ec68790aff but it is not in angular and can't read it :(
@Mark I don't know angular but I think here is irrelevant. pdfMake just needs javascript.
I just made one with AngularJS. it is just that I can't translate it to the correct syntax for angular since I don't know javascript
@Mark, really, read the documentation of of drawImage, and then just apply that to your canvas

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.