gitlink_help_center/src/components/PdfExportButton.js

44 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React from 'react';
export default function PdfExportButton({ title }) {
const handleExport = async () => {
const element = document.getElementById('doc-markdown-content');
if (element) {
// 动态导入 html2pdf.js只在客户端执行
const html2pdf = (await import('html2pdf.js')).default;
html2pdf()
.set({
margin: 0.5,
filename: `${title}.pdf`,
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
})
.from(element)
.save();
} else {
alert('未找到文档内容区域');
}
};
return (
<button
onClick={handleExport}
style={{
fontSize: 14,
padding: '0 16px',
background: '#466aff',
color: '#fff',
borderRadius: 4,
height: 32,
lineHeight: '32px',
border: 'none',
cursor: 'pointer',
display: 'inline-block',
marginLeft: 12,
boxSizing: 'border-box',
}}
>
导出PDF
</button>
);
}