fix(pdfjs): custom scripts no longer embedded

This commit is contained in:
Elian Doran 2026-02-19 21:24:08 +02:00
parent 39ece711d9
commit 5b751fd6e2
No known key found for this signature in database
2 changed files with 15 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import { join } from "path"; import { join } from "path";
import packageJson from "../package.json" with { type: "json" }; import packageJson from "../package.json" with { type: "json" };
import fs from "fs/promises";
import * as yauzl from "yauzl"; import * as yauzl from "yauzl";
import { createWriteStream } from "fs"; import { createWriteStream } from "fs";
const version = packageJson.devDependencies["pdfjs-dist"]; const version = packageJson.devDependencies["pdfjs-dist"];
@ -46,7 +47,19 @@ async function main() {
}); });
zip.readEntry(); zip.readEntry();
}); });
zip.on("end", async () => {
console.log("Finished extracting pdfjs-dist files.");
await patchViewerHTML();
});
}); });
}; };
async function patchViewerHTML() {
const viewerPath = join(__dirname, "../viewer/viewer.html");
let content = await fs.readFile(viewerPath, "utf-8");
content = content.replace(` <link rel="stylesheet" href="viewer.css" />`, ` <link rel="stylesheet" href="viewer.css" />\n <link rel="stylesheet" href="custom.css" />`);
content = content.replace(` <script src="viewer.mjs" type="module"></script>`, ` <script src="custom.mjs" type="module"></script>\n <script src="viewer.mjs" type="module"></script>`);
await fs.writeFile(viewerPath, content, "utf-8");
}
main(); main();

View File

@ -32,7 +32,9 @@ See https://github.com/adobe-type-tools/cmap-resources
<script src="../build/pdf.mjs" type="module"></script> <script src="../build/pdf.mjs" type="module"></script>
<link rel="stylesheet" href="viewer.css" /> <link rel="stylesheet" href="viewer.css" />
<link rel="stylesheet" href="custom.css" />
<script src="custom.mjs" type="module"></script>
<script src="viewer.mjs" type="module"></script> <script src="viewer.mjs" type="module"></script>
</head> </head>