harea costea
harea costea

Reputation: 19

Generate a pdf file using dompdf and CodeIgniter

I have a problem with generation pdf using CodeIgniter and dompdf, My code is:

public function generateTitlePage($name = '', $surname='', $number='', $village='')
{
    $this->load->library('dompdf_gen');
    $dompdf = new DOMPDF();
    $html = <<<HTML
        <html>
        <body>
            <h1>Hello:$name</h1><br />
            <h1>Hello:$surname</h1><br />
            <h1>Hello:$number</h1><br />
            <h1>Hello:$village</h1>
        </body>
        </html>
  HTML;
    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("welcome.pdf");
}

The resultat for this function is

Hello: Name Surname number village
Hello:
Hello:
Hello:

But I need to separate this:

Hello:Name
Hello:Surname
Hello:number
Hello:village

Help me please. The function is called:

 <a href="<?=base_url()."dosar/generateTitlePage($d[name]$d[surname]$d[number]$d[village])" ?>" class="btn btn-primary btn-sm marg-top-10">Generate</a>

Upvotes: 2

Views: 5580

Answers (1)

M Khalid Junaid
M Khalid Junaid

Reputation: 64486

The way you are generating your url is not correct you need to understand the routing first like

example.com/class/function/id/
  • example.com this is your domain
  • class this your controller name
  • function this your function name which reside in above mentioned controller
  • id this will be your 1st parameter which will be to your above mentioned function and same as you can pass as many parameters like
example.com/class/function/parameter1/parameter2/parameter3/

for your pdf url you can write your anchor as below

<a href="<?=base_url().'dosar/generateTitlePage/'. $d[name] .'/'. $d[surname] .'/'. $d[number] .'/'. $d[village])' ?>" class="btn btn-primary btn-sm marg-top-10">Generate</a>

Upvotes: 2

Related Questions