• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

vsmoraes/pdf-laravel5: DOMPDF module for Laravel 5

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

vsmoraes/pdf-laravel5

开源软件地址(OpenSource Url):

https://github.com/vsmoraes/pdf-laravel5

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

pdf-laravel5

DOMPDF module for Laravel 5. Export your views as PDFs - with css support.

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Instalation

Add:

"vsmoraes/laravel-pdf": "^2.0"

To your composer.json

or Run:

composer require vsmoraes/laravel-pdf

Then add:

Vsmoraes\Pdf\PdfServiceProvider::class

To the providers array on your config/app.php

And

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

To the aliases array on yout config/app.php in order to enable the PDF facade

Usage

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

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

Force download

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

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

Return PDF as string

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

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

Set paper size and orientation

    Route::get('/pdf/output', function() {
        $html = view('pdfs.example')->render();
    
        return PDF::load($html, 'A4', 'landscape')
            ->output();
    });

Output to a file

Route::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();
    }
}

Configuration

Dompdf allows you to configure a bunch of things on your PDF file. In previous versions we used to accomplish this through environment vars, now you can change this configuration keys on the fly:

Route::get('/pdf/view', function() {
    $html = view('pdfs.example')->render();
    
    $defaultOptions = PDF::getOptions();
    $defaultOptions->setDefaultFont('Courier');
    
    return PDF::setOptions($defaultOptions)->load($html)->download();
});

For the complete configuration reference: Dompdf options




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
tortuvshin/ecommerce: Laravel open source e-commerce system.发布时间:2022-08-13
下一篇:
especializati/setup-docker-laravel: Setup Docker Laravel发布时间:2022-08-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap