Get Rendered External HTML Code

Asked

Viewed 126 times

2

I am mounting a PDF and in this PDF I have to put a graphic that is being made by Highcharts. I created an HTML and JS code by mounting the graph and it is creating it right, the problem is that I need to get the HTML code of this rendered graph and when I request the link of the page that mounts the graph, it brings the unprocessed HTML, that is, without having run the JS to mount the chart.

<?php

public function SendRequest($url){

        $curl_handle=curl_init();
        curl_setopt($curl_handle, CURLOPT_URL, $url);
        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
        $query = curl_exec($curl_handle);
        curl_close($curl_handle);

        return $query;
}

public function cria_grafico($id_pedido, $id_produto){

     echo $this->load->view('sellins/GeraGraficoSellinB4', array('id_pedido'=>$id_pedido, 'id_produto'=>$id_produto), TRUE);

}

public function download($codigo_pedido = false){

$grafico = $this->SendRequest(base_url('Sellin_B4/cria_grafico/'.$produto['idPedido'].'/'.$produto['codigoProduto']));

$file = 'uploads/extract_sellin_goagro_'.time().'.pdf';

$mpdf = new mPDF();

$mpdf->SetHeader('Go Agro - Extract Sellin');

$mpdf->writeHTML($grafico);

$mpdf->SetFooter('{PAGENO}');

$mpdf->Output($file, 'F');

}

In the method graphic is where he calls HTML with JS and mounts the graph. If I access the link meusite.com.br/cria_grafico it shows the rendered graph, but when I make a request to get the same result via code, it brings the HTML without being rendered.

1 answer

1

You will not be able to accomplish what you want because Javascript runs ONLY on the client’s machine by the web browser, after the client receives the content (and if Javascript is enabled).

Even when you try to make a request from the inside with Curl, it mounts everything and even puts the correct code, so when you access it, you see it correctly because you see it from your browser. But internally the request is within the scope of the Web server, which when merging the view in the PDF does not interpret the Javascript code that truly mounts the graph.

Try using a graphics generating library that employs CSS only. They are generally less beautiful and non-interactive, but cater to situations like this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.