fujian_water_biz_doc/scripts/test-pdf-export.sh

126 lines
2.8 KiB
Bash
Executable File
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.

#!/bin/bash
# PDF导出测试和诊断脚本
# 用于诊断和解决PDF导出问题
echo "🔍 PDF导出诊断测试..."
# 检查依赖
echo "📋 检查依赖工具..."
# 检查pandoc
if command -v pandoc &> /dev/null; then
echo "✅ pandoc: $(pandoc --version | head -1)"
else
echo "❌ pandoc 未安装"
exit 1
fi
# 检查xelatex
if command -v xelatex &> /dev/null; then
echo "✅ xelatex: $(xelatex --version | head -1)"
else
echo "❌ xelatex 未安装"
echo "请安装 MacTeX 或 TeX Live"
exit 1
fi
# 检查中文字体
echo ""
echo "🔤 检查中文字体..."
if fc-list | grep -q "STHeiti"; then
FONT="STHeiti"
echo "✅ 使用字体: STHeiti"
elif fc-list | grep -q "SimHei"; then
FONT="SimHei"
echo "✅ 使用字体: SimHei"
elif fc-list | grep -q "PingFang"; then
FONT="PingFang-SC"
echo "✅ 使用字体: PingFang-SC"
else
FONT="DejaVu Sans"
echo "⚠️ 使用备用字体: DejaVu Sans"
fi
# 创建测试文档
echo ""
echo "📝 创建测试文档..."
cat > test_pdf.md << 'EOF'
---
title: "PDF导出测试文档"
author: "系统测试"
date: "2024-12-19"
---
# 测试标题
这是一个PDF导出测试文档用于验证中文显示和pandoc配置。
## 中文字符测试
- 简体中文:水务营收系统概要设计
- 数字1234567890
- 英文Water Business Revenue System
### 特殊字符测试
- 符号:!@#¥%……&*
- 标点:,。?;:""''
- 数学:α β γ δ ε
## 表格测试
| 项目 | 内容 | 备注 |
|------|------|------|
| 系统名称 | 福建水务营收系统 | 主要业务系统 |
| 开发框架 | Spring Boot | 后端框架 |
| 前端框架 | Vue 3 | 现代化前端 |
## 代码块测试
```java
public class Test {
public static void main(String[] args) {
System.out.println("Hello, 世界!");
}
}
```
EOF
# 测试PDF导出
echo ""
echo "🚀 测试PDF导出..."
mkdir -p output
# 使用改进的pandoc命令
PANDOC_OPTIONS="--pdf-engine=xelatex -V CJKmainfont=$FONT -V geometry:margin=2cm"
echo "使用命令: pandoc test_pdf.md -o output/test_export.pdf $PANDOC_OPTIONS"
if pandoc test_pdf.md -o output/test_export.pdf $PANDOC_OPTIONS 2>&1; then
echo "✅ PDF导出成功"
echo "📄 输出文件: output/test_export.pdf"
# 检查文件大小
if [ -f output/test_export.pdf ]; then
file_size=$(stat -f%z output/test_export.pdf 2>/dev/null || stat -c%s output/test_export.pdf)
echo "📊 文件大小: $file_size 字节"
if [ "$file_size" -gt 1000 ]; then
echo "✅ PDF文件生成正常"
else
echo "⚠️ PDF文件可能生成异常文件过小"
fi
fi
else
echo "❌ PDF导出失败"
echo "请检查错误信息"
fi
# 清理测试文件
rm -f test_pdf.md
echo ""
echo "🏁 测试完成"