简体   繁体   English

php Laravel打印纸

[英]Php Laravel Print paper

My website is related to flight tickets, after booking the ticket and ticket gets issued if i want to print the ticket, it is showing the paths of the buttons in agent panel like this -> welcome agent, Profile ( http://localhost/tb/customer/dashboard ) MarkUp ( http://localhost/tb/agent/markup/list ) Dashboard (localhost/tb) reports (localhost/tb/list) 我的网站与机票有关,预订机票后,如果要打印机票,机票就会发出,它在座席面板中显示按钮的路径,如下所示-> Welcome agent,Profile( http:// localhost / tb / customer / dashboard )标记( http:// localhost / tb / agent / markup / list )仪表板(localhost / tb)报告(localhost / tb / list)

View Ticket Details after all these, ticket details are printing. 所有这些之后,请查看票证详细信息,并打印票证详细信息。

I like DocRaptor for this kind of thing. 我喜欢DocRaptor这样的东西。 Send an API request with some HTML/CSS/Javascript and you get back a PDF with which you can do anything you want, including presenting to the user for download/printing. 发送带有一些HTML / CSS / Javascript的API请求,您将获得一个PDF,您可以使用该PDF做任何您想做的事情,包括呈现给用户进行下载/打印。

They even provide a PHP class to handle API access. 他们甚至提供了一个PHP类来处理API访问。

It's a pay service, but it is worth every penny. 这是一项付费服务​​,但值得每一分钱。

Generating a PDF locally has never worked well for me. 在本地生成PDF从来没有对我很好。 Between the formatting problems that arise with different libraries, lack of Javascript support, and the resources consumed by the process, it was just too inconvenient. 在不同库引起的格式化问题,缺乏Javascript支持以及该过程消耗的资源之间,这太不方便了。

If you want to create PDF and then print the view, try this PDF generation plugin such as pdf-laravel . 如果要创建PDF然后打印视图,请尝试使用此PDF生成插件,例如pdf-laravel This is just a DOMPDF module for Laravel 5. 这只是Laravel 5的DOMPDF模块。

To get this pdf-laravel5 plugin, run below composer command : 要获取此pdf-laravel5插件,请在composer命令下运行

composer require vsmoraes/laravel-pdf

To add provider, update config/app.php with below line to providers array : 要添加提供程序,请使用以下行将config/app.php更新到providers数组

'PDF' => 'Vsmoraes\Pdf\PdfFacade',

To generate out file: 生成文件:

$router->get('/pdf/output', function() { 
    $html = view('pdfs.example')->render();

    PDF::load($html)
        ->filename('/tmp/example1.pdf')
        ->output();

    return 'PDF saved';

});

Inject on your controller: 在您的控制器上注入:

<?php namespace App\Http\Controllers;

use Vsmoraes\Pdf\Pdf;

class HomeController extends BaseControler
{
    private $pdf;

    public function __construct(Pdf $pdf)
    {
        $this->pdf = $pdf;
    }

    public function helloWorld()
    {
        $html = view('pdfs.example1')->render();

        return $this->pdf
            ->load($html)
            ->show();
    }
}

You can also force to download PDF like: 您还可以强制下载PDF,例如:

$router->get('/pdf/download', function() {
    $html = view('pdfs.example')->render();

    return PDF::load($html)->download();
});

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

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