generation table of contents for dompdf

i want to create pdf from my html content containing table of content in codeigniter 3 controller method by dompdf;

consider so simple one as described in TOC example ;

i will use that as inline PHP string concatenation in my controller method which is as follow:

    public function generateTableOfContents() {
        $options = new DompdfOptions();
        $options->set('isHtml5ParserEnabled', true);
        $options->set('isRemoteEnabled', true);
        $pdf = new DompdfDompdf($options);

        $htmlContent='
        <html>
        <body>

        <script type="text/php">';
            $font = $pdf->getFontMetrics()->getFont('times', 'normal');

            //$font = Font_Metrics::get_font("helvetica", "bold");
            $GLOBALS['chapters'] = array();
            $GLOBALS['backside'] = $pdf->open_object();
        '</script>

        <h2>Table of Contents</h2>
        <ol>
            <li>Chapter 1 ....................... page %%CH1%%</li>
            <li>Chapter 2 ....................... page %%CH2%%</li>
            <li>Chapter 3 ....................... page %%CH3%%</li>
        </ol>

        <script type="text/php">';
            $pdf->close_object();
        '</script>

        <h2 style="page-break-before: always;">Chapter 1</h2>
        <script type="text/php">';
            $GLOBALS['chapters']['1'] = $pdf->get_page_number();
        '</script>

        <div id="lipsum">
        <p>p1</p>
        <p>p2</p>
        <p>p3</p>

        <h2>Chapter 2</h2>
        <script type="text/php">';
            $GLOBALS['chapters']['2'] = $pdf->get_page_number();
        '</script>

        <p>p4</p>
        <p>p5</p>
        <p>p6</p>
        </div>

        <h2 style="page-break-before: always;">Chapter 3</h2>
        <script type="text/php">';
            $GLOBALS['chapters']['3'] = $pdf->get_page_number();
        '</script>

        <div id="lipsum">
        <p>p7</p>
        <p>p8</p>
        <p>p9</p>
        </div>

        <script type="text/php">';
            foreach ($GLOBALS['chapters'] as $chapter => $page) {
                $pdf->get_cpdf()->objects[$GLOBALS['backside']]['c'] = str_replace( '%%CH'.$chapter.'%%' , $page , $pdf->get_cpdf()->objects[$GLOBALS['backside']]['c'] );
            }
            $pdf->page_script('
                if ($PAGE_NUM==1 ) {
                    $pdf->add_object($GLOBALS["backside"],"add");
                    $pdf->stop_object($GLOBALS["backside"]);
                } 
            ');
        '</script>

        </body>
        </html>';

    $pdf->loadHtml($htmlContent);
    $pdf->setPaper('A4', 'landscape');
    $pdf->render();
    $pdf->stream('document.pdf', ['Attachment' => false]);
   }

but,it can not get access cpdf: Message: Call to undefined method DompdfDompdf::open_object()

how should i mention cpdf to be abled to call inside method.

how should resolve?

thanks in advance.