[Solved] PDF Report Generation

I have two queestions regarding PDF report generation.

  1. How do I change the orientation of the PDF before it gets generated?

  2. I’d like to add a “Print Receipt” button on the invoice section and generate a PDF receipt. How do I call the function to print PDF docuents?

  1. For this you would have to change something in the code but I have to look it up first. You could search on your own. the used engine is mPDF.
  2. Do you mean this? (right side)

Regarding the poge orientation, I’ll have a search of mPDF documentation. I’ll let you know if I’ve come up with soething.

About the printing of a receipt, yes, that is exactly where I’d like to put the “Print Receipt” option.

But if you print a receipt… if would be the invoice itself?! Or what should the receipt be like?

You will have to by-pass the pdf_create() function in helpers/mpdf.php and deal with mpdf directly as explained in these posts:

and in the mpdf manual

For instance, to get the invoice aging report in landscape you would rewrite the corresponding function in modules/reports/controllers/reports.php as:

public function invoice_aging()
{
    if ($this->input->post('btn_submit'))
    {
        $data = array(
            'results' => $this->mdl_reports->invoice_aging()    
    );

    $html = $this->load->view('reports/invoice_aging', $data, TRUE);

    // we are not using the mpdf helper
    // $this->load->helper('mpdf');
    // pdf_create($html, lang('invoice_aging'), TRUE);

    // but we need the mpdf library
    require_once(APPPATH . 'helpers/mpdf/mpdf.php');
        
    $mpdf = new mPDF('c', 'A4-L');    
    $mpdf->SetAutoFont();
    $mpdf->WriteHTML($html);
    $mpdf->Output($filename . '.pdf', 'I');
    }
    $this->layout->buffer('content', 'reports/invoice_aging_index')->render();
}

where “A4-L” indicates the page size and orientation.

Miquel

1 Like

Thanks for the tip, Miquel!

@Kovah : The layout is totally different but does use the invoice details.

Hi @Kovah: Anty feedback on how I can achieve this?

Sorry I forgot to answer.
If the layout is the only thing that is different you could choose another layout in the settings but directly set do this from the invoice overview wouldn’t be possible at the moment.

I’m not sure I understand what you mean. I was thinking of assigning the “Paid” pdf temlate as the receipt. How would I then create a link to generate that PDF?

No I would not do this as the Paid template will be used automatically by the system.

thanks for the advice! when you said in your previous comment “choose another layout in the settings”, di you mean that I would have to change the default invoice to the “receipt layout”, and download/print the resulting pdf, thn revert back to the default invoice temoplate?

Yes you would have to change the template for each receipt.