定制 isset/alfredo 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

isset/alfredo

Composer 安装命令:

composer require isset/alfredo

包简介

Alfredo for PHP 5.3

README 文档

README

To take advantage of Online PDF Converter's API you'll need to install the client in your project and have access to our system. There are two keys need to access the API, a:

  • Consumer key
  • Private key

Without these you won't be able to connect to our servers. Next is the client. This installation process will be explained in the next chapter.

Installation

At the moment the client library is not publicly available. Please contact us to obtain access to this library. The client library needs to be installed through Composer. Click here if you've never used Composer. (http://getcomposer.org/doc/00-intro.md)

Add the following to your composer.json file in the "require" section:

    "isset/alfredo": "1.*"

After you've added the requirement go to your terminal of choice and run the command: If you've installed Composer on your machine:

    composer update

Otherwise:

    php composer.phar update

Online PDF Converter's API will now be installed and added to Composer's autoloader.

Create Payload

The conversion of a PDF is done through a payload, which is send to the server. With our API it's possible to create a pdf from several different sources. Currently the available sources: HTML, Pdf and Url. These examples will show you how this it's done:

Attach A Source

Attach HTML

    $payload = new Alfredo\Payload\Pdf\Convert;
    $payload->addhtml('<html><thead></thead><tbody>test</tbody></html>');

Attach Pdf

    $payload = new Alfredo\Payload\Pdf\Convert;
    $pdf = file_get_contents('path/to/pdf/file.pdf');
    $payload->addPdf($pdf);

Attach Url

    $payload = new Alfredo\Payload\Pdf\Convert;
    $payload->addUrl('http://online-pdfconverter.nl');
  • Note: Currently our Url conversion is unstable. This is due to the fact that some web pages are not formatted correctly.

Set Callback Url

A callback url is only needed when working with queues. This url will be called with response of the conversion. It'll contain two items, named:

  • Identifier
  • Response

With the identifier it's possible to download the when it's converted. Here's an example of how to set the callback:

    $payload = new Alfredo\Payload\Pdf\Convert;
    $payload->setCallback('http://example.com/callback_url');

Method chaining

All the above methods could be chained together:

    $payload = new Alfredo\Payload\Pdf\Convert;
    $payload->addhtml('<html><thead></thead><tbody>test</tbody></html>')
            ->addPdf(file_get_contents('path/to/pdf/file.pdf'))
            ->addUrl('http://online-pdfconverter.nl');
            ->setCallback('http://example.com/callback-response');

Change Converter Type

Our API is able to switch converter type which each payload. Available types:

  • wkhtmltopdf
  • htmltopdfjava (Default)

This is how you can change the type:

    $payload = new Alfredo\Payload\Pdf\Convert;
    $payload->setConverter('wkhtmltoppdf');

Stream Payload

There are multiple ways to execute conversion. Streaming is one of them. When streaming you'll immediately get a response, but can't be stored by the server, only by the user. For this conversion you'll be needing the consumer and private key. Here is how you can stream a Pdf:

    $payload = new Alfredo\Payload\Pdf\Convert;
    $payload->addhtml('<html><thead></thead><tbody>test</tbody></html>');
    $server = new Alfredo\Server('http://converter.isset.nl', 'consumer_key', 'private_key');

    try {
        $response = $server->stream($payload);
        header('Content-type: application/pdf');
        echo $response
    } catch (Alfredo\ConversionUnableException $e) {
        echo $e->getMessage();
    }

Queue Payload

To queue a pdf conversion you'll need to set a callback url on the payload, this is explained a couple of chapters back. After adding one or multiple sources and a callback url we'll pass the payload to our API.

    $payload = new Alfredo\Payload\Pdf\Convert;
    $payload->addhtml('<html><thead></thead><tbody>test</tbody></html>');
    $payload->setCallback('http://example.com/callback_url');

    $server = new Alfredo\Server('http://converter.isset.nl', 'consumer_key', 'private_key');

    $response = $server->queue($payload);

The server will return a JSON string which contains an identifier and the response status. It could be helpful to save the identifier somewhere in a database. When the pdf has converted our server will send a POST request to the callback url with the same JSON string. If the response status states the converion is completed you'll be able to request the pdf like this:

    $server = new Alfredo\Server('http://converter.isset.nl', 'consumer_key', 'private_key');

    $payload = new Alfredo\Payload\Pdf\QueueItem;
    $payload->setIdentifier('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

    $pdf = $server->getQueueItem($payload);

The response from the method getQueueItem() will be the converted pdf. You could stream it like explained in the chapter above this one.

isset/alfredo 适用场景与选型建议

isset/alfredo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66 次下载、GitHub Stars 达 1, 最近一次更新时间为 2013 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 isset/alfredo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 isset/alfredo 我们能提供哪些服务?
定制开发 / 二次开发

基于 isset/alfredo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-10-24