Giter Site home page Giter Site logo

pravinshahi0007 / pdf-bot-laravel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from esbenp/pdf-bot-laravel

0.0 0.0 0.0 14 KB

๐Ÿค– Laravel integration for pdf-bot. A Node microservice for generating PDFs using headless Chrome

Home Page: https://github.com/esbenp/pdf-bot

License: MIT License

PHP 100.00%

pdf-bot-laravel's Introduction

๐Ÿค– pdf-bot-laravel

Laravel integration for pdf-bot, a Node microservice for generating PDFs using headless Chrome.

Installation

composer require optimus/pdf-bot 0.1.*

Add the service provider to config/app.php

// ... other service providers
Optimus\PdfBot\PdfBotServiceProvider::class,

Publish the config file.

php artisan vendor:publish provider="Optimus\PdfBot\PdfBotServiceProvider"

You also need to create a controller for receiving webhooks.

<?php

namespace Infrastructure\Webhooks\Controllers;

use Illuminate\Http\Request;
use Optimus\PdfBot\PdfBotController;

class PdfController extends PdfBotController
{
    protected function onPdfReceived(array $data, Request $request)
    {
        // Do stuff with PDF
    }
}

And add its route to your routes

<?php
$router->post('/webhooks/pdf', '\Infrastructure\Webhooks\Controllers\PdfController@receive');

Now you can access pdf-bot using

$pdfBot = app()->make(\Optimus\PdfBot\PdfBot::class);

or by adding the including facade to your facades.

Configuration

As a minimum you should change the server and secret parameters in config/optimus.pdfbot.php.

<?php

return [
    'secret' => 'secret-used-for-generating-signature',

    'server' => 'http://url-to-pdf-bot-server',

    'header-namespace' => 'X-PDF-'
];

Usage example

Now you are ready to generate PDF's. Start by pushing a URL to the PDF server for generation.

$pdfBot = app()->make(\Optimus\PdfBot\PdfBot::class);
$pdfBot->push('https://invoices.traede.com/1', [
    'type' => 'invoice',
    'id' => 1
]);

Now this will be added to your PDF queue. At some point your PDF controller method (onPdfReceived) will receive a request with the path to the file. In your controller you can decide what to do with it.

<?php

namespace Infrastructure\Webhooks\Controllers;

use Illuminate\Http\Request;
use Optimus\PdfBot\PdfBotController;

class PdfController extends PdfBotController
{
    protected function onPdfReceived(array $data, Request $request)
    {
        $meta = $data['meta'];
        $s3 = $data['s3'];

        switch ($meta['type']) {
            case 'invoice':
                $invoice = \Invoice::find($meta['id']);
                $invoice->pdf = $s3['path']['key'];
                $invoice->save();
                break;
        }
    }
}

Now the invoice's location is saved on the correct invoice.

Issues

Please report issues to the issue tracker

License

The MIT License (MIT). Please see License File for more information.

pdf-bot-laravel's People

Contributors

esbenp 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.