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 (//i.test(h)) { + h = h.replace(/<title>[^<]*<\/title>/i, `<title>${printTitle}`); + } else { + h = h.replace(//i, `${printTitle}`); + } + } ifr.srcdoc = h; ifr.onload = () => { setTimeout(() => {