您需要先安装libharu才能使用PECL/haru。PECL/haru是用libharu 2.0.8测试的,旧版本可能对您有用,也可能不适用。PECL/haru还需要PHP 5.1.3或更新版本。
haru基础用法例子
Example #1 Fancy "Hello world"
<?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_A4, HaruPage::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(0, 0, 0); /* set colors */ $page->setRGBFill(0.7, 0.8, 0.9); $page->rectangle(150, 150, 550, 250); /* draw a rectangle */ $page->fillStroke(); /* fill and stroke it */ $page->setDash(array(3, 3), 0); /* set dash style for lines at this page */ $page->setFontAndSize($courier, 60); /* set font and size */ $page->setRGBStroke(0.5, 0.5, 0.1); /* set line color */ $page->setRGBFill(1, 1, 1); /* set filling color */ $page->setTextRenderingMode(HaruPage::FILL_THEN_STROKE); /* fill and stroke text */ /* print the text */ $page->beginText(); $page->textOut(210, 270, "Hello World!"); $page->endText(); $doc->save("/tmp/test.pdf"); /* save the document into a file */ ?>
Builtin 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. |
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. |
HaruException类
HaruException extends Exception { /* Inherits */ final public Exception::getMessage ( void ) : string final public Exception::getPrevious ( void ) : Throwable final public Exception::getCode ( void ) : int final public Exception::getFile ( void ) : string final public Exception::getLine ( void ) : int final public Exception::getTrace ( void ) : array final public Exception::getTraceAsString ( void ) : string public Exception::__toString ( void ) : string final private Exception::__clone ( void ) : void }
HaruDoc类
HaruDoc { /* 方法 */ addPage ( void ) : object addPageLabel ( int $first_page , int $style , int $first_num [, string $prefix = "" ] ) : bool __construct ( void ) createOutline ( string $title [, object $parent_outline [, object $encoder ]] ) : object getCurrentEncoder ( void ) : object getCurrentPage ( void ) : object getEncoder ( string $encoding ) : object getFont ( string $fontname [, string $encoding ] ) : object getInfoAttr ( int $type ) : string getPageLayout ( void ) : int getPageMode ( void ) : int getStreamSize ( void ) : int insertPage ( object $page ) : object loadJPEG ( string $filename ) : object loadPNG ( string $filename [, bool $deferred = FALSE ] ) : object loadRaw ( string $filename , int $width , int $height , int $color_space ) : object loadTTC ( string $fontfile , int $index [, bool $embed = FALSE ] ) : string loadTTF ( string $fontfile [, bool $embed = FALSE ] ) : string loadType1 ( string $afmfile [, string $pfmfile ] ) : string output ( void ) : bool readFromStream ( int $bytes ) : string resetError ( void ) : bool resetStream ( void ) : bool save ( string $file ) : bool saveToStream ( void ) : bool setCompressionMode ( int $mode ) : bool setCurrentEncoder ( string $encoding ) : bool setEncryptionMode ( int $mode [, int $key_len = 5 ] ) : bool setInfoAttr ( int $type , string $info ) : bool setInfoDateAttr ( int $type , int $year , int $month , int $day , int $hour , int $min , int $sec , string $ind , int $off_hour , int $off_min ) : bool setOpenAction ( object $destination ) : bool setPageLayout ( int $layout ) : bool setPageMode ( int $mode ) : bool setPagesConfiguration ( int $page_per_pages ) : bool setPassword ( string $owner_password , string $user_password ) : bool setPermission ( int $permission ) : bool useCNSEncodings ( void ) : bool useCNSFonts ( void ) : bool useCNTEncodings ( void ) : bool useCNTFonts ( void ) : bool useJPEncodings ( void ) : bool useJPFonts ( void ) : bool useKREncodings ( void ) : bool useKRFonts ( void ) : bool }