tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.18k stars 1.51k forks source link

Message: preg_split(): Argument #2 ($subject) must be of type string, array given #635

Closed theshafat closed 1 year ago

theshafat commented 1 year ago

I am using TCPDF with codeigniter 3, and facing these errors.

An uncaught Exception was encountered Type: TypeError

Message: preg_split(): Argument #2 ($subject) must be of type string, array given

Filename: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\include\tcpdf_static.php

Line Number: 1779

Backtrace:

File: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\include\tcpdf_static.php Line: 1779 Function: preg_split

File: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\include\tcpdf_fonts.php Line: 2005 Function: pregSplit

File: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\tcpdf.php Line: 6408 Function: UTF8StringToArray

File: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\tcpdf.php Line: 5985 Function: Write

File: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\tcpdf.php Line: 3510 Function: MultiCell

File: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\tcpdf.php Line: 3614 Function: Header

File: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\tcpdf.php Line: 3281 Function: setHeader

File: D:\xampp\htdocs\investus\application\libraries\TCPDF-main\tcpdf.php Line: 3193 Function: startPage

File: D:\xampp\htdocs\investus\application\controllers\Pdfreport.php Line: 125 Function: AddPage

File: D:\xampp\htdocs\investus\index.php Line: 317 Function: require_once

williamdes commented 1 year ago

Can you share the sample code used to trigger this error?

theshafat commented 1 year ago
<?php

require_once APPPATH . "libraries/TCPDF-main/tcpdf.php";

class Pdfreport extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->library("Pdf");

    }

    public function index()
    {

        $pdf = new Pdf("P", "mm", "A4", true, "UTF-8", false);
        // create new PDF document
        //$pdf->SetTitle('My Title');
        $pdf->SetTopMargin(0);
        $pdf->setFooterMargin(0);
        $pdf->SetAutoPageBreak(true);
        $pdf->SetFont("helvetica", "", 10, "", "default", true);

      //  $pdf->SetFont("roboto", "", 10, "", "default", true);

        $pdf->setPrintHeader(true);
        $pdf->setPrintFooter(true);
        //$pdf->SetFont("helvetica", "", 12, "", "false");

        $pdf->AddPage();

        $html = "<h1>test</h1>";

        $pdf->writeHTML($html, true, 0, true, 0, "");

        ob_end_clean();

        $pdf->Output("test.pdf", "I");

       // echo $html;
    }
}
littlepackage commented 1 year ago

I'd be curious to know more here. There seems to be more going on than meets the eye. Where does your output buffering start? More importantly, is TCPDF setHeaderData() being used in your code elsewhere, because it seems to be tripping up on a header_string variable that's not actually a string. This would always be a string by default, which is why I ask what other code is being used...

theshafat commented 1 year ago

Here is my source code. If you hit the url http://localhost/project/index.php/pdfreport you will see the errors. It is just a simple PDF with some html

project.zip

littlepackage commented 1 year ago

Sure, take a look at your tcpdf/include/tcpdf_fonts.php file line 2001. The arguments are in the wrong order somehow. Should be:

public static function UTF8StringToArray($str, $isunicode, &$currentfont)

yours is

public static function UTF8StringToArray(&$currentfont, $isunicode, $str)

No wonder you're having problems! Maybe you should re-load your entire TCPDF library?

theshafat commented 1 year ago

Thank you @sagehenstudio. My issue has been resolved.