函数参考
PHP Manual

Haru PDF Functions

简介

The PECL/haru extension provides bindings for Haru Free PDF Library - free, cross platform, opensource software library for generating PDF files.

You can find the library here: » http://libharu.sourceforge.net.

Warning

本扩展模块是实验性的。本模块的行为,包括其函数的名称以及其它任何关于此模块的文档可能会在没有通知的情况下随 PHP 以后的发布而改变。使用本扩展模块风险自担。

需求

You need to install libharu first to be able to use PECL/haru. PECL/haru is tested with libharu 2.0.8, older versions might or might not work for you. PECL/haru also requires PHP 5.1.3 or newer.

安装

安装此 PECL 扩展库的信息可在手册中标题为 PECL 扩展库安装的一章中找到。 更多信息如新版本,下载,源文件,维护者信息以及更新日志等可以在这里找到: » http://pecl.php.net/package/haru.

The latest PECL/haru Win32 DLL can be downloaded here: » php_haru.dll.

运行时配置

本扩展模块在 php.ini 中未定义任何配置选项。

范例

Example#1 Basic PECL/haru example

<?php

$doc 
= new HaruDoc;

$doc->setPageMode(HaruDoc::PAGE_MODE_USE_THUMBS); /* show thumbnails */

$page $doc->addPage(); /* add page to the document */
$page->setSize(HaruPage::SIZE_A4HaruPage::LANDSCAPE); /* set the page to use A4 landscape format */

$courier $doc->getFont("Courier-Bold"); /* we'll use the bundled font a few lines below */

$page->setRGBStroke(000); /* set colors */
$page->setRGBFill(0.70.80.9);
$page->rectangle(150150550250); /* draw a rectangle */

$page->fillStroke(); /* fill and stroke it */

$page->setDash(array(33), 0); /* set dash style for lines at this page */
$page->setFontAndSize($courier60); /* set font and size */

$page->setRGBStroke(0.50.50.1); /* set line color */
$page->setRGBFill(111); /* set filling color */

$page->setTextRenderingMode(HaruPage::FILL_THEN_STROKE); /* fill and stroke text */

/* print the text */
$page->beginText();
$page->textOut(210270"Hello World!");
$page->endText();

$doc->save("/tmp/test.pdf"); /* save the document into a file */

?>

Open the result document in your favourite PDF viewer and you should see a light-blue rectangle and white "Hello World!" on it.

Builtin Fonts And Encodings

Builtin Fonts

These Base14 fonts are built-in into PDF and all viewers can display them. Using these fonts may decrease the size of the result file and make the processing faster, avoiding loading external fonts. However the fonts support only latin1 character set and you have to load external fonts if you need to use an other character set.

The Base14 fonts:

  • Courier

  • Courier-Bold

  • Courier-Oblique

  • Courier-BoldOblique

  • Helvetica

  • Helvetica-Bold

  • Helvetica-Oblique

  • Helvetica-BoldOblique

  • Times-Roman

  • Times-Bold

  • Times-Italic

  • Times-BoldItalic

  • Symbol

  • ZapfDingbats

Builtin Encodings

Single-byte character set encodings
Name Description
StandardEncoding The default encoding of PDF.
MacRomanEncoding The standard encoding of Mac OS.
WinAnsiEncoding The standard encoding of Windows.
FontSpecific The font built-in encoding.
ISO8859-2 Latin2 (East European)
ISO8859-3 Latin3 (South European)
ISO8859-4 Latin4 (North European)
ISO8859-5 Cyrillic
ISO8859-6 Arabic
ISO8859-7 Greek
ISO8859-8 Hebrew
ISO8859-9 Latin5 (Turkish)
ISO8859-10 Latin6 (Nordic)
ISO8859-11 Thai
ISO8859-13 Latin7 (Baltic Rim)
ISO8859-14 Latin8 (Celtic)
ISO8859-15 Latin9
ISO8859-16 Latin10
CP1250 MS Windows Codepage 1250.
CP1251 MS Windows Codepage 1251.
CP1252 MS Windows Codepage 1252.
CP1253 MS Windows Codepage 1253.
CP1254 MS Windows Codepage 1254.
CP1255 MS Windows Codepage 1255.
CP1256 MS Windows Codepage 1256.
CP1257 MS Windows Codepage 1257.
CP1258 MS Windows Codepage 1258.
KOI8-R Cyrillic character set.
Multi-byte character set encodings
Name Description
GB-EUC-H EUC-CN encoding.
GB-EUC-V Vertical writing version of GB-EUC-H.
GBK-EUC-H Microsoft Code Page 936 (lfCharSet 0x86) GBK encoding.
GBK-EUC-V Vertical writing version of GBK-EUC-H.
ETen-B5-H Microsoft Code Page 950 (lfCharSet 0x88) Big Five character set with ETen extensions.
ETen-B5-V Vertical writing version of ETen-B5-H.
90ms-RKSJ-H Microsoft Code Page 932, JIS X 0208 character.
90ms-RKSJ-V Vertical writing version of 90ms-RKSJ-V.
90msp-RKSJ-H Microsoft Code Page 932, JIS X 0208 character (proportional).
EUC-H JIS X 0208 character set, EUC-JP encoding.
EUC-V Vertical writing version of EUC-H.
KSC-EUC-H KS X 1001:1992 character set, EUC-KR encoding.
KSC-EUC-V Vertical writing version of KSC-EUC-V.
KSCms-UHC-H Microsoft Code Page 949 (lfCharSet 0x81), KS X 1001:1992 character set plus 8822 additional hangul, Unified Hangul Code (UHC) encoding (proportional).
KSCms-UHC-HW-H Microsoft Code Page 949 (lfCharSet 0x81), KS X 1001:1992 character set plus 8822 additional hangul, Unified Hangul Code (UHC) encoding (fixed width).
KSCms-UHC-HW-V Vertical writing version of KSCms-UHC-HW-H.

Table of Contents


函数参考
PHP Manual