pdfkiwi/php-lib

用于与 pdf.kiwi API 交互的 PHP 库

0.4.0 2017-06-16 13:28 UTC

This package is not auto-updated.

Last update: 2024-09-29 02:21:20 UTC


README

用于与 pdf.kiwi API 交互的 PHP 库

Build Status Coverage Status

安装

$ composer require "pdfkiwi/php-lib"

然后,在使用之前,不要忘记在自己的类中使用 PdfKiwi 命名空间

<?php
use PdfKiwi\PdfKiwi;

快速入门指南

实例化 PdfKiwi 类时,我们必须提供 电子邮件地址API 密钥(令牌),以便能够使用我们账户的凭据连接到 API。

这里有一个示例

<?php
use PdfKiwi\PdfKiwi;

$pdfKiwi = new PdfKiwi($email, $token);

然后我们可以设置一些选项,如下所示

<?php
$pdfKiwi->setPageMargins('10mm', '20mm', '10mm', '20mm');
$pdfKiwi->setOrientation('landscape');

最后,一旦我们定义了所有选项,我们可以调用方法 convertHtml(),它返回转换后的 PDF

<?php
$pdf = $pdfKiwi->convertHtml($html);

公共方法列表

setPageWidth()

设置页面宽度。

参数

$value (string) The document's page width, with unit (eg. '210mm')

setPageHeight()

设置页面高度。

参数

$value (string) The document's page height, with unit (eg. '297mm')

setHeaderHtml()

使用 HTML 格式设置页面页眉。

参数

$value (string) The HTML content of the header

setHeaderSpacing()

设置页眉与文档主体的间距。

参数

$value (float) The space (in mm) between the header and the body, without unit

setHeaderText()

使用 TEXT 格式设置页面页眉。

参数

$value (mixed) Can be either :
  - (string) The (text) content of the header (will be left aligned)
  - (array) An array with 3 values of text, respectively : [left, center, right]

setFooterHtml()

使用 HTML 格式设置页面页脚。

参数

$value (string) The HTML content of the footer

setFooterSpacing()

设置页脚与文档主体的间距。

参数

$value (float) The space (in mm) between the footer and the body, without unit

setFooterText()

使用 TEXT 格式设置页面页脚。

参数

$value (mixed) Can be either :
  - (string) The (text) content of the footer (will be left aligned)
  - (array) An array with 3 values of text, respectively : [left, center, right]

setHeaderFooterPageExcludeList()

设置一个页码列表,在这些页码上不会打印页眉和页脚。

参数

$value (mixed) Can be either :
  - (string) A comma separated list of page numbers (without space, eg. '1,3,5')
  - (array) An array with a list of page numbers (eg. [1, 3, 5])

setPageMargins()

设置文档页面的页边距。

参数

$top (string) Top margin value, with unit (eg. '20mm')
$right (string) Right margin value, with unit (eg. '20mm')
$bottom (string) Bottom margin value, with unit (eg. '20mm')
$left (string) Left margin value, with unit (eg. '20mm')

setOrientation()

设置页面的方向。

参数

$orientation (string) The page's orientation. Can be either 'landscape', or 'portrait'.