cannot open pdf file generated using dompdf

前端 未结 5 1622
栀梦
栀梦 2021-01-15 06:22

i am trying to generate a pdf file from smarty template using dompdf:code is below:-

require_once(\'dompdf/dompdf_config.inc.php\');
$dompdf = new DOMPDF();
         


        
5条回答
  •  渐次进展
    2021-01-15 06:30

    yes this is an problem of dompdf. But I am able to overcome from this problem. I created a function for pdf creation. check below function:-

    function pdf_create($html, $filename='', $stream=TRUE) 
    {
        require_once("dompdf/dompdf_config.inc.php");
        $savein = 'uploads/policy_doc/';
        $dompdf = new DOMPDF();
        $dompdf->load_html($html);
        $dompdf->render();
        $canvas = $dompdf->get_canvas();
        $font = Font_Metrics::get_font("arial", "normal","12px");
    
        // the same call as in my previous example
        $canvas->page_text(540, 773, "Page {PAGE_NUM} of {PAGE_COUNT}",
                       $font, 6, array(0,0,0));
    
        $pdf = $dompdf->output();      // gets the PDF as a string
    
        file_put_contents($savein.str_replace("/","-",$filename), $pdf);    // save the pdf file on server
        unset($html);
        unset($dompdf); 
    
    }
    

    Note :- You need to get generated pdf as string then save it to pdf file.

    EDIT :- You may delete the below part from above function:-

        $canvas = $dompdf->get_canvas();
        $font = Font_Metrics::get_font("arial", "normal","12px");
    
        // the same call as in my previous example
        $canvas->page_text(540, 773, "Page {PAGE_NUM} of {PAGE_COUNT}",
                       $font, 6, array(0,0,0));
    

    this above code for handling multiple pages header.

提交回复
热议问题