tenta fix pdfservice.js
This commit is contained in:
1 parent
fb17405fe9
commit
3edd6ed317
1 file changed
+16
-20
@@ -347,6 +347,22 @@ 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
|
||||||
@@ -387,26 +403,6 @@ export class PdfService {
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carregar o timbrado (se houver) e criar o PDF final
|
|
||||||
let pdfDoc: PDFDocument;
|
|
||||||
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();
|
|
||||||
pdfDoc = await PDFDocument.create();
|
|
||||||
// Copiar as páginas do timbrado como EMBEDDED PAGE (PDFEmbeddedPage)
|
|
||||||
timbradoPages = [];
|
|
||||||
for (let i = 0; i < timbradoPageCount; i++) {
|
|
||||||
const [embedded] = await pdfDoc.embedPages([timbradoPdf.getPage(i)]);
|
|
||||||
timbradoPages.push(embedded);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pdfDoc = await PDFDocument.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quebrar o texto em páginas
|
// Quebrar o texto em páginas
|
||||||
let currentPar = 0;
|
let currentPar = 0;
|
||||||
let currentLine = 0;
|
let currentLine = 0;
|
||||||
|
|||||||
Reference in new issue
Block a user