tenta fix pdfservice.js
This commit is contained in:
1 parent
3529bffbbb
commit
49dba7c9be
1 file changed
+22
-9
@@ -379,33 +379,46 @@ export class PdfService {
|
|||||||
let textParts = [];
|
let textParts = [];
|
||||||
|
|
||||||
// Processa texto com formatação - remover tags HTML e aplicar estilos
|
// Processa texto com formatação - remover tags HTML e aplicar estilos
|
||||||
let processedText = '';
|
|
||||||
let currentFont = normalFont;
|
let currentFont = normalFont;
|
||||||
let boldActive = false;
|
let boldActive = false;
|
||||||
let italicActive = false;
|
let italicActive = false;
|
||||||
|
|
||||||
|
// Simplificar texto antes de processar para evitar loops infinitos
|
||||||
|
// Remove tags não suportadas como <u>, <span>, etc.
|
||||||
|
text = text
|
||||||
|
.replace(/<u>|<\/u>/gi, '') // Remover tags de sublinhado
|
||||||
|
.replace(/<span[^>]*>|<\/span>/gi, '') // Remover tags span
|
||||||
|
.replace(/<[^>]*style=[^>]*>/gi, '') // Remover atributos style
|
||||||
|
.replace(/<(?!\/?(?:b|i|strong|em)(?!\w)[^>]*>)[^>]*>/gi, ''); // Manter apenas b, i, strong, em
|
||||||
|
|
||||||
// Primeiro, extrair partes do texto com suas formatações
|
// Primeiro, extrair partes do texto com suas formatações
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (i < text.length) {
|
while (i < text.length) {
|
||||||
if (text.substring(i, i+3) === '<b>') {
|
// Limite de segurança para evitar loops infinitos
|
||||||
|
if (textParts.length > 1000) {
|
||||||
|
console.error('Limite de processamento de texto excedido');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text.substring(i, i+3) === '<b>' || text.substring(i, i+7) === '<strong>') {
|
||||||
boldActive = true;
|
boldActive = true;
|
||||||
currentFont = italicActive ? boldItalicFont : boldFont;
|
currentFont = italicActive ? boldItalicFont : boldFont;
|
||||||
i += 3;
|
i += text.substring(i, i+3) === '<b>' ? 3 : 7;
|
||||||
}
|
}
|
||||||
else if (text.substring(i, i+4) === '</b>') {
|
else if (text.substring(i, i+4) === '</b>' || text.substring(i, i+8) === '</strong>') {
|
||||||
boldActive = false;
|
boldActive = false;
|
||||||
currentFont = italicActive ? italicFont : normalFont;
|
currentFont = italicActive ? italicFont : normalFont;
|
||||||
i += 4;
|
i += text.substring(i, i+4) === '</b>' ? 4 : 8;
|
||||||
}
|
}
|
||||||
else if (text.substring(i, i+3) === '<i>') {
|
else if (text.substring(i, i+3) === '<i>' || text.substring(i, i+4) === '<em>') {
|
||||||
italicActive = true;
|
italicActive = true;
|
||||||
currentFont = boldActive ? boldItalicFont : italicFont;
|
currentFont = boldActive ? boldItalicFont : italicFont;
|
||||||
i += 3;
|
i += text.substring(i, i+3) === '<i>' ? 3 : 4;
|
||||||
}
|
}
|
||||||
else if (text.substring(i, i+4) === '</i>') {
|
else if (text.substring(i, i+4) === '</i>' || text.substring(i, i+5) === '</em>') {
|
||||||
italicActive = false;
|
italicActive = false;
|
||||||
currentFont = boldActive ? boldFont : normalFont;
|
currentFont = boldActive ? boldFont : normalFont;
|
||||||
i += 4;
|
i += text.substring(i, i+4) === '</i>' ? 4 : 5;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Encontrar o próximo início de tag
|
// Encontrar o próximo início de tag
|
||||||
|
|||||||
Reference in new issue
Block a user