当我尝试打印pdf时出现此错误:
An uncaught Exception was encountered
Type: DOMException
Message: Invalid Character Error
Filename: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/TreeBuilder.php
Line Number: 3191
Backtrace:
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/TreeBuilder.php
Line: 3191
Function: setAttribute
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/TreeBuilder.php
Line: 1493
Function: insertElement
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/Tokenizer.php
Line: 2456
Function: emitToken
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/lib/html5lib/Tokenizer.php
Line: 1102
Function: emitToken
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf/src/Dompdf.php
Line: 470
Function: parse
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/helpers/dompdf_helper.php
Line: 26
Function: loadHtml
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/application/controllers/admin/Estimates.php
Line: 136
Function: pdf_create
File: /home/ireto/domains/ireto.be/public_html/madicbelgium/index.php
Line: 293
Function: require_once
这是我的代码在线:3191 - >
private function insertElement($token, $append = true) {
$el = $this->dom->createElementNS(self::NS_HTML, $token['name']);
if (!empty($token['attr'])) {
foreach ($token['attr'] as $attr) {
if (!$el->hasAttribute($attr['name']) && preg_match("/[^A-Za-z0-9]/u", $attr['name'])) {
$el->setAttribute($attr['name'], $attr['value']);
}
}
}
if ($append) {
$this->appendToRealParent($el);
$this->stack[] = $el;
}
return $el;
}
答案 0 :(得分:0)
如果您遇到类似An uncaught Exception was encountered
的错误,那么最好的办法就是实际捕获异常,因为您可以在Exception
以下代码段应该是我的意思
private function insertElement($token, $append = true) {
try
{
$el = $this->dom->createElementNS(self::NS_HTML, $token['name']);
if (!empty($token['attr'])) {
foreach ($token['attr'] as $attr) {
if (!$el->hasAttribute($attr['name']) && preg_match("/[^A-Za-z0-9]/u", $attr['name'])) {
$el->setAttribute($attr['name'], $attr['value']);
}
}
}
if ($append) {
$this->appendToRealParent($el);
$this->stack[] = $el;
}
return $el;
}
catch (DOMException $e)
{
echo '<strong>Errormessage:</strong>'.$e->getMessage().'<br />';
echo $e->getTraceAsString();
}
}
如果您现在有错误,您应该看到确切的信息以便修复此错误,如下所示:
Errormessage: Invalid Character Error
#0 [...][...](7): DOMElement->setAttribute('1pro-1', 'someValue')
#1 {main}DOMException Object