"""
将Markdown文档转换为PDF的脚本
需要先安装依赖：pip install mdpdf
"""
import os
import subprocess

def convert_md_to_pdf():
    # Markdown文件列表
    md_files = [
        'main.md',
        'Oxygen_Ctrl.md',
        'fuzzy.md',
        'task.md',
        'dwin.md',
        'modbus.md',
        'mqtt.md',
        'IOT_4G.md',
        'eeprom.md',
        'config.md',
        'myTimer.md',
        'functions.md',
        'const.md',
        'serial.md',
        'README.md',
        'QuickStart.md',
        'API.md',
        'CHANGELOG.md',
        'TEST_GUIDE.md',
        'SUMMARY.md',
        'LICENSE.md'
    ]

    # 创建pdf目录
    if not os.path.exists('pdf'):
        os.makedirs('pdf')

    # 转换每个文件
    for md_file in md_files:
        input_path = md_file
        output_path = f'pdf/{os.path.splitext(md_file)[0]}.pdf'
        
        try:
            cmd = f'mdpdf {input_path} {output_path}'
            subprocess.run(cmd, shell=True, check=True)
            print(f'Successfully converted {md_file} to PDF')
        except subprocess.CalledProcessError as e:
            print(f'Error converting {md_file}: {e}')

if __name__ == '__main__':
    convert_md_to_pdf()
