Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gaan10's avatar

want to create a pdf from the webpage created using dompdf

I have a webpage from where i want to transfer it to a pdf .But the issue is in my controller when i try to download it ,It says undefined variable which is the variable that was passed from another controller to the view so that the webpage gets generated.How will i access this variable or is there any other method. My Controller :

public function pdfview(Request $request)
    {
if($request->has('download'))
        {
            $pdf = PDF::loadView('pdffileview');
            return $pdf->download('pdfview.pdf');
        }
}

This is how i passed from my view:

<a href="{{ route('pdfview',['download'=>'pdf']) }}">Download PDF report</a> 

Plz have a look.Thanks in advance

0 likes
6 replies
gaan10's avatar

i have to use specifically dompdf only.

jaythanki's avatar

@GAAN10 sorry but i can't understand . Please can you provide more information about that how you want to use

gaan10's avatar

Actually a have a web UI which i want to download as a pdf ,once the user presses the download button.But pdf is not getting generated from the html. I am not able to render it via my controller,for which the code is shown above.Plz let me know where am i getting wrong.The error is undefined variable.I think this is causing because i have used another controller function to generate those variables.

gaan10's avatar
gaan10
OP
Best Answer
Level 1

i am using the blade templates. Need to pass the variable new_records to the 'pdffileview' something like this

$pdf = PDF::loadView('pdffileview',compact('new_records'));

Thanks anyways.

1 like

Please or to participate in this conversation.