GithubHelp home page GithubHelp logo

geekwolverine / laravel-browsershot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from verumconsilium/laravel-browsershot

0.0 1.0 0.0 138 KB

Browsershot wrapper for Laravel 5

License: MIT License

PHP 98.83% Blade 1.17%

laravel-browsershot's Introduction

Browsershot wrapper for Laravel 5

This package takes advantage of Google Chrome's Headless mode to take screenshots and generate PDFs from websites, views and raw html

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License

Requirements

You can install Puppeteer in your project via NPM:

npm install puppeteer

Or you could opt to just install it globally

npm install puppeteer --global

On a Forge provisioned Ubuntu 16.04 server you can install the latest stable version of Chrome like this:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
sudo npm install --global --unsafe-perm puppeteer
sudo chmod -R o+rx /usr/lib/node_modules/puppeteer/.local-chromium

Installation

Install the package through composer

composer require verumconsilium/laravel-browsershot

After the package is installed the service provider will be automatically discovered and two new Facades PDF and Screenshot will be available

Usage

The recommended way to use this package is through its Facades

PDF

Generating a PDF from a view and returning it inline

  
  use VerumConsilium\Browsershot\Facades\PDF;
  
  ...
  
  return PDF::loadView('view.name', $data)
            ->inline();
  

You can chain all the methods available in the browsershot master library

Returning the PDF as a download

  use VerumConsilium\Browsershot\Facades\PDF;
  
  ...
  
  return PDF::loadView('view.name', $data)
            ->margins(20, 0, 0, 20)
            ->download();

You can pass the custom file name and additional headers the response will have to the inline and download methods like

  PDF::loadHtml('<h1>Awesome PDF</h1>') 
      ->download('myawesomepdf.pdf', [
        'Authorization' => 'token'
      ]);

Persisting PDF to disk

If you would like to save the generated pdf file to your storage disk you can call the store or storeAs method

  $pdfStoredPath = PDF::loadUrl('https://google.com')
                      ->store('pdfs/')

This will use the default storage driver to store the pdf in the pdfs/ folder giving it a unique name. If you would like to specify the name you can call de storeAs method

  $pdfStoredPath = PDF::loadUrl('https://google.com')
                      ->storeAs('pdfs/', 'google.pdf')

Screenshots

Screenshots are created the same way as PDFs just change the facade to Screenshot

Generating screenshots as JPG/JPEG

By default screenshots will be taken as PNG format if you would like to use JPG instead call the useJPG() method

use VerumConsilium\Browsershot\Facades\Screenshot;

Screenshot::loadView('view.name', $data)
           ->useJPG()
           ->margins(20, 0, 0, 20)
           ->download();

laravel-browsershot's People

Contributors

nickels avatar okaufmann avatar sgtpepper9907 avatar

Watchers

 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.