PHP导出成PDF文件(输出或下载)

public function exportOrPreviewPDF(Request $request)
    {
    
    
        // 或者是导出还是预览,1预览2导出
        $type = $request->type;
        $id = $request->id;
        $data = TmpFeed::where('id',$request->id)->with(['feed_list','quarter_one'])->first();

        $pdf = new \TCPDF();

        // 设置文档信息
        $pdf->SetCreator('PDF_CREATOR');
        $pdf->SetAuthor('PDF_CREATOR');
        $pdf->SetTitle('PDF_CREATOR');
        $pdf->SetSubject('PDF_CREATOR');
        $pdf->SetKeywords('TCPDF, PDF, PHP');
        // 设置页眉和页脚信息
        // $pdf->SetHeaderData('tcpdf_logo.jpg', 30, '融裕行', '融裕行纺织制造', [0, 64, 255], [0, 64, 128]);
        $pdf->setFooterData([0, 64, 0], [0, 64, 128]);
        // 设置页眉和页脚字体
        $pdf->setHeaderFont(['stsongstdlight', '', '10']);
        $pdf->setFooterFont(['helvetica', '', '8']);
        // 设置默认等宽字体
        $pdf->SetDefaultMonospacedFont('courier');
        $pdf->setCellPaddings(0, 0, 0, 0);
        // 设置间距
        $pdf->SetMargins(15, 15, 15);//页面间隔
        $pdf->SetHeaderMargin(5);//页眉top间隔
        $pdf->SetFooterMargin(10);//页脚bottom间隔
        // 设置分页
        $pdf->SetAutoPageBreak(true, 25);
        // set default font subsetting mode
        $pdf->setFontSubsetting(true);
        //设置字体 stsongstdlight支持中文
        $pdf->SetFont('stsongstdlight', '', 10);
        // set image scale factor
        $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
        ob_clean();
        //第一页 导出的页面
        $view = \View::make("tpl.tmpfeeds.detailpdf",['data'=>$data,'type'=>4,'id'=>$id,'which'=>1]); //获取数据
        $html = $view->render();
        $html = preg_replace("/\s\s+/", '', $html);
        $pdf->AddPage();
       
        $pdf->Write(0,'折线图',4,0,'L',true,0,false,false,0);
		$pdf->Image('aa.png',10,40,200,80,'PNG','','',true,150,'',false,false,1,false,false,false);
       
        $pdf->writeHTML($html,true,false,true,false,'');
       
		$pdf->lastPage();
        $pdfName = '价格确认书'.date("Ymd").time();
        //输出PDF
        if ($type == 1) {
    
    
            $pdf->Output($pdfName.'pdf', 'I');//I输出、D下载
        }else{
    
    
            $pdf->Output($pdfName.'pdf', 'D');//I输出、D下载
        }
    }

detailpdf.blade.php

<link rel="stylesheet" href="{
    
    { \Illuminate\Support\Facades\URL::asset('common/common.css') }}">
<style>
    .form-group {
    
    
        margin-bottom: 0px !important;
    }
    .form-control{
    
    font-size: 15px;padding: 5px}
    .select2-container--default .select2-selection--single, .select2-selection .select2-selection--single{
    
    padding: 6px}
</style>

<div class="col-md-12" style="padding:0px">
    <div class="panel-heading" style="text-align: center"><h1>大货面、辅料采购价格确认书</h1></div>
        <div class="panel-body" style=" padding: 10px 15px 5px;"><div class="form-group" style="font-size: 10px">{
    
    {
    
    -- 编号 --}}<span style="color: #0066ff;font-weight: 700;margin-right: 20px;"><b>编号:</b>&nbsp;{
    
    {
    
    $data->number}}</span>
            {
    
    {
    
    -- 客户名称 --}}
            <span style="margin-right: 20px;"><b>客户名称:</b>&nbsp;{
    
    {
    
    $data->client_name}}</span>
            {
    
    {
    
    -- 款号 --}}
            <span style="margin-right: 20px;"><b>款号:</b>&nbsp;{
    
    {
    
    $data->bulk_no}}</span>
            {
    
    {
    
    -- 生产工厂 --}}
            <span style="margin-right: 20px;"><b>类型:</b>&nbsp;{
    
    {
    
     tmp_feeds_flag()[$data->flag]}}</span>
            {
    
    {
    
    -- 业务员 --}}
            <span style="margin-right: 20px;"><b>业务员:</b>&nbsp;{
    
    {
    
    $data->sales_name}}</span>
            {
    
    {
    
    -- 生产工厂 --}}
            <span style="margin-right: 20px;"><b>生产工厂:</b>&nbsp;{
    
    {
    
    $data->factory_abbr}}</span>
             {
    
    {
    
    -- 有效期 --}}
            <span style="margin-right: 20px;" @if($data->indate < date("Y-m-d"))style="color: red"@endif ><b>有效期:</b>&nbsp;{
    
    {
    
    $data->indate}}</span>
            {
    
    {
    
    -- 订单季度 --}}
            @if(isset($data->quarter_one))
                <span style="margin-right: 20px;"><b>季度:</b>&nbsp;{
    
    {
    
    $data->quarter_one->season}}</span>
            @endif
            <br>
            {
    
    {
    
    -- 款名 --}}
            @if(isset($data->quarter_one))
                <span style="margin-right: 20px;"><b>款名:</b>&nbsp;{
    
    {
    
    $data->style_name}}</span>
            @endif
            {
    
    {
    
    -- 品名 --}}
            @if(isset($data->place_name))
                <span style="margin-right: 20px;"><b>品名:</b>&nbsp;{
    
    {
    
    $data->place_name}}</span>
            @endif
        </div>
    </div>
    <table class="table table-has-many has-many-extra table-striped"  style="overflow:auto;width:100%;margin-bottom: 0">
        <thead>
        <tr style="background: #035aa5;color: black;">
            <th style="min-width: 92px;border: 1px solid black;text-align: center;height: 40px;line-height: 20px;">面辅料名称</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">规格</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">成分</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">克重</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">门幅</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">颜色</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">单位</th>
            <th style="min-width: 77px;border: 1px solid black;text-align: center;height: 40px;line-height: 20px;">大货数量</th>
            <th style="min-width: 77px;border: 1px solid black;text-align: center;height: 40px;line-height: 20px;">付款说明</th>
            <th style="min-width: 92px;border: 1px solid black;text-align: center;height: 40px;line-height: 20px;">基准价编码</th>
            <th style="min-width: 92px;border: 1px solid black;text-align: center;height: 40px;line-height: 20px;">公司基准价</th>
            <th style="min-width: 62px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">供应商</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">单价</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">含税</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">运费</th>
            <th style="min-width: 47px;border: 1px solid black;text-align: center;height: 40px;line-height: 40px;" title="备注">备注</th>
        </tr>
        </thead>
        <tbody class="has-many-extra-forms">
        @foreach($data->feed_list as $k => $v)
            <tr class="has-many-extra-form">
                <td style="border: 1px solid black;text-align: center;height: 50px;line-height: 25px;">{
    
    {
    
     $v->feed_name }}</td>
                <td style="border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">{
    
    {
    
     $v->feed_size }}</td>
                <td style="border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">{
    
    {
    
     $v->feed_element }}</td>
                <td style="border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">{
    
    {
    
     $v->gsm }}</td>
                <td style="border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">{
    
    {
    
     $v->cm }}</td>
                <td style="border: 1px solid black;text-align: center;line-height: 20px;">{
    
    {
    
     $v->color_no }}</td>
                <td style="border: 1px solid black;text-align: center;height: 60px;line-height: 60px;">{
    
    {
    
     $v->feed_units }}</td>
                <td style="border: 1px solid black;text-align: center;height: 60px;line-height: 60px;">{
    
    {
    
     $v->amount }}</td>
                <td style="border: 1px solid black;text-align: center;height: 60px;line-height: 60px;">{
    
    {
    
     $v->pay_remark }}</td>
                <td style="border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">{
    
    {
    
     $v->datum_menber }}</td>
                <td style="border: 1px solid black;text-align: center;height: 40px;line-height: 40px;">{
    
    {
    
     $v->datum_price }}</td>
                <td style="border: 1px solid black;text-align: center;">{
    
    {
    
     $v->supplier }}</td>
                <td style="border: 1px solid black;text-align: center;height: 60px;line-height: 60px;">{
    
    {
    
     $v->price }}</td>
                <td style="border: 1px solid black;text-align: center;height: 60px;line-height: 30px;">{
    
    {
    
     tmp_revenue_type()[$v->revenue] }}</td>
                <td style="border: 1px solid black;text-align: center;height: 60px;line-height: 60px;">{
    
    {
    
     tmp_carriage_type()[$v->carriage] }}</td>
                <td style="border: 1px solid black;text-align: center;height: 40px;">{
    
    {
    
     $v->remark }}</td>
            </tr>
        @endforeach
        </tbody>
    </table>
    <div class="panel-heading" style="border: 1px solid black;">
        <span>说明:</span>
        <br />

        <span>1)说明。</span>
        <br />

        <span>2)说明</span>
        <br />

        <span>3)备注说明。</span>
        
        <br />
        <span>4)大核对。</span>
    </div>
        

    <div class="form-group" style="font-size: 10px;display:inline-block;">
        <div style="text-align:right;">
            <span><b>供管部主管:</b>&nbsp;{
    
    {
    
     $data->supplyboss }} &nbsp;&nbsp;&nbsp;{
    
    {
    
     isset($data->supply_boss_check)?date("Y-m-d H:i",strtotime($data->supply_boss_check )):''}}</span><br />
            <span><b>供管部经理:</b>&nbsp;{
    
    {
    
     $data->supplylead }} &nbsp;&nbsp;&nbsp;{
    
    {
    
     isset($data->supply_check)?date("Y-m-d H:i",strtotime($data->supply_check )):''}}</span><br />
            <span><b>业务部主管:</b>&nbsp;{
    
    {
    
     $data->salelead }} &nbsp;&nbsp;&nbsp;{
    
    {
    
     isset($data->sale_check)?date("Y-m-d H:i",strtotime($data->sale_check )):''}}</span><br />
            <span><b>采购经办:</b>&nbsp;{
    
    {
    
     $data->buyer_name }} &nbsp;&nbsp;&nbsp;{
    
    {
    
     isset($data->created_at)?date("Y-m-d H:i",strtotime($data->created_at )):''}}</span><br />
        </div>
        
        <div style="clear: both"></div>
    </div>
    <!-- /.box-body -->
    <div class="box-footer">
        <div class="col-md-2">

        </div>
    </div>
</div>

tcpdf.php
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/xcbzsy/article/details/108234218