|
@@ -381,29 +381,28 @@ const exportWordTemplate = async () => {
|
|
|
await _word.initWord((_this) => {
|
|
|
const out = _this.addDownloadFile(); // 获取文件的 Blob
|
|
|
console.log(`${data.studentName}_.docx 文件已生成`);
|
|
|
- // 将生成的 .docx 文件添加到 zip 压缩包中
|
|
|
zip.file(`${data.studentName}_.docx`, out);
|
|
|
});
|
|
|
- const pdfDoc = await PDFDocument.create();
|
|
|
- const page = pdfDoc.addPage();
|
|
|
- const { width, height } = page.getSize();
|
|
|
- // 将 Word 文件内容写入 PDF
|
|
|
- const text = `学生姓名: ${data.studentName}\n学号: ${data.userNumber}\n专业: ${data.major}\n电话: ${data.mobile}\n导师: ${data.nickname}\n工作职称: ${data.title}\n签名日期: ${data.studentSignDate}\n导师签名日期: ${data.supervisorSignDate}`;
|
|
|
- page.drawText(text, { x: 50, y: height - 50, size: 12 });
|
|
|
- const fontBytes = await fetch('/GB2312.ttf').then(res => res.arrayBuffer());
|
|
|
- const customFont = await pdfDoc.embedFont(fontBytes);
|
|
|
- // 在页面上绘制文本时使用指定的字体
|
|
|
- page.drawText(text, {
|
|
|
- x: 50,
|
|
|
- y: height - 50,
|
|
|
- size: 12,
|
|
|
- font: customFont, // 使用自定义字体
|
|
|
- });
|
|
|
- // 生成 PDF 文件的 Blob
|
|
|
- const pdfBytes = await pdfDoc.save();
|
|
|
- const pdfBlob = new Blob([pdfBytes], { type: 'application/pdf' });
|
|
|
- zip.file(`${data.studentName}_.pdf`, pdfBlob);
|
|
|
-
|
|
|
+ // 转pdf
|
|
|
+ // const pdfDoc = await PDFDocument.create();
|
|
|
+ // const page = pdfDoc.addPage();
|
|
|
+ // const { width, height } = page.getSize();
|
|
|
+ // // 将 Word 文件内容写入 PDF
|
|
|
+ // const text = `学生姓名: ${data.studentName}\n学号: ${data.userNumber}\n专业: ${data.major}\n电话: ${data.mobile}\n导师: ${data.nickname}\n工作职称: ${data.title}\n签名日期: ${data.studentSignDate}\n导师签名日期: ${data.supervisorSignDate}`;
|
|
|
+ // page.drawText(text, { x: 50, y: height - 50, size: 12 });
|
|
|
+ // const fontBytes = await fetch('/GB2312.ttf').then(res => res.arrayBuffer());
|
|
|
+ // const customFont = await pdfDoc.embedFont(fontBytes);
|
|
|
+ // // 在页面上绘制文本时使用指定的字体
|
|
|
+ // page.drawText(text, {
|
|
|
+ // x: 50,
|
|
|
+ // y: height - 50,
|
|
|
+ // size: 12,
|
|
|
+ // font: customFont, // 使用自定义字体
|
|
|
+ // });
|
|
|
+ // // 生成 PDF 文件的 Blob
|
|
|
+ // const pdfBytes = await pdfDoc.save();
|
|
|
+ // const pdfBlob = new Blob([pdfBytes], { type: 'application/pdf' });
|
|
|
+ // zip.file(`${data.studentName}_.pdf`, pdfBlob);
|
|
|
}
|
|
|
|
|
|
// 生成 zip 文件并保存
|