optimus/pdf-bot 问题修复 & 功能扩展

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

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

optimus/pdf-bot

最新稳定版本:0.5.5

Composer 安装命令:

composer require optimus/pdf-bot

包简介

README 文档

README

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.

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-13