简体   繁体   中英

generate pdf and embed in page with mpdf

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.

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM