Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
theshafat opened this issue Aug 5, 2023 · 6 comments

Comments

@theshafat
Copy link

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
Copy link
Contributor

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

@theshafat
Copy link
Author

theshafat commented Aug 5, 2023

<?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;
    }
}

@sagehenstudio
Copy link
Contributor

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
Copy link
Author

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

@sagehenstudio
Copy link
Contributor

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
Copy link
Author

Thank you @sagehenstudio. My issue has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants