简体   繁体   English

无法在Laravel中使用dompdf转换表

[英]Can not convert table using dompdf in Laravel

I want to convert my HTML page to pdf but I can not do it. 我想将HTML页面转换为pdf,但是我做不到。 Maybe you know what I am doing wrong? 也许您知道我在做什么错? Here is my code 这是我的代码

web.php web.php

Route::get('print/{id}',array('as'=>'htmltopdfview','uses'=>'ClientController@htmltopdfview'));

controller: 控制器:

 public function htmltopdfview(Request $request)
{
    $products = Client::all();
    view()->share('products',$products);
    if($request->has('download')){
        $pdf = PDF::loadView('client/print');
        return $pdf->download('client/print');
    }
    return view('client/print' compact('client'));
}

and view: 并查看:

<a href="{{ route('htmltopdfview',['download'=>'pdf']) }}">Download PDF</a>

            <div class="panel-body">
                {!! Form::open(['action' => ['ClientController@doEdit', $client->id]]) !!}

                {!! Form::label('name', 'Imie i nazwisko:'); !!}
                {!! Form::text('name', null, ['class' => 'form-control']) !!}
{!! Form::submit('Edit!', ['class' => 'btn btn-success']) !!}
                {!! Form::close() !!}                 

So first you make a blade without that anchor tag , just keep plain html in your view ie blade .I don't get the form part but you mostly need static page for that apart from accessing the products like 所以首先您要制作一个没有锚标记的刀片只在您的视图中保留纯html即刀片 。我没有获得表单的一部分,但是除了访问诸如

{{$products->id}}  

Also for accessing the data in In controller , instead of returning view, return the below code right after the view()->share. 同样为了在In controller中访问数据,而不是返回视图,请在view()-> share之后立即返回以下代码。 I have mentioned below why you won't need that if condition 我在下面提到了为什么如果有条件就不需要那个

return $pdf->stream(); 

The download option will be automatically available in browsers like chrome. 下载选项将在chrome等浏览器中自动提供。 Also If you aren't using any data from request,why don't you try removing it. 另外,如果您没有使用请求中的任何数据,为什么不尝试删除它。 Also you never defined $client in that view . 同样,您也从未在该视图中定义$ client

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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