fujian_water_biz_doc/export_to_pdf.sh

61 lines
2.1 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/zsh
# 确保pandoc已安装
if ! command -v pandoc &> /dev/null; then
echo "错误: 需要安装pandoc。请运行 'brew install pandoc' 安装。"
exit 1
fi
# 检查PDF引擎
pdf_engine="wkhtmltopdf"
if command -v xelatex &> /dev/null; then
pdf_engine="xelatex"
pdf_engine_opts="-V mainfont='SimSun'"
elif ! command -v wkhtmltopdf &> /dev/null; then
echo "错误: 未找到PDF转换引擎。请安装xelatex或wkhtmltopdf:"
echo " brew install basictex # 安装xelatex"
echo " 或"
echo " brew install wkhtmltopdf # 安装wkhtmltopdf"
exit 1
else
pdf_engine_opts=""
echo "注意: 使用wkhtmltopdf作为转换引擎中文显示可能需要调整。"
fi
# 创建输出目录
mkdir -p pdf_output
# 转换文件并设置对应的中文名
convert_file() {
md_file=$1
cn_name=$2
cn_pdf="pdf_output/$cn_name"
if [ -f "$md_file" ]; then
echo "正在将 $md_file 转换为 $cn_pdf..."
pandoc "$md_file" -o "$cn_pdf" --pdf-engine=$pdf_engine $pdf_engine_opts 2>/dev/null ||
pandoc "$md_file" -o "$cn_pdf" --pdf-engine=$pdf_engine
if [ $? -eq 0 ]; then
echo "✅ 成功转换: $cn_pdf"
else
echo "❌ 转换失败: $md_file"
fi
else
echo "❌ 文件不存在: $md_file"
fi
}
# 逐个处理文件
convert_file "water_biz_database_design.md" "福建水务业务系统数据库设计.pdf"
convert_file "water_biz_deployment_design.md" "福建水务业务系统部署设计.pdf"
convert_file "water_biz_design_plan.md" "福建水务业务系统设计方案.pdf"
convert_file "water_biz_integrated_doc.md" "福建水务业务系统集成文档.pdf"
convert_file "water_biz_interface_design.md" "福建水务业务系统接口设计.pdf"
convert_file "water_biz_module_design.md" "福建水务业务系统模块设计.pdf"
convert_file "water_biz_summary.md" "福建水务业务系统概要.pdf"
convert_file "water_biz_system_architecture.md" "福建水务业务系统架构.pdf"
echo "转换完成! 输出文件保存在 pdf_output/ 目录下"
tar -czvf pdf_output.tar.gz pdf_output