danielboendergaard/phantom-pdf

A Package for generating PDF files using PhantomJS
494,780 72
Install
composer require danielboendergaard/phantom-pdf
Latest Version:v3.1.0
PHP:>=8.1
License:MIT
Last Updated:Mar 20, 2024
Links: GitHub  ·  Packagist
Maintainer: danielboendergaard

Phantom PDF

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');
  }
}

Related Packages

clippings/phantom-pdf

A Package for generating PDF files using PhantomJS

87,565 4
antking/phantom-pdf

A Package for generating PDF files using PhantomJS, which fork from danielboende...

1,997 0
eve/pdf-converter

Laravel package to convert HTML to PDF, supporting multiple drivers.

4,065 11
spatie/laravel-html

A fluent html builder

9,073,540 827
mc0de/laravel-html

A fluent html builder

2 0

Version History

Version Released PHP License
v3.1.0 >=8.1 MIT
v3.0.0 >=8.1 MIT
v2.0.1 ^7.2.5|^8.0 MIT
v2.0.0 ^7.2.5 MIT
v1.4.0 >=5.4.0 MIT