tenta fix pdfservice.js
This commit is contained in:
1 parent
0121f67c65
commit
cb47df6e88
1 file changed
+44
-25
@@ -412,6 +412,11 @@ export class PdfService {
|
||||
lines.push({ tokens: currentTokens });
|
||||
}
|
||||
|
||||
// Ajuste: Força alinhamento consistente para todas as linhas do parágrafo
|
||||
// Se align === 'center', todas as linhas centralizadas
|
||||
// Se align === 'justify', todas as linhas justificadas (inclusive a última)
|
||||
// Se align === 'left' ou outro, todas à esquerda
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (y < bottomMargin + fontSize * 1.5) {
|
||||
return null;
|
||||
@@ -420,13 +425,29 @@ export class PdfService {
|
||||
let drawX = x;
|
||||
let totalWidth = line.tokens.reduce((acc, t) => acc + t.font.widthOfTextAtSize(t.text, fontSize), 0);
|
||||
|
||||
// Alinhamento
|
||||
if (align === 'center') {
|
||||
drawX = x + (maxWidth - totalWidth) / 2;
|
||||
} else if (align === 'right') {
|
||||
drawX = x + (maxWidth - totalWidth);
|
||||
} else if (align === 'justify' && i !== lines.length - 1 && line.tokens.length > 1) {
|
||||
// Justify: distribui espaço entre palavras (menos na última linha)
|
||||
for (const t of line.tokens) {
|
||||
page.drawText(t.text, {
|
||||
x: drawX,
|
||||
y,
|
||||
size: fontSize,
|
||||
font: t.font,
|
||||
color
|
||||
});
|
||||
if (t.underline && t.text.trim() !== '') {
|
||||
const underlineY = y - 1.5;
|
||||
page.drawLine({
|
||||
start: { x: drawX, y: underlineY },
|
||||
end: { x: drawX + t.font.widthOfTextAtSize(t.text, fontSize), y: underlineY },
|
||||
thickness: 0.75,
|
||||
color
|
||||
});
|
||||
}
|
||||
drawX += t.font.widthOfTextAtSize(t.text, fontSize);
|
||||
}
|
||||
} else if (align === 'justify') {
|
||||
// Justify: distribui espaço entre palavras em TODAS as linhas
|
||||
const spaces = line.tokens.filter(t => /^\s+$/.test(t.text));
|
||||
const numSpaces = spaces.length;
|
||||
const lineTextWidth = line.tokens.reduce((acc, t) => acc + t.font.widthOfTextAtSize(t.text, fontSize), 0);
|
||||
@@ -459,29 +480,27 @@ export class PdfService {
|
||||
localDrawX += t.font.widthOfTextAtSize(t.text, fontSize);
|
||||
}
|
||||
}
|
||||
y -= fontSize * 1.5;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Alinhamento padrão (esquerda, centro, direita)
|
||||
for (const t of line.tokens) {
|
||||
page.drawText(t.text, {
|
||||
x: drawX,
|
||||
y,
|
||||
size: fontSize,
|
||||
font: t.font,
|
||||
color
|
||||
});
|
||||
if (t.underline && t.text.trim() !== '') {
|
||||
const underlineY = y - 1.5;
|
||||
page.drawLine({
|
||||
start: { x: drawX, y: underlineY },
|
||||
end: { x: drawX + t.font.widthOfTextAtSize(t.text, fontSize), y: underlineY },
|
||||
thickness: 0.75,
|
||||
} else {
|
||||
// Alinhamento à esquerda (padrão)
|
||||
for (const t of line.tokens) {
|
||||
page.drawText(t.text, {
|
||||
x: drawX,
|
||||
y,
|
||||
size: fontSize,
|
||||
font: t.font,
|
||||
color
|
||||
});
|
||||
if (t.underline && t.text.trim() !== '') {
|
||||
const underlineY = y - 1.5;
|
||||
page.drawLine({
|
||||
start: { x: drawX, y: underlineY },
|
||||
end: { x: drawX + t.font.widthOfTextAtSize(t.text, fontSize), y: underlineY },
|
||||
thickness: 0.75,
|
||||
color
|
||||
});
|
||||
}
|
||||
drawX += t.font.widthOfTextAtSize(t.text, fontSize);
|
||||
}
|
||||
drawX += t.font.widthOfTextAtSize(t.text, fontSize);
|
||||
}
|
||||
y -= fontSize * 1.5;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user