); useEffect(() => { generatePdf({ ComponentString, fileName: ‘docs.pdf’ }); }, [printType, data]); return (
);};export default MyComponent;// pdfGenerator.jsimport jsPDF from ‘jspdf’;export const generatePdf = ({ ComponentString, fileName }) => { const pdf = new jsPDF({ format: “a4”, unit: “px” }); pdf.html(ComponentString, { callback(doc) { doc.save(fileName); }, margin: [10, 10, 10, 10], // top, left, bottom, right margins autoPaging: ‘text’, // Automatically add new pages if content overflows x: 0, y: 50, html2canvas: { scale: 0.5 // Adjusts the resolution of the output } });};
微信扫一扫
支付宝扫一扫