Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOMPDF_Exception "No block-level parent found. Not good." #137

Closed
TomasNiDo opened this issue Jun 30, 2015 · 27 comments
Closed

DOMPDF_Exception "No block-level parent found. Not good." #137

TomasNiDo opened this issue Jun 30, 2015 · 27 comments
Labels

Comments

@TomasNiDo
Copy link

Hi, im working on a project and I'm using your dompdf to create and render PDFs. Rendering PDFs is a success on my localhost but what's odd is it throws DOMPDF_Exception "No block-level parent found. Not good." error on live server. Any idea how to fix this?

Im using loadView() function..

@rayk-ri
Copy link

rayk-ri commented Oct 13, 2015

I'm having a similar issue when using the loadView method:

DOMPDF_Exception in inline_positioner.cls.php line 37:
No block-level parent found. Not good.

@NickOneTeam
Copy link

DOMPDF_Exception in inline_positioner.cls.php line 37:
No block-level parent found. Not good.

What is the problem?

http://prntscr.com/8rjf0j

@rayk-ri
Copy link

rayk-ri commented Oct 15, 2015

Here's how I'm using loadView:

$pdf = \App::make('dompdf.wrapper');
$pdf->loadView('foo.bar', $foobar);
return $pdf->stream();

Here's the stack trace I'm getting:

in inline_positioner.cls.php line 37
at Inline_Positioner->position() in frame_decorator.cls.php line 700
at Frame_Decorator->position() in text_frame_reflower.cls.php line 330
at Text_Frame_Reflower->reflow(null) in frame_decorator.cls.php line 711
at Frame_Decorator->reflow() in page_frame_reflower.cls.php line 123
at Page_Frame_Reflower->reflow(null) in frame_decorator.cls.php line 711
at Frame_Decorator->reflow() in dompdf.cls.php line 949
at DOMPDF->render() in PDF.php line 208
at PDF->render() in PDF.php line 154
at PDF->output() in PDF.php line 191
at PDF->stream() in RegistryController.php line 291

@NickOneTeam
Copy link

Guys, the problem in CSS.
I removed the CSS and it worked. DOMPDF use CSS 2.1.

@rayk-ri
Copy link

rayk-ri commented Oct 21, 2015

Worked for me too.
Thanks Nick!

@gplv2
Copy link

gplv2 commented Jul 7, 2016

I was able to fix this error by remove this CSS definition in de body section

        body {
           ...
           display: table;
           ...
        } 

Switched everything back on, even the fonts (who are responsible for massive delay when included) and it worked, so the display:table is the culprit here.

@FloKnapp
Copy link

Also try to prevent line breaks in your template (if you're using one) - this caused this error in my case.

@vaites
Copy link

vaites commented Sep 25, 2017

I have this problem on Mac OS X using any PHP version and libxml2 2.9.5 (I have different PHP versions compiled against it). I used the ugly hack for strip spaces between tags.

The bug is detailed on this dompdf issue: dompdf/dompdf#1494

@frin
Copy link

frin commented Oct 9, 2017

Thanks for that link @vaites I used another better solution on that page which is:

use Dompdf\Options;
$options = new Options();
$options->set('enable_html5_parser', true);
$dompdf = new Dompdf($options);

You have to set option enable_html5_parser to true, then it works again with libxml2 2.9.5 or newer.
This also fixed the issue of "Cannot redeclare ...." function, if you had any PHP functions inside the template/HTML.

@MuzaffarMahmood
Copy link

Dompdf was working fine with php5.5.12 but on changing php version to 7.0.25 it stopped working and throwing this error.

An uncaught Exception was encountered

Type: DOMPDF_Exception

Message: No block-level parent found. Not good.

Filename: D:\wamp\www\ci316\application\libraries\dompdf\include\inline_positioner.cls.php

Line Number: 37

How to resolve this????

I removed all css still not working.

@gbrits
Copy link

gbrits commented Oct 31, 2017

Removing the entire HEAD section fixed my issue. Use inline styles, like an EDM.

@gajendra1310
Copy link

After resolving all errors i am getting this error please give solution how to resolve this issue

An uncaught Exception was encountered

Type: DOMPDF_Exception

Message: No block-level parent found. Not good.

Filename: C:\xampp\htdocs\pdf_invoice\application\libraries\dompdf\include\inline_positioner.cls.php

Line Number: 37

Backtrace:

File: C:\xampp\htdocs\pdf_invoice\application\libraries\dompdf\include\frame_decorator.cls.php
Line: 679
Function: position

File: C:\xampp\htdocs\pdf_invoice\application\libraries\dompdf\include\text_frame_reflower.cls.php
Line: 330
Function: position

File: C:\xampp\htdocs\pdf_invoice\application\libraries\dompdf\include\frame_decorator.cls.php
Line: 690
Function: reflow

File: C:\xampp\htdocs\pdf_invoice\application\libraries\dompdf\include\page_frame_reflower.cls.php
Line: 123
Function: reflow

File: C:\xampp\htdocs\pdf_invoice\application\libraries\dompdf\include\frame_decorator.cls.php
Line: 690
Function: reflow

File: C:\xampp\htdocs\pdf_invoice\application\libraries\dompdf\include\dompdf.cls.php
Line: 937
Function: reflow

File: C:\xampp\htdocs\pdf_invoice\application\controllers\Welcome.php
Line: 26
Function: render

File: C:\xampp\htdocs\pdf_invoice\index.php
Line: 315
Function: require_once

@JoukeD
Copy link

JoukeD commented Nov 21, 2017

The solution from @frin seems to be doing the trick! Better than debugging your html template.
I used $dompdf->set_option('enable_html5_parser', TRUE); to enable the option.

@Nesdf
Copy link

Nesdf commented Dec 23, 2017

I fixed with "composer update"

@jglantonio
Copy link

I solved , deleting tag title.

@phoalmeida
Copy link

Hi,
I am not a programmer, but i am with that same problem. Here are the logs. How can i fix this issue?
I need step by step please. Can anyone help me?

[2018-01-22 12:09:31] production.ERROR: exception 'DOMPDF_Exception' with message 'No block-level parent found. Not good.' in /home/nfe/public_html/vendor/dompdf/dompdf/include/inline_positioner.cls.php:37
Stack trace:
#0 /home/nfe/public_html/vendor/dompdf/dompdf/include/frame_decorator.cls.php(700): Inline_Positioner->position()
#1 /home/nfe/public_html/vendor/dompdf/dompdf/include/text_frame_reflower.cls.php(330): Frame_Decorator->position()
#2 /home/nfe/public_html/vendor/dompdf/dompdf/include/frame_decorator.cls.php(711): Text_Frame_Reflower->reflow(NULL)
#3 /home/nfe/public_html/vendor/dompdf/dompdf/include/page_frame_reflower.cls.php(123): Frame_Decorator->reflow()
#4 /home/nfe/public_html/vendor/dompdf/dompdf/include/frame_decorator.cls.php(711): Page_Frame_Reflower->reflow(NULL)
#5 /home/nfe/public_html/vendor/dompdf/dompdf/include/dompdf.cls.php(949): Frame_Decorator->reflow()
#6 /home/nfe/public_html/app/models/Nfse.php(225): DOMPDF->render()
#7 /home/nfe/public_html/app/models/Nfse.php(645): Nfse::gerarPdf('6054', 'N15X-C16A', 'NFe_6054_df83dd...')
#8 /home/nfe/public_html/app/models/Nfse.php(567): Nfse::salvaNota(Array)
#9 /home/nfe/public_html/app/controllers/NfseController.php(164): Nfse::geraNota(Array, 6652, 169552, '2018-01-22')
#10 [internal function]: NfseController->postAdicionar('6652')
#11 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(231): call_user_func_array(Array, Array)
#12 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(93): Illuminate\Routing\Controller->callAction('postAdicionar', Array)
#13 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(62): Illuminate\Routing\ControllerDispatcher->call(Object(NfseController), Object(Illuminate\Routing\Route), 'postAdicionar')
#14 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(967): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'NfseController', 'postAdicionar')
#15 [internal function]: Illuminate\Routing\Router->Illuminate\Routing{closure}('6652')
#16 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(109): call_user_func_array(Object(Closure), Array)
#17 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1033): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#18 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(1001): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#19 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(775): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#20 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(745): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#21 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Session/Middleware.php(72): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#22 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php(47): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#23 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php(51): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#24 /home/nfe/public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#25 /home/nfe/public_html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(641): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#26 /home/nfe/public_html/public/index.php(80): Illuminate\Foundation\Application->run()
#27 {main} [] []

@phoalmeida
Copy link

phoalmeida commented Jan 29, 2018

This a message that i found on log after enable the log:
PHP Fatal error: Call to a member function get_node() on a non-object in /home/nfe/public_html/vendor/dompdf/dompdf/include/inline_positioner.cls.php on line 32

And this is the code near line 32:
if ( !$p )
throw new DOMPDF_Exception("No block-level parent found. Not good.");

$f = $this->_frame;

$cb = $f->get_containing_block();
$line = $p->get_current_line_box();

@DuncanFairley
Copy link

Just got this after a libxml2 update to 2.9.7.
I updated to dompdf 0.8.2 but the issue remains.

@tarhe
Copy link

tarhe commented May 8, 2018

Change:

public function loadView($view, $data = array(), $mergeData = array(), $encoding = null){
     $html = $this->view->make($view, $data, $mergeData)->render();
     return $this->loadHTML($html, $encoding);
 }

To:

public function loadView($view, $data = array(), $mergeData = array(), $encoding = null){
     $html = $this->view->make($view, $data, $mergeData)->render();
     $html = preg_replace('/>\s+</', '><', $html);
     return $this->loadHTML($html, $encoding);
 }

in /vendor/barryvdh/laravel-dompdf/src/PDF.php

Notice: $html = preg_replace('/>\s+</', '><', $html); in the second one.

@phoalmeida
Copy link

I didn't find any barryvdh/laravel-dompdf/src/PDF.php or public function loadView using grep.

Mine is dompdf, and on folder vendor there is only these folders:
composer filp laravel nesbot patchwork predis swiftmailer zizaco
bin d11wtq ircmaxell laravelbook nideia phenx psr symfony
classpreloader dompdf jeremeamia monolog nikic phpseclib stack zendframework

Any idea?

@victor-priceputu
Copy link

Had the same issue, for me it was caused by the html tag not being detected as a block-level parent.
Had to add the following CSS to fix it:
html, body { display: block; }

@vipinkumarvk
Copy link

"No block-level parent found. Not good."-if this is ur problem then the given below is one of its solution

Change lines 122 to 125 in /vendor/barryvdh/laravel-dompdf/src/PDF.php
From

public function loadView($view, $data = array(), $mergeData = array(), $encoding = null){
    $html = $this->view->make($view, $data, $mergeData)->render();
    return $this->loadHTML($html, $encoding);
}

To

public function loadView($view, $data = array(), $mergeData = array(), $encoding = null){
    $html = $this->view->make($view, $data, $mergeData)->render();
    $html = preg_replace('/>\s+</', '><', $html);
    return $this->loadHTML($html, $encoding);
}

@victor-priceputu
Copy link

NEVER change the code in your vendor folder. A pull request may be better than that. The next time you try to update the code, it will override the change and you are back to square 1. Plus how will you deploy? Normally the vendor folder is not supposed to be version controlled, so your change will not go beyond your local code.

My fix came with adding the following styling in the template:html, body {display: block;}

@markuszeller
Copy link

Enable before parsing via load_html(); solved it for me.
$oDompdf->set_option('enable_html5_parser', true);

@stale
Copy link

stale bot commented Jul 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/dompdf/dompdf instead. When having doubts, please try to reproduce the issue with just dompdf.
If you believe this is an actual issue with the latest version of laravel-dompdf, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.

@stale stale bot added the stale label Jul 29, 2020
@stale stale bot closed this as completed Aug 6, 2020
@nzrubin
Copy link

nzrubin commented Aug 11, 2020

try to minimize the HTML template for PDF (it will remove all the spaces and white spaces etc)
it worked for me

@alankarmore
Copy link

I was facing this same issue with Laravel 5.4 and "barryvdh/laravel-dompdf": "^0.7.1", but later I updated the version of dompdf to "barryvdh/laravel-dompdf": "^0.8", and issue resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests