Welcome Guest, Not a member yet? Register   Sign In
calling library function stops foreach loop
#1

I am building a app that requires the production of pdf files. I am using FPDF and FPDI. Sometimes the app requires the calling of the library class multiple times in the form a foreach loop. But everytime when I am in need of multiple calls it stops after the first one. Also the library class seems to refresh to a blanck window.

If anyone can produce a logical explenation I would be very happy.

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * Maak een pdf
 */
class CreatePdf
{
    /**
     * Maak de pdf
     * @param $data collectie van input data
     * @param $sourceFile basis pdf bestands locatie
     *  */ 
    public function create($data$sourceFile)
    {
        require_once('PDF_Textbox.php');

        // initializeer FPDI in ladnscape 
        // $pdf = new Fpdi('L');
        $pdf = new PDF_TextBox('L');

        // Nieuwe pagina
        $pdf->AddPage();
        $pdf->setSourceFile($sourceFile);
        $tpl $pdf->importPage(1);

        /* Gebruik de nieuwe pagina als een template op de achtergrond
         * Dit met de volledige breedte en hoogte */
        $pdf->useTemplate($tpl00nullnull);

        // Set font en kleur
        $pdf->SetFont('Helvetica''B'8);
        $pdf->SetTextColor(000);

        foreach($data['single'] as $single)
        {
            $pdf->Text($single[0], $single[1], $single[2]);
        }

        foreach($data['textbox'] as $textbox)
        {
            $pdf->SetXY($textbox[0], $textbox[1]);
            $pdf->drawTextBox($textbox[2], $textbox[3], $textbox[4], $textbox[5], $textbox[6], $textbox[7]);
        }

        /* Output our new pdf into a file
         * F = Write local file
         * I = Send to standard output (browser)
         * D = Download file
         * S = Return PDF as a string */
        $pdf->Output(APPPATH '../docs/s627-'date("d-m-Y-H.i.s") .'.pdf''F');   
    



PHP Code:
/**
     * Verzamel alle data en creeër de documenten
     */
    public function create_s627()
    {
        $input $this->collectInput();
        if(!empty($input))
        {
            $sourceFiles $this->getSourceFiles($input['checkbox']);
            foreach($sourceFiles as $sourceFile)
            {
                $this->createpdf->create($input$sourceFile);
            }
        }
        else
        {
            echo "Data was leeg";
        }
    
Code:
Array of sourcefile
array(3) {
  [0]=>
  string(31) "./assets/base/S627-bis-lvhw.pdf"
  [1]=>
  string(29) "./assets/base/S627-bis-wl.pdf"
  [2]=>
  string(22) "./assets/base/S627.pdf"
}
Reply
#2

Are you sure collectInput always return the expected data?
Your code is probably crashing on a fatal error. Check your log files.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

The issue was with the speed of wich the files where created. I was in the assumption that using a time based name of the file was the smart way to go. But the file was just overwritten by the one created after it.

So the name of the game was using the name of the start pdf in the actual name.

As for the blanck page. If you don't tell the method to redirect or load new pages it goes blanck
Reply




Theme © iAndrew 2016 - Forum software by © MyBB