md-editor-extension
md-editor-extension copied to clipboard
pdf导出问题
一、效果图
- 预期的内容:
- 导出的pdf:
二、部分代码
项目主要使用了tailwindcss和nextjs。
import { MdEditor } from 'md-editor-rt';
import { ExportPDF } from '@vavt/rt-extension';
import { toolbars } from './staticConfig';
import '@vavt/rt-extension/lib/asset/style.css';
import 'md-editor-rt/lib/style.css';
let updateRatio: ((str: string) => void) | undefined;
let closrRatio = () => {};
interface Props {
value: string;
onChange: (value: string) => void;
}
const onProgress = ({ ratio }: { ratio: number }) => {
if (updateRatio) {
updateRatio(`Progress: ${ratio * 100}%`);
} else {
const { close, update } = message.info(`Progress: ${ratio * 100}%`, {
zIndex: 999999,
duration: 0,
});
updateRatio = update;
closrRatio = close;
}
};
const onSuccess = () => {
closrRatio();
setTimeout(() => {
updateRatio = undefined;
}, 100);
message.success('导出成功!', {
zIndex: 999999,
});
};
const EditorMD = ({ value, onChange }: Props) => {
const pdfRef = useRef<any>();
const defToolbars = useMemo(() => {
return [
<ExportPDF
key="ExportPDF"
ref={pdfRef}
value={value}
height="700px"
onProgress={onProgress}
onSuccess={onSuccess}
/>,
];
}, [value]);
return (
<>
<MdEditor
ref={editorRef}
value={value}
onChange={onChange}
language='zh-CN'
defToolbars={defToolbars}
toolbars={toolbars}
/>
</>
);
}
html2pdf和html3pdf都处于更新停止状态,在没有找到合适的替代库前,这类问题得等待一下
尝试使用v4.0.0版本,使用window.print替换了html2pdf