From 206ef091cc2f0a75f285deb11a7a66ecd37415a6 Mon Sep 17 00:00:00 2001 From: Leon Date: Mon, 13 Jul 2026 17:06:14 +0800 Subject: [PATCH] fix: use translated filename as PDF print title Read Content-Disposition filename from the HTML download response, strip the extension, inject it as before printing. Browser uses <title> as the filename when saving to PDF. --- docutranslate/static/index.html | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docutranslate/static/index.html b/docutranslate/static/index.html index c7ad2e7..05721ff 100644 --- a/docutranslate/static/index.html +++ b/docutranslate/static/index.html @@ -2004,7 +2004,19 @@ }, 3000); const ifr = document.getElementById('printFrame'); - fetch(url).then(r => r.text()).then(h => { + fetch(url).then(r => { + const cd = r.headers.get('content-disposition') || ''; + const match = cd.match(/filename[^;=\n]*=['"]?([^'"\n;]+)['"]?/i); + const printTitle = match ? match[1].replace(/\.[^.]+$/, '') : ''; + return r.text().then(h => ({ h, printTitle })); + }).then(({ h, printTitle }) => { + if (printTitle) { + if (/<title>/i.test(h)) { + h = h.replace(/<title>[^<]*<\/title>/i, `<title>${printTitle}`); + } else { + h = h.replace(//i, `${printTitle}`); + } + } ifr.srcdoc = h; ifr.onload = () => { setTimeout(() => {