feat: add configurable watermark text in API settings
This commit is contained in:
@@ -660,6 +660,7 @@ def export_pdf(plan_id):
|
||||
content=content,
|
||||
output_dir=current_app.config["PDF_OUTPUT_DIR"],
|
||||
rendered_report=rendered_report, # 传递渲染后的报告
|
||||
watermark_text=api_config.get("watermark_text"),
|
||||
)
|
||||
|
||||
return send_file(
|
||||
|
||||
@@ -192,7 +192,7 @@ class PianoPDF:
|
||||
self.elements.append(Spacer(1, 5*mm))
|
||||
|
||||
|
||||
def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=None):
|
||||
def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=None, watermark_text=None):
|
||||
"""生成PDF文件"""
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
output_path = os.path.join(output_dir, f"plan_{plan_id}.pdf")
|
||||
@@ -272,7 +272,7 @@ def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=Non
|
||||
|
||||
# 水印函数(每页都绘制)
|
||||
def draw_watermark(c, doc):
|
||||
if not CHINESE_FONT_OK:
|
||||
if not watermark_text or not CHINESE_FONT_OK:
|
||||
return
|
||||
c.saveState()
|
||||
try:
|
||||
@@ -283,7 +283,7 @@ def generate_pdf(plan_id, student_name, content, output_dir, rendered_report=Non
|
||||
c.translate(A4[0]/2, A4[1]/2)
|
||||
c.rotate(45)
|
||||
# 绘制水印文字(居中)
|
||||
c.drawCentredString(0, 0, "仅供学习参考")
|
||||
c.drawCentredString(0, 0, watermark_text)
|
||||
except Exception:
|
||||
pass # 字体问题则跳过水印
|
||||
c.restoreState()
|
||||
|
||||
@@ -57,6 +57,12 @@
|
||||
<small class="text-muted">控制输出的随机性,值越大越有创造性</small>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">PDF水印文本</label>
|
||||
<input type="text" class="form-control" id="watermarkText" placeholder="留空则不显示水印">
|
||||
<small class="text-muted">PDF每页中央显示的斜向水印文字</small>
|
||||
</div>
|
||||
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-primary" onclick="saveApiConfig()">
|
||||
<i class="bi bi-save"></i> 保存配置
|
||||
@@ -171,7 +177,8 @@ async function saveApiConfig(silent = false, overrideProvider = null) {
|
||||
model: document.getElementById('apiModel').value,
|
||||
api_key: document.getElementById('apiKey').value,
|
||||
base_url: document.getElementById('apiEndpoint').value,
|
||||
temperature: parseFloat(document.getElementById('apiTemperature').value)
|
||||
temperature: parseFloat(document.getElementById('apiTemperature').value),
|
||||
watermark_text: document.getElementById('watermarkText').value.trim()
|
||||
};
|
||||
|
||||
const r = await fetch('/api/config', {
|
||||
@@ -199,6 +206,7 @@ async function loadApiConfig() {
|
||||
document.getElementById('apiKey').value = config.api_key || '';
|
||||
document.getElementById('apiEndpoint').value = config.base_url || '';
|
||||
document.getElementById('apiTemperature').value = config.temperature || 0.7;
|
||||
document.getElementById('watermarkText').value = config.watermark_text || '';
|
||||
|
||||
if (config.api_key_preview) {
|
||||
document.getElementById('apiKeyPreview').textContent = '当前: ' + config.api_key_preview;
|
||||
|
||||
Reference in New Issue
Block a user