• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

205
Views
JSPDF generate two DIVs in two pages PDF file

can anyone help me with a code snippet that generates two DIVs HTML in PDF file?

I tried this code and the pdf.save() is the only function working but the pdf.output() not working so I need another snippet

const pdf = new jsPDF('p', 'mm', 'a4');
const imgWidth = 208;
const position = 0;

let page1 = document.querySelector('#report-one');
let page2 = document.querySelector('#report-two');
const [imgPage1, imgPage2] = await Promise.all([html2canvas(page1), html2canvas(page2)]);
// Process first image
let imgHeight = imgPage1.height * imgWidth / imgPage1.width;
let contentDataURL = imgPage1.toDataURL('image/jpeg');
pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
pdf.addPage();
// Process second image
imgHeight = imgPage2.height * imgWidth / imgPage2.width;
contentDataURL = imgPage2.toDataURL('image/jpeg');
pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);

pdf.save('Result.pdf');
almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error