tenta fix pdfservice.js

This commit is contained in:
rodrigo committed 2025-04-21 21:00:52 -03:00
1 parent 8d12d45621
commit 570f3408c9
1 file changed
+11 -11
+11 -11
View File
@@ -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; let font = null, fontBold = null, fontItalic = null, fontBoldItalic = null;
try { try {
const timesPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman.ttf'); const timesPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman.ttf');
const timesBoldPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-Bold.ttf'); const timesBoldPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-Bold.ttf');
const timesItalicPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-Italic.ttf'); const timesItalicPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-Italic.ttf');
const timesBoldItalicPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-BoldItalic.ttf'); const timesBoldItalicPath = path.join(process.cwd(), 'public', 'fonts', 'TimesNewRoman-BoldItalic.ttf');
const [times, timesBold, timesItalic, timesBoldItalic] = await Promise.all([ const [times, timesBoldBuf, timesItalicBuf, timesBoldItalicBuf] = await Promise.all([
fs.readFile(timesPath).catch(() => null), fs.readFile(timesPath).catch(() => undefined),
fs.readFile(timesBoldPath).catch(() => null), fs.readFile(timesBoldPath).catch(() => undefined),
fs.readFile(timesItalicPath).catch(() => null), fs.readFile(timesItalicPath).catch(() => undefined),
fs.readFile(timesBoldItalicPath).catch(() => null), fs.readFile(timesBoldItalicPath).catch(() => undefined),
]); ]);
if (times) font = await pdfDoc.embedFont(times); if (times && times.length > 0) font = await pdfDoc.embedFont(times);
if (timesBold) fontBold = await pdfDoc.embedFont(timesBold); if (timesBoldBuf && timesBoldBuf.length > 0) fontBold = await pdfDoc.embedFont(timesBoldBuf);
if (timesItalic) fontItalic = await pdfDoc.embedFont(timesItalic); if (timesItalicBuf && timesItalicBuf.length > 0) fontItalic = await pdfDoc.embedFont(timesItalicBuf);
if (timesBoldItalic) fontBoldItalic = await pdfDoc.embedFont(timesBoldItalic); if (timesBoldItalicBuf && timesBoldItalicBuf.length > 0) fontBoldItalic = await pdfDoc.embedFont(timesBoldItalicBuf);
} catch { /* fallback para Helvetica */ } } catch { /* fallback para Times padrão */ }
if (!font) font = await pdfDoc.embedFont(StandardFonts.TimesRoman); if (!font) font = await pdfDoc.embedFont(StandardFonts.TimesRoman);
if (!fontBold) fontBold = await pdfDoc.embedFont(StandardFonts.TimesBold); if (!fontBold) fontBold = await pdfDoc.embedFont(StandardFonts.TimesBold);
if (!fontItalic) fontItalic = await pdfDoc.embedFont(StandardFonts.TimesItalic); if (!fontItalic) fontItalic = await pdfDoc.embedFont(StandardFonts.TimesItalic);