代码之家  ›  专栏  ›  技术社区  ›  Nileshsinh Rathod

从XML响应生成pdf花费了太多时间

  •  0
  • Nileshsinh Rathod  · 技术社区  · 6 年前

    我的数据库中有xml,希望从xml生成pdf,但如果xml太大,则会出现超时错误。我不想改变我的服务器超时,而不是如何改进生成pdf的时间。 <pre> 标记以获得良好的格式。

    下面的pdf生成代码

    public function generateCreditReport($form, $path=false, $htmlPath=false){       
        $this->load->library('fpdf/fpdf');
        $this->load->library('fpdi/fpdi');
        if(!empty($path) && !file_exists($path)){
            $data['form'] =  $form;       
            $data['date'] = $data['xml'] = null;
            if($data['form']->credit_report != ''){ 
                try{
                    $data['xml'] = new SimpleXMLElement($data['form']->credit_report);   
                }catch(Exception $e){
    
                }
                $timeStatus = $this->admin->get_timestamp($data['form']->id, 'credit_pulled');
                if(!empty($timeStatus)) {
                    $data['date'] = $timeStatus->date;
                }
            }
            $pdf = new TCPDF();     
            $pdf->SetFont('Helvetica');
            $pdf->SetFontSize(10);
            $pdf->SetTextColor(0, 0, 0);
            $pdf->SetProtection(array('print','modify'),"$form->loan_id","sefinance",0);
            $pdf->AddPage();
            $html = $this->load->view('admin/credit_report_pdf', $data,true);
            $generatedReport = file_put_contents($htmlPath, $html , FILE_APPEND | LOCK_EX);
            $pdf->WriteHTML($html);
    
            if($path){
                $pdf->Output($path, "F");             
            }else{
                $pdf->Output(); 
            }
        }
    }
    

    credit_report_pdf 如下所示

    <h4>Report Results</h4>
    <br>
    <?php if(!empty($xml)){ ?>
    <?php echo print_credit($xml->EfxReport->USPrintImage); ?>
    <?php } ?>
    

    我正在使用格式化 < 为了好看。

    function print_credit($report) {
        $split = " <div style='page-break-before: always;'></div>" . repeater(' ', 43);
        $report = preg_replace('/\* \* \*[\s\S]+?USER REF./', $split, $report);
        $output = "";
        $output = '<pre>';
        $length = strlen($report);
        $count = $length / 81;
        $position = 1;
        for ($i = 0; $i < $count; $i++) {
            if (strpos(substr($report, $position, 80), 'THIS FORM PRODUCED BY EQUIFAX') === FALSE) {
                $output .= substr($report, $position, 80) . '<br>';
            }
    
            if ($i == 32) {
                $output .= '</pre><pre>';
            }
            $position += 81;
        }
        $output .= '</pre>';
        return $output;
    }
    

    这是pdf的截图。

    enter image description here

    请帮助我改进pdf的计时,目前10页pdf需要10分钟以上的时间。

    0 回复  |  直到 6 年前