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

How to split the large content and print the splitted content into multi pages to get high resolution? #3258

Closed
jyothiyellapu8 opened this issue Sep 13, 2021 · 2 comments

Comments

@jyothiyellapu8
Copy link

I’m using the React app and I have this code with html2canvas & jsPDF node modules.

Can anyone tell me how can we do this without affecting the actual content?

”bi-diagram-canvas” specifies child element and innerHtml contains div and svg tags

var input = document.getElementById('bi-diagram-canvas');
var w = document.getElementById("bi-diagram-canvas").offsetWidth;
var h = document.getElementById("bi-diagram-canvas").offsetHeight;
var height = h/2
html2canvas(input)
.then((canvas) => {
var imgWidth = 210;
var pageHeight = 295;
var imgHeight = canvas.height * imgWidth / canvas.width;
var heightLeft = imgHeight;
const imgData = canvas.toDataURL('image/png')

var doc = new jsPDF('p', 'mm');
var position = 0;

doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight+15, '', 'FAST');
heightLeft -= pageHeight;

while (heightLeft >= 0) {
position = heightLeft - imgHeight;
doc.addPage();
doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight + 15);
heightLeft -= pageHeight;
}
doc.autoPrint();
doc.output('datauri');
doc.output('dataurlnewwindow');
doc.save('autoprint.pdf');
});

@HackbrettXXX
Copy link
Collaborator

I would recommend using the jsPDF html function. This has also the advantage that the result is a vector graphic with real text and not bitmap images. #2977 improved the autopaging functionality and will be released this week.

@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants