tenta fix pdfservice.js

This commit is contained in:
rodrigo committed 2025-04-22 10:04:59 -03:00
1 parent 3406723bd4
commit 85977d7229
1 file changed
+2 -1
+2 -1
View File
@@ -392,7 +392,6 @@ export class PdfService {
} }
} }
// Reformulação: sem recuo de parágrafo (nem blockquote, nem primeira linha)
let lines: { tokens: { text: string, font: any, underline: boolean, bold: boolean, italic: boolean }[] }[] = []; let lines: { tokens: { text: string, font: any, underline: boolean, bold: boolean, italic: boolean }[] }[] = [];
let currentTokens: { text: string, font: any, underline: boolean, bold: boolean, italic: boolean }[] = []; let currentTokens: { text: string, font: any, underline: boolean, bold: boolean, italic: boolean }[] = [];
let currentWidth = 0; let currentWidth = 0;
@@ -423,6 +422,7 @@ export class PdfService {
} }
let line = lines[i]; let line = lines[i];
let drawX = x; let drawX = x;
// Remove espaços no início e fim da linha para não justificar esses espaços // Remove espaços no início e fim da linha para não justificar esses espaços
let trimmedTokens = [...line.tokens]; let trimmedTokens = [...line.tokens];
while (trimmedTokens.length && /^\s+$/.test(trimmedTokens[0].text)) trimmedTokens.shift(); while (trimmedTokens.length && /^\s+$/.test(trimmedTokens[0].text)) trimmedTokens.shift();
@@ -430,6 +430,7 @@ export class PdfService {
let totalWidth = trimmedTokens.reduce((acc, t) => acc + t.font.widthOfTextAtSize(t.text, fontSize), 0); let totalWidth = trimmedTokens.reduce((acc, t) => acc + t.font.widthOfTextAtSize(t.text, fontSize), 0);
// Corrige centralização: centraliza a linha inteira, inclusive se for a única linha do parágrafo
if (align === 'center') { if (align === 'center') {
drawX = x + (maxWidth - totalWidth) / 2; drawX = x + (maxWidth - totalWidth) / 2;
for (const t of trimmedTokens) { for (const t of trimmedTokens) {