Question

I am using mPdf to generate a pdf and it is working great.

function generate_pdf()
{
    $bom =$_POST["bom_contents"];
    $html = $this->load->view("public/print",array($bom),TRUE); //returns the html
    $this->load->library("mpdf");//loading the library
    $this->mpdf->WriteHTML($html); //setting the html content to generate
    $this->mpdf->Output(); //send to browser
}

My html is as follows:

<div>
    <embed  id="doc" class="doc" src="what_i_put_here ?"></embed>
</div>

How can I set the src attribute of the embedded element, because mPdf is sending the content directly to the browser also I am using POST data, so that I cannot access it through URL.

Was it helpful?

Solution 2

I managed it to work .

When i click on Preview button ,it will show a notification that tells Please wait generating pdf... ,also i did a ajax request.

I generated a file using a ajax request and after that file creation i opened a popup,so that i can use the src attribute to the embed.

OTHER TIPS

Put your generate_pdf() function inside another file, such as pdf_generator.php. Then set that file as the source:

<div>
    <embed  id="doc" class="doc" src="pdf_generator.php<?=$_POST["bom_contents"];?>"></embed>
</div>

Updated function:

function generate_pdf()
{
    $bom =$_GET["bom_contents"];
    $html = $this->load->view("public/print",array($bom),TRUE); //returns the html
    $this->load->library("mpdf");//loading the library
    $this->mpdf->WriteHTML($html); //setting the html content to generate
    $this->mpdf->Output(); //send to browser
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top