# Haru PDF Functions

## Introduction

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

This extension is EXPERIMENTAL. The behaviour of this extension -- including the names of its functions and anything else documented about this extension -- may change without notice in a future release of PHP. Use this extension at your own risk.

## Requirements

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.

## Installation

Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: » http://pecl.php.net/package/haru.

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

## Runtime Configuration

This extension has no configuration directives defined in php.ini.

## Examples

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_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 */
?>`

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

## Predefined Classes

- HaruException
- HaruDoc
- HaruPage
- HaruFont
- HaruImage
- HaruEncoder
- HaruOutline
- HaruAnnotation
- HaruDestination

## 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

- HaruException — Haru PDF Exception Class
- HaruDoc — Haru PDF Document Class
- HaruPage — Haru PDF Page Class
- HaruFont — Haru PDF Font Class
- HaruImage — Haru PDF Image Class
- HaruEncoder — Haru PDF Encoder Class
- HaruOutline — Haru PDF Outline Class
- HaruAnnotation — Haru PDF Annotation Class
- HaruDestination — Haru PDF Destination Class
- HaruAnnotation::setBorderStyle — Set the border style of the annotation
- HaruAnnotation::setHighlightMode — Set the highlighting mode of the annotation
- HaruAnnotation::setIcon — Set the icon style of the annotation
- HaruAnnotation::setOpened — Set the initial state of the annotation
- HaruDestination::setFit — Set the appearance of the page to fit the window
- HaruDestination::setFitB — Set the appearance of the page to fit the bounding box of the page within the window
- HaruDestination::setFitBH — Set the appearance of the page to fit the width of the bounding box
- HaruDestination::setFitBV — Set the appearance of the page to fit the height of the boudning box
- HaruDestination::setFitH — Set the appearance of the page to fit the window width
- HaruDestination::setFitR — Set the appearance of the page to fit the specified rectangle
- HaruDestination::setFitV — Set the appearance of the page to fit the window height
- HaruDestination::setXYZ — Set the appearance of the page
- HaruDoc::addPage — Add new page to the document
- HaruDoc::addPageLabel — Set the numbering style for the specified range of pages
- HaruDoc::__construct — Construct new HaruDoc instance
- HaruDoc::createOutline — Create a HaruOutline instance
- HaruDoc::getCurrentEncoder — Get HaruEncoder currently used in the document
- HaruDoc::getCurrentPage — Return current page of the document
- HaruDoc::getEncoder — Get HaruEncoder instance for the specified encoding
- HaruDoc::getFont — Get HaruFont instance
- HaruDoc::getInfoAttr — Get current value of the specified document attribute
- HaruDoc::getPageLayout — Get current page layout
- HaruDoc::getPageMode — Get current page mode
- HaruDoc::getStreamSize — Get the size of the temporary stream
- HaruDoc::insertPage — Insert new page just before the specified page
- HaruDoc::loadJPEG — Load JPEG image and return new HaruImage instance
- HaruDoc::loadPNG — Load PNG image and return HaruImage instance
- HaruDoc::loadRaw — Load RAW image and return HaruImage instance
- HaruDoc::loadTTC — Load the font with the specified index from TTC file
- HaruDoc::loadTTF — Load TTF font file
- HaruDoc::loadType1 — Load Type1 font
- HaruDoc::output — Write the document data to the output buffer
- HaruDoc::readFromStream — Read data from the temporary stream
- HaruDoc::resetError — Reset error state of the document handle
- HaruDoc::resetStream — Rewind the temporary stream
- HaruDoc::save — Save the document into the specified file
- HaruDoc::saveToStream — Save the document into a temporary stream
- HaruDoc::setCompressionMode — Set compression mode for the document
- HaruDoc::setCurrentEncoder — Set the current encoder for the document
- HaruDoc::setEncryptionMode — Set encryption mode for the document
- HaruDoc::setInfoAttr — Set the info attribute of the document
- HaruDoc::setInfoDateAttr — Set the datetime info attributes of the document
- HaruDoc::setOpenAction — Define which page is shown when the document is opened
- HaruDoc::setPageLayout — Set how pages should be displayed
- HaruDoc::setPageMode — Set how the document should be displayed
- HaruDoc::setPagesConfiguration — Set the number of pages per set of pages
- HaruDoc::setPassword — Set owner and user passwords for the document
- HaruDoc::setPermission — Set permissions for the document
- HaruDoc::useCNSEncodings — Enable Chinese simplified encodings
- HaruDoc::useCNSFonts — Enable builtin Chinese simplified fonts
- HaruDoc::useCNTEncodings — Enable Chinese traditional encodings
- HaruDoc::useCNTFonts — Enable builtin Chinese traditional fonts
- HaruDoc::useJPEncodings — Enable Japanese encodings
- HaruDoc::useJPFonts — Enable builtin Japanese fonts
- HaruDoc::useKREncodings — Enable Korean encodings
- HaruDoc::useKRFonts — Enable builtin Korean fonts
- HaruEncoder::getByteType — Get the type of the byte in the text
- HaruEncoder::getType — Get the type of the encoder
- HaruEncoder::getUnicode — Convert the specified character to unicode
- HaruEncoder::getWritingMode — Get the writing mode of the encoder
- HaruFont::getAscent — Get the vertical ascent of the font
- HaruFont::getCapHeight — Get the distance from the baseline of uppercase letters
- HaruFont::getDescent — Get the vertical descent of the font
- HaruFont::getEncodingName — Get the name of the encoding
- HaruFont::getFontName — Get the name of the font
- HaruFont::getTextWidth — Get the total width of the text, number of characters, number of words and number of spaces
- HaruFont::getUnicodeWidth — Get the width of the character in the font
- HaruFont::getXHeight — Get the distance from the baseline of lowercase letters
- HaruFont::measureText — Calculate the number of characters which can be included within the specified width
- HaruImage::getBitsPerComponent — Get the number of bits used to describe each color component of the image
- HaruImage::getColorSpace — Get the name of the color space
- HaruImage::getHeight — Get the height of the image
- HaruImage::getSize — Get size of the image
- HaruImage::getWidth — Get the width of the image
- HaruImage::setColorMask — Set the color mask of the image
- HaruImage::setMaskImage — Set the image mask
- HaruOutline::setDestination — Set the destination for the outline
- HaruOutline::setOpened — Set the initial state of the outline
- HaruPage::arc — Append an arc to the current path
- HaruPage::beginText — Begin a text object and set the current text position to (0,0)
- HaruPage::circle — Append a circle to the current path
- HaruPage::closePath — Append a straight line from the current point to the start point of the path
- HaruPage::concat — Concatenate current transformation matrix of the page and the specified matrix
- HaruPage::createDestination — Create new HaruDestination instance
- HaruPage::createLinkAnnotation — Create new HaruAnnotation instance
- HaruPage::createTextAnnotation — Create new HaruAnnotation instance
- HaruPage::createURLAnnotation — Create and return new HaruAnnotation instance
- HaruPage::curveTo2 — Append a Bezier curve to the current path
- HaruPage::curveTo3 — Append a Bezier curve to the current path
- HaruPage::curveTo — Append a Bezier curve to the current path
- HaruPage::drawImage — Show image at the page
- HaruPage::ellipse — Append an ellipse to the current path
- HaruPage::endPath — End current path object without filling and painting operations
- HaruPage::endText — End current text object
- HaruPage::eofill — Fill current path using even-odd rule
- HaruPage::eoFillStroke — Fill current path using even-odd rule, then paint the path
- HaruPage::fill — Fill current path using nonzero winding number rule
- HaruPage::fillStroke — Fill current path using nonzero winding number rule, then paint the path
- HaruPage::getCharSpace — Get the current value of character spacing
- HaruPage::getCMYKFill — Get the current filling color
- HaruPage::getCMYKStroke — Get the current stroking color
- HaruPage::getCurrentFont — Get the currently used font
- HaruPage::getCurrentFontSize — Get the current font size
- HaruPage::getCurrentPos — Get the current position for path painting
- HaruPage::getCurrentTextPos — Get the current position for text printing
- HaruPage::getDash — Get the current dash pattern
- HaruPage::getFillingColorSpace — Get the current filling color space
- HaruPage::getFlatness — Get the flatness of the page
- HaruPage::getGMode — Get the current graphics mode
- HaruPage::getGrayFill — Get the current filling color
- HaruPage::getGrayStroke — Get the current stroking color
- HaruPage::getHeight — Get the height of the page
- HaruPage::getHorizontalScaling — Get the current value of horizontal scaling
- HaruPage::getLineCap — Get the current line cap style
- HaruPage::getLineJoin — Get the current line join style
- HaruPage::getLineWidth — Get the current line width
- HaruPage::getMiterLimit — Get the value of miter limit
- HaruPage::getRGBFill — Get the current filling color
- HaruPage::getRGBStroke — Get the current stroking color
- HaruPage::getStrokingColorSpace — Get the current stroking color space
- HaruPage::getTextLeading — Get the current value of line spacing
- HaruPage::getTextMatrix — Get the current text transformation matrix of the page
- HaruPage::getTextRenderingMode — Get the current text rendering mode
- HaruPage::getTextRise — Get the current value of text rising
- HaruPage::getTextWidth — Get the width of the text using current fontsize, character spacing and word spacing
- HaruPage::getTransMatrix — Get the current transformation matrix of the page
- HaruPage::getWidth — Get the width of the page
- HaruPage::getWordSpace — Get the current value of word spacing
- HaruPage::lineTo — Draw a line from the current point to the specified point
- HaruPage::measureText — Calculate the number of characters which can be included within the specified width
- HaruPage::moveTextPos — Move text position to the specified offset
- HaruPage::moveTo — Set starting point for new drawing path
- HaruPage::moveToNextLine — Move text position to the start of the next line
- HaruPage::rectangle — Append a rectangle to the current path
- HaruPage::setCharSpace — Set character spacing for the page
- HaruPage::setCMYKFill — Set filling color for the page
- HaruPage::setCMYKStroke — Set stroking color for the page
- HaruPage::setDash — Set the dash pattern for the page
- HaruPage::setFlatness — Set flatness for the page
- HaruPage::setFontAndSize — Set font and fontsize for the page
- HaruPage::setGrayFill — Set filling color for the page
- HaruPage::setGrayStroke — Sets stroking color for the page
- HaruPage::setHeight — Set height of the page
- HaruPage::setHorizontalScaling — Set horizontal scaling for the page
- HaruPage::setLineCap — Set the shape to be used at the ends of lines
- HaruPage::setLineJoin — Set line join style for the page
- HaruPage::setLineWidth — Set line width for the page
- HaruPage::setMiterLimit — Set the current value of the miter limit of the page
- HaruPage::setRGBFill — Set filling color for the page
- HaruPage::setRGBStroke — Set stroking color for the page
- HaruPage::setRotate — Set rotation angle of the page
- HaruPage::setSize — Set size and direction of the page
- HaruPage::setSlideShow — Set transition style for the page
- HaruPage::setTextLeading — Set text leading (line spacing) for the page
- HaruPage::setTextMatrix — Set the current text transformation matrix of the page
- HaruPage::setTextRenderingMode — Set text rendering mode for the page
- HaruPage::setTextRise — Set the current value of text rising
- HaruPage::setWidth — Set width of the page
- HaruPage::setWordSpace — Set word spacing for the page
- HaruPage::showText — Print text at the current position of the page
- HaruPage::showTextNextLine — Move the current position to the start of the next line and print the text
- HaruPage::stroke — Paint current path
- HaruPage::textOut — Print the text on the specified position
- HaruPage::textRect — Print the text inside the specified region