|
|
@@ -372,7 +372,7 @@ export async function GeneratePDF(ctx) {
|
|
372
|
372
|
}
|
|
373
|
373
|
|
|
374
|
374
|
const content = params.Content;
|
|
375
|
|
- console.log("Generating PDF with content:", JSON.stringify(content).substring(0, 200) + "...");
|
|
|
375
|
+ //console.log("Generating PDF with content:", JSON.stringify(content).substring(0, 200) + "...");
|
|
376
|
376
|
|
|
377
|
377
|
try {
|
|
378
|
378
|
// 创建新的 PDF 文档 - 使用A4尺寸
|
|
|
@@ -427,7 +427,7 @@ export async function GeneratePDF(ctx) {
|
|
427
|
427
|
try {
|
|
428
|
428
|
if (typeof content.Words === 'string') {
|
|
429
|
429
|
// 尝试解析JSON字符串
|
|
430
|
|
- words = content.Words.join(",");
|
|
|
430
|
+ words = content.Words.split(",");
|
|
431
|
431
|
} else if (Array.isArray(content.Words)) {
|
|
432
|
432
|
// 已经是数组
|
|
433
|
433
|
words = content.Words;
|
|
|
@@ -513,11 +513,26 @@ export async function GeneratePDF(ctx) {
|
|
513
|
513
|
// 添加调试信息
|
|
514
|
514
|
console.log(`Drawing word: "${word}" at position: ${yPosition}`);
|
|
515
|
515
|
|
|
516
|
|
- doc.text(word.toString(), wordAreaLeft, yPosition, {
|
|
517
|
|
- width: wordAreaWidth,
|
|
518
|
|
- align: 'right', // 右对齐
|
|
519
|
|
- lineBreak: false // 防止自动换行
|
|
520
|
|
- });
|
|
|
516
|
+ // 检查词组长度,如果过长则调整字体大小
|
|
|
517
|
+ const wordLength = word.toString().length;
|
|
|
518
|
+ let fontSize = pixelToPt(48); // 默认字体大小
|
|
|
519
|
+
|
|
|
520
|
+ // 根据词组长度动态调整字体大小
|
|
|
521
|
+ if (wordLength > 15) {
|
|
|
522
|
+ fontSize = pixelToPt(36); // 长词组使用较小字体
|
|
|
523
|
+ } else if (wordLength > 10) {
|
|
|
524
|
+ fontSize = pixelToPt(42); // 中等长度词组使用中等字体
|
|
|
525
|
+ }
|
|
|
526
|
+
|
|
|
527
|
+ doc.fontSize(fontSize)
|
|
|
528
|
+ .text(word.toString(), wordAreaLeft, yPosition, {
|
|
|
529
|
+ width: wordAreaWidth,
|
|
|
530
|
+ align: 'right', // 右对齐
|
|
|
531
|
+ lineBreak: true // 允许自动换行,处理特别长的词组
|
|
|
532
|
+ });
|
|
|
533
|
+
|
|
|
534
|
+ // 重置字体大小为默认值,以便下一个词组使用
|
|
|
535
|
+ doc.fontSize(pixelToPt(48));
|
|
521
|
536
|
}
|
|
522
|
537
|
}
|
|
523
|
538
|
}
|