tenta fix pdfservice.js
This commit is contained in:
1 parent
8d12d45621
commit
570f3408c9
1 file changed
+11
-11
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user