首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何获取原始HTML字符串形式的刀片模板视图?

如何获取原始HTML字符串形式的刀片模板视图?
EN

Stack Overflow用户
提问于 2018-06-20 07:38:28
回答 3查看 64.2K关注 0票数 67

我需要我的刀片模板的HTML作为字符串。

我将使用该HTML字符串从它生成PDF。

目前,我已经将Blade streaming作为对浏览器的回应。

 return view('users.edit', compact('user'));

如何从刀片模板中获取原始字符串?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-06-20 07:44:42

您可以在view上调用render()

$html = view('users.edit', compact('user'))->render();

有关更多信息,请参阅View源代码。

票数 163
EN

Stack Overflow用户

发布于 2021-11-20 08:05:18

这是下载/转换刀片文件为HTML的完美解决方案。

$view = view('welcome')->render();
header("Content-type: text/html");
header("Content-Disposition: attachment; filename=view.html");
return $view;
票数 1
EN

Stack Overflow用户

发布于 2019-04-30 16:03:18

    <!-- View stored in resources/views/greeting.blade.php -->
    <html>
        <body>
            <h1>Hello, {{ $name }}</h1>
        </body>
    </html>

<!-- In your php controller  -->
    
    return view('greeting', ['name' => 'James']);

编辑过的

<!-- In your PHP controller You can add html variable , and then use it for example to print PDF -->

$html=view('greeting', ['name' => 'James']);

 $pdf = \App::make('snappy.pdf.wrapper');
 $output = $pdf->loadHTML($html)->output();


$headers = [
            'Content-Type' => 'application/pdf',
            'Content-Disposition' => 'inline; filename="' . $filename . '"',
        ];
        
\Storage::put("pdfs/$filename", $output);
return response()->download(storage_path("app\\pdfs\\$filename"), $filename . '.pdf', $headers);

<!-- or return \Response::make($output, 200, $headers); -->

要使用snappy,您需要遵循以下说明:https://github.com/barryvdh/laravel-snappy

1. Download wkhtmltopdf from here https://wkhtmltopdf.org/downloads.html

2. Package Installation: composer require barryvdh/laravel-snappy

3. In (app.php) providers array add Barryvdh\Snappy\ServiceProvider::class,

4. In (app.php) aliases array add 'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class, 'SnappyImage' => Barryvdh\Snappy\Facades\SnappyImage::class,

5. Run php artisan vendor:publish --provider="Barryvdh\Snappy\ServiceProvider"

6. In (snappy.php) edit the binary path based on your installation path for wkhtmltopdf For me it is the following :返回数组(

'pdf' => array(
    'enabled' => true,
    // base_path('vendor\wemersonjanuario\wkhtmltopdf-windows\bin\64bit\wkhtmltopdf'),
    'binary'  =>'"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"',
    'timeout' => false,
    'options' => array(),
    'env'     => array(),
),
'image' => array(
    'enabled' => true,
    'binary'  =>'"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"',
    'timeout' => false,
    'options' => array(),
    'env'     => array(),

    
),

);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50938285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档