Skip to content

The Open Source DocuSign Alternative.

fix: unable to load font for signing

Mythie823034911487
diff --git a/apps/marketing/next.config.js b/apps/marketing/next.config.js
index d2b20fbb9..41a80c12c 100644
--- a/apps/marketing/next.config.js
+++ b/apps/marketing/next.config.js
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
+const fs = require('fs');
const path = require('path');
const { withContentlayer } = require('next-contentlayer');
@@ -10,6 +11,12 @@ ENV_FILES.forEach((file) => {
});
});
+// !: This is a temp hack to get caveat working without placing it back in the public directory.
+// !: By inlining this at build time we should be able to sign faster.
+const FONT_CAVEAT_BYTES = fs.readFileSync(
+ path.join(__dirname, '../../packages/assets/fonts/caveat.ttf'),
+);
+
/** @type {import('next').NextConfig} */
const config = {
experimental: {
@@ -17,9 +24,16 @@ const config = {
outputFileTracingRoot: path.join(__dirname, '../../'),
},
reactStrictMode: true,
- transpilePackages: ['@documenso/lib', '@documenso/prisma', '@documenso/trpc', '@documenso/ui'],
+ transpilePackages: [
+ '@documenso/assets',
+ '@documenso/lib',
+ '@documenso/tailwind-config',
+ '@documenso/trpc',
+ '@documenso/ui',
+ ],
env: {
NEXT_PUBLIC_PROJECT: 'marketing',
+ FONT_CAVEAT_URI: `data:font/ttf;base64,${FONT_CAVEAT_BYTES.toString('base64')}`,
},
modularizeImports: {
'lucide-react': {
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index ed1136d91..97af05ab5 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
+const fs = require('fs');
const path = require('path');
const { version } = require('./package.json');
@@ -10,6 +11,12 @@ ENV_FILES.forEach((file) => {
});
});
+// !: This is a temp hack to get caveat working without placing it back in the public directory.
+// !: By inlining this at build time we should be able to sign faster.
+const FONT_CAVEAT_BYTES = fs.readFileSync(
+ path.join(__dirname, '../../packages/assets/fonts/caveat.ttf'),
+);
+
/** @type {import('next').NextConfig} */
const config = {
output: process.env.DOCKER_OUTPUT ? 'standalone' : undefined,
@@ -19,15 +26,18 @@ const config = {
},
reactStrictMode: true,
transpilePackages: [
+ '@documenso/assets',
+ '@documenso/ee',
'@documenso/lib',
'@documenso/prisma',
+ '@documenso/tailwind-config',
'@documenso/trpc',
'@documenso/ui',
- '@documenso/email',
],
env: {
APP_VERSION: version,
NEXT_PUBLIC_PROJECT: 'web',
+ FONT_CAVEAT_URI: `data:font/ttf;base64,${FONT_CAVEAT_BYTES.toString('base64')}`,
},
modularizeImports: {
'lucide-react': {
diff --git a/package-lock.json b/package-lock.json
index f7d0e2a5d..c11ccd14d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -19715,6 +19715,7 @@
"@aws-sdk/cloudfront-signer": "^3.410.0",
"@aws-sdk/s3-request-presigner": "^3.410.0",
"@aws-sdk/signature-v4-crt": "^3.410.0",
+ "@documenso/assets": "*",
"@documenso/email": "*",
"@documenso/prisma": "*",
"@documenso/signing": "*",
diff --git a/package.json b/package.json
index d21af733e..8c154401c 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,7 @@
"build": "turbo run build",
"build:web": "turbo run build --filter=@documenso/web",
"dev": "turbo run dev --filter=@documenso/web --filter=@documenso/marketing",
- "start": "cd apps && cd web && next start",
+ "start": "turbo run start --filter=@documenso/web --filter=@documenso/marketing",
"lint": "turbo run lint",
"lint:fix": "turbo run lint:fix",
"format": "prettier --write \"**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts,mdx}\"",
diff --git a/packages/lib/package.json b/packages/lib/package.json
index 482866d63..56be5a7f0 100644
--- a/packages/lib/package.json
+++ b/packages/lib/package.json
@@ -20,6 +20,7 @@
"@aws-sdk/cloudfront-signer": "^3.410.0",
"@aws-sdk/s3-request-presigner": "^3.410.0",
"@aws-sdk/signature-v4-crt": "^3.410.0",
+ "@documenso/assets": "*",
"@documenso/email": "*",
"@documenso/prisma": "*",
"@documenso/signing": "*",
diff --git a/packages/lib/server-only/pdf/insert-field-in-pdf.ts b/packages/lib/server-only/pdf/insert-field-in-pdf.ts
index 9da0e0bf1..dde46ba6b 100644
--- a/packages/lib/server-only/pdf/insert-field-in-pdf.ts
+++ b/packages/lib/server-only/pdf/insert-field-in-pdf.ts
@@ -2,7 +2,6 @@ import fontkit from '@pdf-lib/fontkit';
import { PDFDocument, StandardFonts } from 'pdf-lib';
import {
- CAVEAT_FONT_PATH,
DEFAULT_HANDWRITING_FONT_SIZE,
DEFAULT_STANDARD_FONT_SIZE,
MIN_HANDWRITING_FONT_SIZE,
@@ -10,12 +9,12 @@ import {
} from '@documenso/lib/constants/pdf';
import { FieldType } from '@documenso/prisma/client';
import { isSignatureFieldType } from '@documenso/prisma/guards/is-signature-field';
-import { FieldWithSignature } from '@documenso/prisma/types/field-with-signature';
+import type { FieldWithSignature } from '@documenso/prisma/types/field-with-signature';
export const insertFieldInPDF = async (pdf: PDFDocument, field: FieldWithSignature) => {
- // Fetch the font file from the public URL.
- const fontResponse = await fetch(CAVEAT_FONT_PATH);
- const fontCaveat = await fontResponse.arrayBuffer();
+ const fontCaveat = await fetch(process.env.FONT_CAVEAT_URI).then(async (res) =>
+ res.arrayBuffer(),
+ );
const isSignatureField = isSignatureFieldType(field.type);
diff --git a/packages/tsconfig/process-env.d.ts b/packages/tsconfig/process-env.d.ts
index 491b84012..749cfcc43 100644
--- a/packages/tsconfig/process-env.d.ts
+++ b/packages/tsconfig/process-env.d.ts
@@ -62,6 +62,7 @@ declare namespace NodeJS {
VERCEL_URL?: string;
DEPLOYMENT_TARGET?: 'webapp' | 'marketing';
+ FONT_CAVEAT_URI: string;
POSTGRES_URL?: string;
DATABASE_URL?: string;
diff --git a/turbo.json b/turbo.json
index 0dac59203..0f0038887 100644
--- a/turbo.json
+++ b/turbo.json
@@ -85,6 +85,7 @@
"VERCEL_ENV",
"VERCEL_URL",
"DEPLOYMENT_TARGET",
+ "FONT_CAVEAT_URI",
"POSTGRES_URL",
"DATABASE_URL",
"POSTGRES_PRISMA_URL",