Error : “SyntaxError : Unexpected token: <” in the advanced pdf.

This error is to check for invalid XML characters [<, >, “, ‘, &] in the template. These characters need to be replaced with the corresponding Escape String as shown below.

<       &lt;

>       &gt;

”      &quot;

‘      &apos;

&    &amp;

Using the below mentioned function, we can solve the issue.

function escapeXml(unsafe){

try{
if(unsafe) {
log.debug("inside escape");

return unsafe.replace(/[<>&'"]/g, function (c) {

switch (c) {

case '<':

return '&lt;';

case '>':

return '&gt;';

case '&':

return '&amp;';

case '\'':

return '&apos;';

case '"':

return '&quot;';

}

});

}

}

catch (e) {

log.debug("error@unsafe", e.message)

}

}

Using this function in the variables, which store the special characcters.

Eg:   obj.loc_address1=escapeXml(loc_address1);

 

Leave a comment

Your email address will not be published. Required fields are marked *