I am currently working on incorporating the pdfmake
package into my application. In order to load fonts, a list of URLs is required during initialization. However, the fonts I am using are managed by npm and Vite, so they do not have fixed URLs. Here's the progress I've made so far:
npm install @fontsource/source-sans-pro
In my app.js
file:
import pdfMake from "pdfmake/build/pdfmake";
import "@fontsource/source-sans-pro/latin-400.css"
import "@fontsource/source-sans-pro/latin-400-italic.css"
import "@fontsource/source-sans-pro/latin-700.css"
import "@fontsource/source-sans-pro/latin-700-italic.css"
pdfMake.fonts = {
SourceSans: {
normal: "", // need to provide URLs for the WOFF files
bold: "",
italics: "",
bolditalics: ""
},
};
After running npm run build
, the following output is generated:
✓ 636 modules transformed.
public/build/manifest.json 6.12 kB
public/build/assets/source-sans-pro-latin-400-italic-500f8aaf.woff2 14.16 kB
public/build/assets/source-sans-pro-latin-700-italic-fae9ee8d.woff2 14.20 kB
public/build/assets/source-sans-pro-latin-700-normal-0d0a6262.woff2 14.71 kB
public/build/assets/source-sans-pro-latin-400-normal-7b348b30.woff2 14.89 kB
public/build/assets/source-sans-pro-latin-700-italic-1933b21f.woff 17.68 kB
public/build/assets/source-sans-pro-latin-400-italic-c3707996.woff 17.76 kB
public/build/assets/source-sans-pro-latin-700-normal-bcc2a2ed.woff 18.39 kB
public/build/assets/source-sans-pro-latin-400-normal-69491b82.woff 18.42 kB
As you can see, the fonts are accessible at URLs like
https://example.com/build/assets/source-sans-pro-latin-400-normal-69491b82.woff
, but this is a dynamic URL. How can I retrieve that URL for use in my script?