### Start Development Server Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Launches the GovDocFormatter service in development mode. This command starts the Python backend. ```bash python run.py ``` -------------------------------- ### Configure API Key from Example Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Copies the example environment file and prepares it for API key configuration. This is for development mode. ```bash cp .env.example .env ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Install necessary Python packages for development mode. Ensure you have Python installed. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install LibreOffice on CentOS/RHEL Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Installs LibreOffice for .doc file conversion on CentOS/RHEL systems. This is optional if you only work with .docx files. ```bash sudo yum install -y libreoffice ``` -------------------------------- ### Install LibreOffice on Ubuntu/Debian/WSL Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Installs LibreOffice for .doc file conversion on Debian-based systems. This is optional if you only work with .docx files. ```bash sudo apt update && sudo apt install -y libreoffice ``` -------------------------------- ### Install LibreOffice on Windows using winget Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Installs LibreOffice for .doc file conversion on Windows using the winget package manager. This is optional if you only work with .docx files. ```bash winget install TheDocumentFoundation.LibreOffice ``` -------------------------------- ### Install LibreOffice on Windows using choco Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Installs LibreOffice for .doc file conversion on Windows using the Chocolatey package manager. This is optional if you only work with .docx files. ```bash choco install libreoffice ``` -------------------------------- ### Install LibreOffice on macOS Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Installs LibreOffice for .doc file conversion on macOS using Homebrew. This is optional if you only work with .docx files. ```bash brew install --cask libreoffice ``` -------------------------------- ### Run Packaged Executable Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Instructions for running the packaged executable after unzipping. This is for users who do not want to set up a Python environment. ```bash 解压 公文自动排版工具.zip 双击运行 公文自动排版工具.exe ``` -------------------------------- ### Set API Key in .env File Source: https://github.com/drenches/gov-doc-formatter/blob/main/README.md Edits the .env file to include your Tongyi Qianwen API Key. Replace 'your_api_key_here' with your actual key. ```bash DASHSCOPE_API_KEY=your_api_key_here ``` -------------------------------- ### Initialize Font Preset Listeners Source: https://github.com/drenches/gov-doc-formatter/blob/main/static/index.html Sets up event listeners for font preset selection. It toggles the visibility of detailed font configuration and global English font settings based on whether 'custom' is selected or a standard preset like 'gb9704' is chosen. ```javascript function initFontPresetListeners() { ['File', 'Text'].forEach(mode => { const presetSelect = document.getElementById(`fontPreset${mode}`); if (presetSelect) { presetSelect.addEventListener('change', (e) => { const detailConfig = document.getElementById(`fontDetailConfig${mode}`); const englishFontSection = document.getElementById(`globalEnglishFont${mode}Section`); if (e.target.value === 'custom') { // 切换到自定义模式,自动展开详细配置和英文字体选择 detailConfig.classList.add('active'); if (englishFontSection) { englishFontSection.style.display = 'flex'; } } else { // 切换到 GB/T 标准,隐藏详细配置和英文字体选择 detailConfig.classList.remove('active'); if (englishFontSection) { englishFontSection.style.display = 'none'; } } }); } }); } ``` -------------------------------- ### Process Batch Formatting Source: https://github.com/drenches/gov-doc-formatter/blob/main/static/index.html Handles the asynchronous process of batch formatting documents. It displays progress, sends files and font configurations to the server via POST request, and updates the UI with results. Includes error handling for network issues. ```javascript async function processBatchFormat(data, button) { try { // 显示进度条 const batchProgress = document.getElementById('batchProgress'); const batchProgressBar = document.getElementById('batchProgressBar'); const batchProgressText = document.getElementById('batchProgressText'); batchProgress.style.display = 'block'; batchProgressBar.style.width = '0%'; batchProgressText.textContent = `0 / ${data.files.length}`; // 隐藏结果 const batchResults = document.getElementById('batchResults'); batchResults.style.display = 'none'; // 准备FormData const formData = new FormData(); data.files.forEach(file => { formData.append('files', file); }); formData.append('font_config', JSON.stringify(data.font_config || {})); // 发送请求 const response = await fetch('/api/format-batch', { method: 'POST', body: formData }); const result = await response.json(); // 更新进度条到100% batchProgressBar.style.width = '100%'; batchProgressText.textContent = `${result.total_files} / ${result.total_files}`; // 显示结果 setTimeout(() => { batchProgress.style.display = 'none'; displayBatchResults(result); }, 500); } catch (error) { alert('批量处理失败: ' + error.message); } finally { button.disabled = false; button.textContent = '开始排版'; } } ``` -------------------------------- ### Display Batch Results Source: https://github.com/drenches/gov-doc-formatter/blob/main/static/index.html Renders the results of a batch formatting operation. It populates a list with success/failure status for each file and displays an error message if applicable. It also conditionally shows a download button for successfully processed files. ```javascript function displayBatchResults(result) { const batchResults = document.getElementById('batchResults'); const batchResultsList = document.getElementById('batchResultsList'); const downloadBatchBtn = document.getElementById('downloadBatchBtn'); batchResults.style.display = 'block'; batchResultsList.innerHTML = result.results.map(item => { const statusClass = item.success ? 'success' : 'failed'; const statusText = item.success ? '成功' : '失败'; const errorMsg = item.error_message ? `