radweb/pdfcrowd-php

此包已被废弃且不再维护。作者建议使用 pdfcrowd/pdfcrowd 包。

dev-master 2020-02-28 13:51 UTC

This package is auto-updated.

Last update: 2020-02-28 13:53:14 UTC


README

此包不再维护,请使用此 https://github.com/pdfcrowd/pdfcrowd-php

Pdfcrowd API 允许您在 PHP 应用程序中轻松地将网页或原始 HTML 代码转换为 PDF。

要使用 API,您需要在 http://pdfcrowd.com 上有一个账户,如果没有,您可以在 此处 注册。这将为您提供用户名和 API 密钥。

安装

pdfcrowd.php 复制到您的源目录。

示例

服务器端 PDF 生成。此代码将网页转换为 PDF 并发送到浏览器(别忘了使用您的 "username""apikey"

require 'pdfcrowd.php';

try
{   
    // create an API client instance
    $client = new Pdfcrowd("username", "apikey");

    // convert a web page and store the generated PDF into a $pdf variable
    $pdf = $client->convertURI('http://example.com/');

    // set HTTP response headers
    header("Content-Type: application/pdf");
    header("Cache-Control: no-cache");
    header("Accept-Ranges: none");
    header("Content-Disposition: attachment; filename=\"created.pdf\"");

    // send the generated PDF 
    echo $pdf;
}
catch(PdfcrowdException $e)
{
    echo "Pdfcrowd Error: " . $e->getMessage();
}

其他基本操作

// convert an HTML string
$html = "<html><body>In-memory HTML.</body></html>";
$pdf = $client->convertHtml($html);

// convert an HTML file
$pdf = $client->convertFile('/path/to/local/file.html');