Coder Social home page Coder Social logo

phantom-pdf's Introduction

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

phantom-pdf's People

Contributors

danielboendergaard avatar mactwister avatar matthijs110 avatar przemekperon avatar rumeau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.