Welcome Guest, Not a member yet? Register   Sign In
redirect or load->view() --- isn't in my dompdf controller!!?!?
#1

[eluser]PeteSig[/eluser]
Hi

I've got a contriller which uses dompdf to create a pdf, after which I've tried to redirect or load->view, but neither option seems to work - in the debugger the code is run, but seems to be ignored.

What I'm trying to do is have some sort of progress bar / page / etc load on entry to the printpdf controller function, then the controller does the pdf creation (using dompdf), after which I refresh the calling page.

My controller is here:
Code:
function print_order($ids)
{
    //if I do redirect here, then I get redirceted & the code below doesn't do its stuff
    // tried doing $this->load->view() instead, but it doesn't!!!

    if(isset($ids))
    {
        $invoice_html = createHtml();

        // create the pdf
        $dompdf = new DOMPDF();
        // create a path to the base of this app
        // ie. C:/...... or /..... , etc
        $inf = pathinfo(__FILE__);
        $bp = $inf['dirname'];
        // this file is in applocation/views, so need to go up 2 levels to get to
        $bp = $bp . '/../..';
        $dompdf->set_base_path($bp);
        $dompdf->load_html($invoice_html);
        $dompdf->render();
        $dompdf->stream("invoice-" . $ids .  ".pdf");
    }

    // reload the calling page
        // - doesn't do anything!!!!
    redirect('admin/orders', 'refresh');
    // tried doing $this->load->view() instead, but it doesn't!!!
}


Anyone got any ideas?

Cheers

Pete
#2

[eluser]matt.asbury[/eluser]
If you put:
Code:
$dompdf->stream("invoice-" . $ids .  ".pdf");
die("test");
what happens when you run the code? If you do not see the die statement in the browser, your code is failing somewhere in the $dompdf object.
#3

[eluser]PeteSig[/eluser]
Hi thanks for the reply & suggestion.

I put the die('test'); straight after the $dompdf->stream() call & I did not see any die message!!!

However, dompdf does seem to work, as an alert box opens asking if I want to open the pdf or cancel. When I click open the pdf is displayed.

Also, if I walk through the code in the debugger the die line allows me to F8 on it, at which point I exit the debugger.

So, I'm baffled!?!?

Pete
#4

[eluser]matt.asbury[/eluser]
Move the die("test"); up one line at a time until you see the "test" statement. The line following this should then be the one causing you problems.
#5

[eluser]PeteSig[/eluser]
Yep, its the
Code:
$dompdf->stream("invoice--" . $ids .  ".pdf");
line which is giving the weird behaviour.


Its as if its taking the 'focus' away from codeigniter code!

If I put the redirect() above this line then I get redirected, but then I don't get option to open the pdf page. If the redirect is after this line (or the die, or anyother php) then I get the option to see the generated pdf, but the rest of the code isn't carried out (even though I can walk over it in the debugger!!).

So, still stumped. How have other displayed pdf's gen'd by dompdf in the past?
I'll have a search of the forum; but any suggestions are most welcome.

Cheers

Pete
#6

[eluser]Bastian Heist[/eluser]
How are you running php anyway? Since you get a popup I assume you're using it in some kind of local environment? Can you give us some info here?
#7

[eluser]PeteSig[/eluser]
Okay, I used:
Code:
$pdf = $dompdf->output();
file_put_contents("tmp.pdf", $pdf);

instead of the stream function.

this saved the pdf to disk & then redirected me as I wanted, guess I just need to display the pdf in the page I redirect to.

Oh, and display a progress bar or something whilst dompdf is rendering the pdf (which can take a few seconds - depending on size of text to be pdf'ed).

Many thanks for your help.

Pete
#8

[eluser]PeteSig[/eluser]
Not sure I understand what you meant by how am I using php?!

I'm developing locally, with xammp.

I have a list of orders, with check boxes and a print button off to one side.

Depending upon which check boxes are checked, the print button 'activates' a controller, which in turn gets info for each order from a db. This info is then used to generates html, which dompdf uses to generate a pdf.

The intention is / was that the user will then be able to save the pdf &/or print the pdf off as a hard copy.

Pete
#9

[eluser]Bastian Heist[/eluser]
OK, I just seem to have misunderstood you. Good luck with your development!
#10

[eluser]PeteSig[/eluser]
Thanks for takingthe time to help Bastian, its much appreciated.

Pete




Theme © iAndrew 2016 - Forum software by © MyBB