tenta fix pdfservice.js
This commit is contained in:
1 parent
3edd6ed317
commit
8d12d45621
1 file changed
+16
-16
@@ -324,6 +324,22 @@ export class PdfService {
|
|||||||
// Quebra o texto em parágrafos (mantendo quebras de linha duplas como parágrafo)
|
// Quebra o texto em parágrafos (mantendo quebras de linha duplas como parágrafo)
|
||||||
const paragrafos = texto.split(/\n{2,}/).map(p => p.trim()).filter(Boolean);
|
const paragrafos = texto.split(/\n{2,}/).map(p => p.trim()).filter(Boolean);
|
||||||
|
|
||||||
|
// Carregar o timbrado (se houver) e criar o PDF final
|
||||||
|
let pdfDoc: PDFDocument = await PDFDocument.create();
|
||||||
|
let timbradoPdf: PDFDocument | null = null;
|
||||||
|
let timbradoPageCount = 0;
|
||||||
|
let timbradoPages: any[] = [];
|
||||||
|
if (timbradoExists) {
|
||||||
|
const timbradoBytes = await fs.readFile(timbradoPath);
|
||||||
|
timbradoPdf = await PDFDocument.load(timbradoBytes);
|
||||||
|
timbradoPageCount = timbradoPdf.getPageCount();
|
||||||
|
timbradoPages = [];
|
||||||
|
for (let i = 0; i < timbradoPageCount; i++) {
|
||||||
|
const [embedded] = await pdfDoc.embedPages([timbradoPdf.getPage(i)]);
|
||||||
|
timbradoPages.push(embedded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fonte Times New Roman (se disponível), senão Helvetica
|
// Fonte Times New Roman (se disponível), senão Helvetica
|
||||||
let font = null, fontBold = null, fontItalic = null, fontBoldItalic = null;
|
let font = null, fontBold = null, fontItalic = null, fontBoldItalic = null;
|
||||||
try {
|
try {
|
||||||
@@ -347,22 +363,6 @@ export class PdfService {
|
|||||||
if (!fontItalic) fontItalic = await pdfDoc.embedFont(StandardFonts.TimesItalic);
|
if (!fontItalic) fontItalic = await pdfDoc.embedFont(StandardFonts.TimesItalic);
|
||||||
if (!fontBoldItalic) fontBoldItalic = fontBold;
|
if (!fontBoldItalic) fontBoldItalic = fontBold;
|
||||||
|
|
||||||
// Carregar o timbrado (se houver) e criar o PDF final
|
|
||||||
let pdfDoc: PDFDocument = await PDFDocument.create();
|
|
||||||
let timbradoPdf: PDFDocument | null = null;
|
|
||||||
let timbradoPageCount = 0;
|
|
||||||
let timbradoPages: any[] = [];
|
|
||||||
if (timbradoExists) {
|
|
||||||
const timbradoBytes = await fs.readFile(timbradoPath);
|
|
||||||
timbradoPdf = await PDFDocument.load(timbradoBytes);
|
|
||||||
timbradoPageCount = timbradoPdf.getPageCount();
|
|
||||||
timbradoPages = [];
|
|
||||||
for (let i = 0; i < timbradoPageCount; i++) {
|
|
||||||
const [embedded] = await pdfDoc.embedPages([timbradoPdf.getPage(i)]);
|
|
||||||
timbradoPages.push(embedded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Função para quebrar texto em linhas respeitando largura máxima e manter quebras de linha simples
|
// Função para quebrar texto em linhas respeitando largura máxima e manter quebras de linha simples
|
||||||
function wrapTextStyled(text: string, font: any, fontBold: any, fontItalic: any, fontBoldItalic: any, fontSize: number, maxWidth: number, indent: boolean, align: string, bold: boolean, italic: boolean): { text: string, font: any, indent: boolean, align: string, bold: boolean, italic: boolean }[] {
|
function wrapTextStyled(text: string, font: any, fontBold: any, fontItalic: any, fontBoldItalic: any, fontSize: number, maxWidth: number, indent: boolean, align: string, bold: boolean, italic: boolean): { text: string, font: any, indent: boolean, align: string, bold: boolean, italic: boolean }[] {
|
||||||
// Mantém quebras de linha simples para espaçamento
|
// Mantém quebras de linha simples para espaçamento
|
||||||
|
|||||||
Reference in new issue
Block a user