danielboendergaard/phantom-pdf 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

danielboendergaard/phantom-pdf

最新稳定版本:v3.1.0

Composer 安装命令:

composer require danielboendergaard/phantom-pdf

包简介

A Package for generating PDF files using PhantomJS

README 文档

README

A Package for generating PDF files using PhantomJS. The package is framework agnostic, but provides integration with Laravel.

Notice: This package only ships with the 64-bit Linux version of PhantomJS. If you want to use it with another version you can reference it in the configuration.

Installation

Run composer require danielboendergaard/phantom-pdf

Usage

$pdf = new PdfGenerator;

// Set a writable path for temporary files
$pdf->setStoragePath('storage/path');

// Saves the PDF as a file (optional)
$pdf->saveFromView($html, 'filename.pdf');

// Returns a Symfony\Component\HttpFoundation\BinaryFileResponse
return $pdf->createFromView($html, 'filename.pdf');

PhantomJS Version

This package uses PhantomJS 1.9.8 x64 which is included in the package. If you want to use another version it's easy.

$pdf->setBinaryPath('/some/path/phantomjs');

Customizing the conversion script

If you want to use another script to execute with PhantomJS, this it how you do it.

$pdf->useScript('`/path/to/script');

Laravel integration

Installation

For Laravel 5.5 the package supports auto discovery and don't need any configuration.

For Laravel 4, use the 0.10.0 branch.

Add LaravelServiceProvider in the providers array in config/app.php

'providers' => [
  PhantomPdf\Laravel\LaravelServiceProvider::class,
]

Facades (optional)

Add the facade to the aliases array in app/config/app.php (optional)

'aliases' => [
  'PDF' => PhantomPdf\Laravel\PDFFacade::class,
]

Usage

class SampleController extends Controller
{
  public function index()
  {
    return PDF::createFromView(view('index'), 'filename.pdf');
  }

  // Save the pdf to disk
  public function save()
  {
      PDF::saveFromView(view('index'), 'path/filename.pdf');
  }

  // Usa via injection
  public function foo(PdfGenerator $pdf)
  {
    return $pdf->createFromView(view('path'), 'filename.pdf');
  }
}

统计信息

  • 总下载量: 452.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 74
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 72
  • Watchers: 6
  • Forks: 26
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-05-14