如何使用domPDF在Laravel中打印刀片文件的某些部分

I have to create a pdf file with Laravel. So I install in my composer domPDF. But I have to generate the pdf with only some parts of my blade file. I've already tried to create a new blade file and include it in the old blade file, but this return to me errors as the new blade file can't get the data I passed with the controller, so what can I do?

This is the function I wrote

    public function printPDF(){
    $pdf = PDF::loadView('pages.newblade');
    return $pdf->download('document.pdf');
    }

Thanks

I am suggesting an option to refactor your code like this

public function printPDF(){
    $printthis = true;
    $pdf = PDF::loadView('pages.newblade', compact('printthis'));
    return $pdf->download('document.pdf');
}

on pages.newblade check printthis variable if present means show the printable content else show all like this

   @if(isset($printthis))
        //printable code goes here
   @else
        //General code goes here
   @endif