将 HTML 内容转换为 PDF(包括图像)

问题描述 投票:0回答:1
javascript reactjs base64 jspdf
1个回答
0
投票

您可以使用 html2canvas 库

 import html2canvas from 'html2canvas';
 import jsPDF from 'jspdf';

// Function to convert React-quill content to PDF
function convertContentToPDF(content) {
  // Capture React-quill content as an image using html2canvas
  html2canvas(document.getElementById('yourEditorElementId')).then((canvas) => {
    const imgData = canvas.toDataURL('image/png');

    // Generate PDF using jsPDF
    const pdf = new jsPDF();
    pdf.addImage(imgData, 'PNG', 0, 0, 210, 297); // Image dimensions and positioning
    pdf.save('react-quill-content.pdf'); // Save the PDF
  });
}

// Use the function with the React-quill content
convertContentToPDF(yourReactQuillContent);

希望这有帮助

© www.soinside.com 2019 - 2024. All rights reserved.