bytes/docraptor

DocRaptor API 客户端

dev-master 2017-03-22 20:57 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:06:21 UTC


README

这是一个用于 DocRaptor API 的简单客户端,使用 PHP5 编写。

特性

  • 通过 DocRaptor API 将 HTML 转换为 PDF 和 Excel。

要求

  • PHP >= 5.3.2 且包含 cURL 扩展

安装

使用 composer,在 composer.json 中添加以下内容

{
	"require": {
		"bytes/docraptor": "dev-master@dev"
	}
}

用法

<?php

use Bytes\Docraptor\Document\PdfDocument;
use Bytes\Docraptor\Http\Client as HttpClient;
use Bytes\Docraptor\Client;

$document = new PdfDocument('<Document name>');
$html = '<some html goes here>';
$document->setContent($html);

$httpClient = new HttpClient();
$client = new Client($httpClient, 'YOUR_API_KEY_HERE');

try {
	$pdf = $client->setTestMode(true)->convert($document);
	// write to file, stream to user, etc.
} catch (DocraptorException $e) {
        echo($e);
}