From 570f3408c99fd838fb7b4d67f955fa4ee3981fe8 Mon Sep 17 00:00:00 2001 From: Rodrigo Martins Date: Mon, 21 Apr 2025 21:00:52 -0300 Subject: [PATCH] tenta fix pdfservice.js --- src/server/services/PdfService.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/server/services/PdfService.ts b/src/server/services/PdfService.ts index 7a78279..e3e7337 100644 --- a/src/server/services/PdfService.ts +++ b/src/server/services/PdfService.ts @@ -340,24 +340,24 @@ export class PdfService { } } - // Fonte Times New Roman (se disponível), senão Helvetica + // Fonte Times New Roman (se disponível), senão Times padrão do PDF-LIB let font = null, fontBold = null, fontItalic = null, fontBoldItalic = null; try { const timesPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman.ttf'); const timesBoldPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-Bold.ttf'); const timesItalicPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-Italic.ttf'); const timesBoldItalicPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-BoldItalic.ttf'); - const [times, timesBold, timesItalic, timesBoldItalic] = await Promise.all([ - fs.readFile(timesPath).catch(() => null), - fs.readFile(timesBoldPath).catch(() => null), - fs.readFile(timesItalicPath).catch(() => null), - fs.readFile(timesBoldItalicPath).catch(() => null), + const [times, timesBoldBuf, timesItalicBuf, timesBoldItalicBuf] = await Promise.all([ + fs.readFile(timesPath).catch(() => undefined), + fs.readFile(timesBoldPath).catch(() => undefined), + fs.readFile(timesItalicPath).catch(() => undefined), + fs.readFile(timesBoldItalicPath).catch(() => undefined), ]); - if (times) font = await pdfDoc.embedFont(times); - if (timesBold) fontBold = await pdfDoc.embedFont(timesBold); - if (timesItalic) fontItalic = await pdfDoc.embedFont(timesItalic); - if (timesBoldItalic) fontBoldItalic = await pdfDoc.embedFont(timesBoldItalic); - } catch { /* fallback para Helvetica */ } + if (times && times.length > 0) font = await pdfDoc.embedFont(times); + if (timesBoldBuf && timesBoldBuf.length > 0) fontBold = await pdfDoc.embedFont(timesBoldBuf); + if (timesItalicBuf && timesItalicBuf.length > 0) fontItalic = await pdfDoc.embedFont(timesItalicBuf); + if (timesBoldItalicBuf && timesBoldItalicBuf.length > 0) fontBoldItalic = await pdfDoc.embedFont(timesBoldItalicBuf); + } catch { /* fallback para Times padrão */ } if (!font) font = await pdfDoc.embedFont(StandardFonts.TimesRoman); if (!fontBold) fontBold = await pdfDoc.embedFont(StandardFonts.TimesBold); if (!fontItalic) fontItalic = await pdfDoc.embedFont(StandardFonts.TimesItalic);