我可以在php中将这种布局生成为PDF吗?

问题描述 投票:0回答:1

我正在尝试通过使用DOMPDF在HTML中将HTML转换为pdf。我将数据从数据库传递到HTML视图,然后生成一个pdf,并将该pdf保存到数据库中的文件和pdf名称中,但是当生成pdf时,布局在生成的pdf上看起来有所不同。如何在PHP中将此类布局生成为PDF?我正在共享要转换为pdf的布局。请任何人帮助我。

    $this->load->library('pdf');
    $report_data = $this->reports->get_relational_data_by_id($id, TRUE);
    $data = array(
        'report' => $report_data,
        );

    $this->pdf->set_base_path('http://localhost/kyl/assets/css/bootstrap.min.css');
    $this->pdf->set_base_path('http://localhost/kyl/assets/css/typography.css');
    $this->pdf->set_base_path('http://localhost/kyl/assets/css/default-css.css');
    $this->pdf->set_base_path('http://localhost/kyl/assets/css/styles.css');
    $this->pdf->set_base_path('http://localhost/kyl/assets/css/responsive.css');
    $output = $this->load->view('Report/reportlayout/layout_1', $data, TRUE);
    $this->pdf->loadHtml($output);
    $this->pdf->render();
    $this->pdf->set_option('fontHeightRatio', 0.6);
    //$this->pdf->stream("welcome.pdf");
    $file = $this->pdf->output();
    $file_name = 'reports/pdfs/report_'.round(microtime(true) * 1000).'.pdf';
    file_put_contents($file_name, $file);

    $data1 = array(
            'report_url' => $file_name,
        );

    $data2 = array(
            'user_report_status' => 3,
        );

    $this->reports->update($this->table_reports, array('report_id' => $id), $data1);
    $this->reports->update($this->table_report_details, array('report_details_id' => $report_data->report_details_id), $data2);

    $user = $this->reports->get_relational_data_by_id($id, TRUE);

    $email_status =  $this->user_email->report_email($user);

    if($email_status == TRUE)
    {
        $this->flash->success('Email has been sent successfully');
    }
    else
    {
        $this->flash->errors('Error during sending email');
    }

    redirect(base_url('Report/view_generated_report/').$id);

referance image 1

referance image 2

referance image 3

php pdf pdf-generation fpdf dompdf
1个回答
0
投票

html的布局可以更改,并且不会影响它产生的输出,因为html不是大小写-敏感的语言,它也不需要像python一样的缩进规则。但是,如果您谈论的是pdf产生的输出与html产生的布局不同,那么照顾起来就不会多了。

© www.soinside.com 2019 - 2024. All rights reserved.