diff --git a/assets/logo.png b/assets/logo.png new file mode 100644 index 0000000..01d3128 Binary files /dev/null and b/assets/logo.png differ diff --git a/pdf.js b/pdf.js index 2162e5b..d4b7b3a 100644 --- a/pdf.js +++ b/pdf.js @@ -94,20 +94,24 @@ return ''; } - // Load the bundled header logo (JPEG) in the extension background page. - // Returns null in Node (tests) or if the asset is unavailable. + // Load the bundled header logo. Prefer the transparent PNG (matches the + // official PDF, which masks the JPEG's baked-in background) for a clean + // look on white; fall back to the JPEG in Node (tests) or if unavailable. async function loadLogo() { - try { - const url = (typeof browser !== 'undefined' && browser.runtime && browser.runtime.getURL) - ? browser.runtime.getURL('assets/logo.jpeg') - : null; - if (!url) return null; - const resp = await fetch(url); - if (!resp.ok) return null; - return new Uint8Array(await resp.arrayBuffer()); - } catch (e) { - return null; + const ext = (typeof browser !== 'undefined' && browser.runtime && browser.runtime.getURL); + const candidates = ['assets/logo.png', 'assets/logo.jpeg']; + for (const asset of candidates) { + try { + const url = ext ? browser.runtime.getURL(asset) : null; + if (!url) return null; + const resp = await fetch(url); + if (!resp.ok) continue; + return { bytes: new Uint8Array(await resp.arrayBuffer()), transparent: /logo\.png$/.test(asset) }; + } catch (e) { + continue; + } } + return null; } // Builds a Letter-size PDF replicating the official ISMIS Study Load layout: @@ -134,10 +138,16 @@ const black = rgb(0, 0, 0); const gray = rgb(0.3, 0.3, 0.3); - const logoBytes = await loadLogo(); + const logo = await loadLogo(); let logoImg = null; - if (logoBytes) { - try { logoImg = await doc.embedJpg(logoBytes); } catch (e) { logoImg = null; } + if (logo) { + try { + // Transparent PNG embeds with an alpha mask (matches official PDF); + // the JPEG is embedded as-is (no mask). + logoImg = logo.transparent + ? await doc.embedPng(logo.bytes) + : await doc.embedJpg(logo.bytes); + } catch (e) { logoImg = null; } } function center(text, size, f, dy) {