<HTML ><HEAD ><TITLE >ClibPDF functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="method_exists" HREF="function.method-exists.html"><LINK REL="NEXT" TITLE="cpdf_add_annotation" HREF="function.cpdf-add-annotation.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.method-exists.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.cpdf-add-annotation.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.cpdf" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >X. ClibPDF functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN11877" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="cpdf.intro" ></A >Introduction</H1 ><P > ClibPDF lets you create PDF documents with PHP. ClibPDF functionality and API are similar to <A HREF="ref.pdf.html" >PDFlib</A >. This documentation should be read alongside the ClibPDF manual since it explains the library in much greater detail. </P ><P > Many functions in the native ClibPDF and the PHP module, as well as in <A HREF="ref.pdf.html" >PDFlib</A >, have the same name. All functions except for <A HREF="function.cpdf-open.html" ><B CLASS="function" >cpdf_open()</B ></A > take the handle for the document as their first parameter. </P ><P > Currently this handle is not used internally since ClibPDF does not support the creation of several PDF documents at the same time. Actually, you should not even try it, the results are unpredictable. I can't oversee what the consequences in a multi threaded environment are. According to the author of ClibPDF this will change in one of the next releases (current version when this was written is 1.10). If you need this functionality use the pdflib module. </P ><P > A nice feature of ClibPDF (and <A HREF="ref.pdf.html" >PDFlib</A >) is the ability to create the pdf document completely in memory without using temporary files. It also provides the ability to pass coordinates in a predefined unit length. (This feature can also be simulated by <A HREF="function.pdf-translate.html" ><B CLASS="function" >pdf_translate()</B ></A > when using the <A HREF="ref.pdf.html" >PDFlib</A > functions.) </P ><P > Another nice feature of ClibPDF is the fact that any page can be modified at any time even if a new page has been already opened. The function <A HREF="function.cpdf-set-current-page.html" ><B CLASS="function" >cpdf_set_current_page()</B ></A > allows to leave the current page and presume modifying an other page. </P ><P > Most of the functions are fairly easy to use. The most difficult part is probably creating a very simple PDF document at all. The following example should help you to get started. It creates a document with one page. The page contains the text "Times-Roman" in an outlined 30pt font. The text is underlined. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="cpdf.requirements" ></A >Requirements</H1 ><P > In order to use the ClibPDF functions you need to install the ClibPDF package. It is available for download from <A HREF="http://www.fastio.com/" TARGET="_top" > FastIO</A >, but requires that you purchase a license for commercial use. PHP requires that you use cpdflib >= 2. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="cpdf.installation" ></A >Installation</H1 ><P > To get these functions to work, you have to compile PHP with <TT CLASS="option" >--with-cpdflib[=DIR]</TT >. DIR is the cpdflib install directory, defaults to <TT CLASS="filename" >/usr</TT >. In addition you can specify the jpeg library and the tiff library for ClibPDF to use. To do so add to your configure line the options <TT CLASS="option" >--with-jpeg-dir[=DIR]</TT > <TT CLASS="option" >--with-tiff-dir[=DIR]</TT >. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="cpdf.configuration" ></A >Runtime Configuration</H1 ><P >This extension has no configuration directives defined in <TT CLASS="filename" >php.ini</TT >.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="cpdf.constants" ></A >Predefined Constants</H1 ><P > The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >CPDF_PM_NONE</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PM_OUTLINES</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PM_THUMBS</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PM_FULLSCREEN</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PL_SINGLE</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PL_1COLUMN</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PL_2LCOLUMN</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >CPDF_PL_2RCOLUMN</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="cpdf.examples" ></A >Examples</H1 ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN11962" ></A ><P ><B >Example 1. Simple ClibPDF Example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php $cpdf = cpdf_open(0); cpdf_page_init($cpdf, 1, 0, 595, 842, 1.0); cpdf_add_outline($cpdf, 0, 0, 0, 1, "Page 1"); cpdf_begin_text($cpdf); cpdf_set_font($cpdf, "Times-Roman", 30, "WinAnsiEncoding"); cpdf_set_text_rendering($cpdf, 1); cpdf_text($cpdf, "Times Roman outlined", 50, 750); cpdf_end_text($cpdf); cpdf_moveto($cpdf, 50, 740); cpdf_lineto($cpdf, 330, 740); cpdf_stroke($cpdf); cpdf_finalize($cpdf); Header("Content-type: application/pdf"); cpdf_output_buffer($cpdf); cpdf_close($cpdf); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > The pdflib distribution contains a more complex example which creates a series of pages with an analog clock. Here is that example converted into PHP using the ClibPDF extension: </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN11966" ></A ><P ><B >Example 2. pdfclock example from pdflib 2.0 distribution</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php $radius = 200; $margin = 20; $pagecount = 40; $pdf = cpdf_open(0); cpdf_set_creator($pdf, "pdf_clock.php3"); cpdf_set_title($pdf, "Analog Clock"); while($pagecount-- > 0) { cpdf_page_init($pdf, $pagecount+1, 0, 2 * ($radius + $margin), 2 * ($radius + $margin), 1.0); cpdf_set_page_animation($pdf, 4, 0.5, 0, 0, 0); /* wipe */ cpdf_translate($pdf, $radius + $margin, $radius + $margin); cpdf_save($pdf); cpdf_setrgbcolor($pdf, 0.0, 0.0, 1.0); /* minute strokes */ cpdf_setlinewidth($pdf, 2.0); for ($alpha = 0; $alpha < 360; $alpha += 6) { cpdf_rotate($pdf, 6.0); cpdf_moveto($pdf, $radius, 0.0); cpdf_lineto($pdf, $radius-$margin/3, 0.0); cpdf_stroke($pdf); } cpdf_restore($pdf); cpdf_save($pdf); /* 5 minute strokes */ cpdf_setlinewidth($pdf, 3.0); for ($alpha = 0; $alpha < 360; $alpha += 30) { cpdf_rotate($pdf, 30.0); cpdf_moveto($pdf, $radius, 0.0); cpdf_lineto($pdf, $radius-$margin, 0.0); cpdf_stroke($pdf); } $ltime = getdate(); /* draw hour hand */ cpdf_save($pdf); cpdf_rotate($pdf, -(($ltime['minutes']/60.0) + $ltime['hours'] - 3.0) * 30.0); cpdf_moveto($pdf, -$radius/10, -$radius/20); cpdf_lineto($pdf, $radius/2, 0.0); cpdf_lineto($pdf, -$radius/10, $radius/20); cpdf_closepath($pdf); cpdf_fill($pdf); cpdf_restore($pdf); /* draw minute hand */ cpdf_save($pdf); cpdf_rotate($pdf, -(($ltime['seconds']/60.0) + $ltime['minutes'] - 15.0) * 6.0); cpdf_moveto($pdf, -$radius/10, -$radius/20); cpdf_lineto($pdf, $radius * 0.8, 0.0); cpdf_lineto($pdf, -$radius/10, $radius/20); cpdf_closepath($pdf); cpdf_fill($pdf); cpdf_restore($pdf); /* draw second hand */ cpdf_setrgbcolor($pdf, 1.0, 0.0, 0.0); cpdf_setlinewidth($pdf, 2); cpdf_save($pdf); cpdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0)); cpdf_moveto($pdf, -$radius/5, 0.0); cpdf_lineto($pdf, $radius, 0.0); cpdf_stroke($pdf); cpdf_restore($pdf); /* draw little circle at center */ cpdf_circle($pdf, 0, 0, $radius/30); cpdf_fill($pdf); cpdf_restore($pdf); cpdf_finalize_page($pdf, $pagecount+1); } cpdf_finalize($pdf); Header("Content-type: application/pdf"); cpdf_output_buffer($pdf); cpdf_close($pdf); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="cpdf.seealso" ></A >See Also</H1 ><P > See also the <A HREF="ref.pdf.html" >PDFlib</A > extension documentation. </P ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.cpdf-add-annotation.html" >cpdf_add_annotation</A > -- Adds annotation</DT ><DT ><A HREF="function.cpdf-add-outline.html" >cpdf_add_outline</A > -- Adds bookmark for current page</DT ><DT ><A HREF="function.cpdf-arc.html" >cpdf_arc</A > -- Draws an arc</DT ><DT ><A HREF="function.cpdf-begin-text.html" >cpdf_begin_text</A > -- Starts text section</DT ><DT ><A HREF="function.cpdf-circle.html" >cpdf_circle</A > -- Draw a circle</DT ><DT ><A HREF="function.cpdf-clip.html" >cpdf_clip</A > -- Clips to current path</DT ><DT ><A HREF="function.cpdf-close.html" >cpdf_close</A > -- Closes the pdf document</DT ><DT ><A HREF="function.cpdf-closepath-fill-stroke.html" >cpdf_closepath_fill_stroke</A > -- Close, fill and stroke current path</DT ><DT ><A HREF="function.cpdf-closepath-stroke.html" >cpdf_closepath_stroke</A > -- Close path and draw line along path</DT ><DT ><A HREF="function.cpdf-closepath.html" >cpdf_closepath</A > -- Close path</DT ><DT ><A HREF="function.cpdf-continue-text.html" >cpdf_continue_text</A > -- Output text in next line</DT ><DT ><A HREF="function.cpdf-curveto.html" >cpdf_curveto</A > -- Draws a curve</DT ><DT ><A HREF="function.cpdf-end-text.html" >cpdf_end_text</A > -- Ends text section</DT ><DT ><A HREF="function.cpdf-fill-stroke.html" >cpdf_fill_stroke</A > -- Fill and stroke current path</DT ><DT ><A HREF="function.cpdf-fill.html" >cpdf_fill</A > -- Fill current path</DT ><DT ><A HREF="function.cpdf-finalize-page.html" >cpdf_finalize_page</A > -- Ends page</DT ><DT ><A HREF="function.cpdf-finalize.html" >cpdf_finalize</A > -- Ends document</DT ><DT ><A HREF="function.cpdf-global-set-document-limits.html" >cpdf_global_set_document_limits</A > -- Sets document limits for any pdf document</DT ><DT ><A HREF="function.cpdf-import-jpeg.html" >cpdf_import_jpeg</A > -- Opens a JPEG image</DT ><DT ><A HREF="function.cpdf-lineto.html" >cpdf_lineto</A > -- Draws a line</DT ><DT ><A HREF="function.cpdf-moveto.html" >cpdf_moveto</A > -- Sets current point</DT ><DT ><A HREF="function.cpdf-newpath.html" >cpdf_newpath</A > -- Starts a new path</DT ><DT ><A HREF="function.cpdf-open.html" >cpdf_open</A > -- Opens a new pdf document</DT ><DT ><A HREF="function.cpdf-output-buffer.html" >cpdf_output_buffer</A > -- Outputs the pdf document in memory buffer</DT ><DT ><A HREF="function.cpdf-page-init.html" >cpdf_page_init</A > -- Starts new page</DT ><DT ><A HREF="function.cpdf-place-inline-image.html" >cpdf_place_inline_image</A > -- Places an image on the page</DT ><DT ><A HREF="function.cpdf-rect.html" >cpdf_rect</A > -- Draw a rectangle</DT ><DT ><A HREF="function.cpdf-restore.html" >cpdf_restore</A > -- Restores formerly saved environment</DT ><DT ><A HREF="function.cpdf-rlineto.html" >cpdf_rlineto</A > -- Draws a line</DT ><DT ><A HREF="function.cpdf-rmoveto.html" >cpdf_rmoveto</A > -- Sets current point</DT ><DT ><A HREF="function.cpdf-rotate-text.html" >cpdf_rotate_text</A > -- Sets text rotation angle </DT ><DT ><A HREF="function.cpdf-rotate.html" >cpdf_rotate</A > -- Sets rotation</DT ><DT ><A HREF="function.cpdf-save-to-file.html" >cpdf_save_to_file</A > -- Writes the pdf document into a file</DT ><DT ><A HREF="function.cpdf-save.html" >cpdf_save</A > -- Saves current environment</DT ><DT ><A HREF="function.cpdf-scale.html" >cpdf_scale</A > -- Sets scaling</DT ><DT ><A HREF="function.cpdf-set-action-url.html" >cpdf_set_action_url</A > -- Sets hyperlink </DT ><DT ><A HREF="function.cpdf-set-char-spacing.html" >cpdf_set_char_spacing</A > -- Sets character spacing</DT ><DT ><A HREF="function.cpdf-set-creator.html" >cpdf_set_creator</A > -- Sets the creator field in the pdf document</DT ><DT ><A HREF="function.cpdf-set-current-page.html" >cpdf_set_current_page</A > -- Sets current page</DT ><DT ><A HREF="function.cpdf-set-font-directories.html" >cpdf_set_font_directories</A > -- Sets directories to search when using external fonts </DT ><DT ><A HREF="function.cpdf-set-font-map-file.html" >cpdf_set_font_map_file</A > -- Sets fontname to filename translation map when using external fonts </DT ><DT ><A HREF="function.cpdf-set-font.html" >cpdf_set_font</A > -- Select the current font face and size</DT ><DT ><A HREF="function.cpdf-set-horiz-scaling.html" >cpdf_set_horiz_scaling</A > -- Sets horizontal scaling of text</DT ><DT ><A HREF="function.cpdf-set-keywords.html" >cpdf_set_keywords</A > -- Sets the keywords field of the pdf document</DT ><DT ><A HREF="function.cpdf-set-leading.html" >cpdf_set_leading</A > -- Sets distance between text lines</DT ><DT ><A HREF="function.cpdf-set-page-animation.html" >cpdf_set_page_animation</A > -- Sets duration between pages</DT ><DT ><A HREF="function.cpdf-set-subject.html" >cpdf_set_subject</A > -- Sets the subject field of the pdf document</DT ><DT ><A HREF="function.cpdf-set-text-matrix.html" >cpdf_set_text_matrix</A > -- Sets the text matrix</DT ><DT ><A HREF="function.cpdf-set-text-pos.html" >cpdf_set_text_pos</A > -- Sets text position</DT ><DT ><A HREF="function.cpdf-set-text-rendering.html" >cpdf_set_text_rendering</A > -- Determines how text is rendered</DT ><DT ><A HREF="function.cpdf-set-text-rise.html" >cpdf_set_text_rise</A > -- Sets the text rise</DT ><DT ><A HREF="function.cpdf-set-title.html" >cpdf_set_title</A > -- Sets the title field of the pdf document</DT ><DT ><A HREF="function.cpdf-set-viewer-preferences.html" >cpdf_set_viewer_preferences</A > -- How to show the document in the viewer </DT ><DT ><A HREF="function.cpdf-set-word-spacing.html" >cpdf_set_word_spacing</A > -- Sets spacing between words</DT ><DT ><A HREF="function.cpdf-setdash.html" >cpdf_setdash</A > -- Sets dash pattern</DT ><DT ><A HREF="function.cpdf-setflat.html" >cpdf_setflat</A > -- Sets flatness</DT ><DT ><A HREF="function.cpdf-setgray-fill.html" >cpdf_setgray_fill</A > -- Sets filling color to gray value</DT ><DT ><A HREF="function.cpdf-setgray-stroke.html" >cpdf_setgray_stroke</A > -- Sets drawing color to gray value</DT ><DT ><A HREF="function.cpdf-setgray.html" >cpdf_setgray</A > -- Sets drawing and filling color to gray value</DT ><DT ><A HREF="function.cpdf-setlinecap.html" >cpdf_setlinecap</A > -- Sets linecap parameter</DT ><DT ><A HREF="function.cpdf-setlinejoin.html" >cpdf_setlinejoin</A > -- Sets linejoin parameter</DT ><DT ><A HREF="function.cpdf-setlinewidth.html" >cpdf_setlinewidth</A > -- Sets line width</DT ><DT ><A HREF="function.cpdf-setmiterlimit.html" >cpdf_setmiterlimit</A > -- Sets miter limit</DT ><DT ><A HREF="function.cpdf-setrgbcolor-fill.html" >cpdf_setrgbcolor_fill</A > -- Sets filling color to rgb color value</DT ><DT ><A HREF="function.cpdf-setrgbcolor-stroke.html" >cpdf_setrgbcolor_stroke</A > -- Sets drawing color to rgb color value</DT ><DT ><A HREF="function.cpdf-setrgbcolor.html" >cpdf_setrgbcolor</A > -- Sets drawing and filling color to rgb color value</DT ><DT ><A HREF="function.cpdf-show-xy.html" >cpdf_show_xy</A > -- Output text at position</DT ><DT ><A HREF="function.cpdf-show.html" >cpdf_show</A > -- Output text at current position</DT ><DT ><A HREF="function.cpdf-stringwidth.html" >cpdf_stringwidth</A > -- Returns width of text in current font</DT ><DT ><A HREF="function.cpdf-stroke.html" >cpdf_stroke</A > -- Draw line along path</DT ><DT ><A HREF="function.cpdf-text.html" >cpdf_text</A > -- Output text with parameters</DT ><DT ><A HREF="function.cpdf-translate.html" >cpdf_translate</A > -- Sets origin of coordinate system</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.method-exists.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.cpdf-add-annotation.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >method_exists</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >cpdf_add_annotation</TD ></TR ></TABLE ></DIV ></BODY ></HTML >