### 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 ? `
${item.error_message}
` : ''; return `
${item.filename} ${errorMsg}
${statusText}
`; }).join(''); // 如果有成功的文件,显示下载按钮 if (result.successful_files > 0) { downloadBatchBtn.style.display = 'block'; downloadBatchBtn.onclick = () => { window.location.href = `/api/download-batch/${result.batch_id}`; }; } else { downloadBatchBtn.style.display = 'none'; } } ``` -------------------------------- ### Collect Font Configuration Source: https://github.com/drenches/gov-doc-formatter/blob/main/static/index.html Gathers font settings for specific modes (File or Text). Returns an empty object for GB/T 9704-2012 standard to use backend defaults. Collects global English font and detailed configurations for various text elements. ```javascript function collectFontConfig(mode) { const fontPreset = document.getElementById(`fontPreset${mode}`).value; // 如果使用 GB/T 9704-2012 标准,返回空对象(使用后端默认) if (fontPreset === 'gb9704') { return {}; } // 自定义模式:收集全局英文字体和所有元素的字体配置 const detailConfig = document.getElementById(`fontDetailConfig${mode} `); const globalEnglishFont = document.getElementById(`globalEnglishFont${mode}`).value; const config = { global_english_font: globalEnglishFont }; const elementTypes = ['title', 'heading1', 'heading2', 'heading3', 'heading4', 'body', 'issuing_authority', 'date']; elementTypes.forEach(elementType => { const chineseSelect = detailConfig.querySelector(`.font-chinese[data-element="${elementType}"]`); const boldSelect = detailConfig.querySelector(`.font-bold[data-element="${elementType}"]`); const sizeSelect = detailConfig.querySelector(`.font-size[data-element="${elementType}"]`); if (chineseSelect && boldSelect && sizeSelect) { config[elementType] = { chinese_font: chineseSelect.value, bold: boldSelect.value === 'true', size: parseInt(sizeSelect.value) }; } }); return config; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.