-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: bold font in azure static web apps #439
base: main
Are you sure you want to change the base?
Conversation
Thank you for the PR. I can see some problems with the current state of this PR:
I have already started working on fixing these issues as I was reviewing, so you don't need to be concerned about it. I will get back to this in the next days. |
I tried to create the test cases for the Blob fonts and read the PDFKit documentation again. Does it not work for you to register the fonts as described in the documentation? You could register the font using the Blob and reference it later by the name: pdf.registerFont("Liberation-Sans", LiberationSansBlob);
pdf.registerFont("Liberation-Sans-Bold", LiberationSansBoldBlob);
const qrBill = new SwissQRBill(data, { fontName: "Liberation-Sans" }); If you already pass the Blob, there should be no way for PDFKit to not find the fonts. |
Thank you for your help I tried that before making a commit, but sadly, it gave me an error message saying it could not write to a folder named /data/. It might be related to this issue foliojs/pdfkit#1516
The path seems valid to me but i don't think it should even touch the file system if possible. This also only happens in Azure Static Web Apps on my machine it works perfectly with Maybe I could start a PR on the pdfkit repo so that |
I Have found a workaround for the issue So no import { defineConfig } from 'vite';
import arraybuffer from 'vite-plugin-arraybuffer';
import dts from 'vite-plugin-dts';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
export default defineConfig({
build: {
target: 'node18',
lib: {
entry: './src/index.ts',
formats: ['es']
},
rollupOptions: {
external: []
},
outDir: 'build'
},
plugins: [
nodePolyfills({
include: ['fs', 'stream', 'zlib']
}),
arraybuffer(),
dts({ rollupTypes: true })
],
optimizeDeps: {
include: []
}
}); Then i can use it the way you suggested: import helveticaBold from './fonts/Helvetica-Bold.ttf?arraybuffer';
import helvetica from './fonts/Helvetica.ttf?arraybuffer';
pdf.registerFont('Helvetica', helvetica);
pdf.registerFont('Helvetica-Bold', helveticaBold);
const qrBill = new SwissQRBill(data, {
fontName: 'Helvetica'
});
qrBill.attachTo(pdf); The downside is that the bundle is over 2 MiB but it works |
Hello
I had problems when deploying to Azure static web apps.
It couldn't find the font files.
I need to pass them in as a Blob so that they are found.
This works in pdfkit but this library assumes that the font will be a string.
I changed it to accept two fonts one normal and one bold this should make my use case work.
Thanks for the great library