From 2e296e775e1dc0633969dcaa820105217bbfb58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Malfait?= Date: Mon, 23 Jun 2025 16:27:21 +0200 Subject: [PATCH] Fix export to pdf (#12782) Export to PDF was throwing an error due to fonts not being registered. Maybe linked to the async loading changes or blocknote upgrades. I wasn't a fan of hardcoding the fonts here (makes a second source of truth for Inter), but after a few tests this seemed like the best compromise --- .../utils/exportBlockNoteEditorToPdf.ts | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/utils/exportBlockNoteEditorToPdf.ts b/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/utils/exportBlockNoteEditorToPdf.ts index cc359bdde..46bb335cb 100644 --- a/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/utils/exportBlockNoteEditorToPdf.ts +++ b/packages/twenty-front/src/modules/action-menu/actions/record-actions/single-record/utils/exportBlockNoteEditorToPdf.ts @@ -3,13 +3,44 @@ import { PDFExporter, pdfDefaultSchemaMappings, } from '@blocknote/xl-pdf-exporter'; -import { pdf } from '@react-pdf/renderer'; +import { Font, pdf } from '@react-pdf/renderer'; import { saveAs } from 'file-saver'; +const registerInterFonts = (() => { + let registrationPromise: Promise | null = null; + + return () => { + if (!registrationPromise) { + registrationPromise = Promise.resolve().then(() => { + Font.register({ + family: 'Inter', + fonts: [ + { + src: 'https://fonts.gstatic.com/s/inter/v19/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuLyfMZg.ttf', + fontWeight: 400, + }, + { + src: 'https://fonts.gstatic.com/s/inter/v19/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuI6fMZg.ttf', + fontWeight: 500, + }, + { + src: 'https://fonts.gstatic.com/s/inter/v19/UcCO3FwrK3iLTeHuS_nVMrMxCp50SjIw2boKoduKmMEVuGKYMZg.ttf', + fontWeight: 600, + }, + ], + }); + }); + } + return registrationPromise; + }; +})(); + export const exportBlockNoteEditorToPdf = async ( parsedBody: PartialBlock[], filename: string, ) => { + await registerInterFonts(); + const editor = BlockNoteEditor.create({ initialContent: parsedBody, });