Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : ClibPDF Functions [deprecated]

ClibPDF Functions [deprecated]

Introduction

Warning:

ClibPDF support is deprecated and users are strongly encouraged to use an alternative, like Haru, PDFlib, or one of the available PHP alternatives.

ClibPDF lets you create PDF documents with PHP. ClibPDF functionality and API are similar to PDFlib. This documentation should be read alongside the ClibPDF manual since it explains the library in much greater detail.

Many functions in the native ClibPDF and the PHP module, as well as in PDFlib, have the same name. All functions except for cpdf_open() take the handle for the document as their first parameter.

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.

A nice feature of ClibPDF (and PDFlib) 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 pdf_translate() when using the PDFlib functions.)

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 cpdf_set_current_page() allows to leave the current page and presume modifying an other page.

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.

Note:

This extension has been moved to the » PECL repository and is no longer bundled with PHP as of PHP 5.1.0.

Note:

If you're interested in alternative free PDF generators that do not utilize external PDF libraries, see this related FAQ.

Requirements

In order to use the ClibPDF functions you need to install the ClibPDF package. It is available for download from » FastIO, but requires that you purchase a license for commercial use. PHP requires that you use cpdflib >= 2. The development of ClibPDF library has been discontinued thus FastIO website would be most probably inaccessible.

Installation

To get these functions to work, you have to compile PHP with --with-cpdflib[=DIR]. DIR is the cpdflib install directory, defaults to /usr. 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 --with-jpeg-dir[=DIR] --with-tiff-dir[=DIR].

Runtime Configuration

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

Predefined Constants

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.

CPDF_PM_NONE (integer)
CPDF_PM_OUTLINES (integer)
CPDF_PM_THUMBS (integer)
CPDF_PM_FULLSCREEN (integer)
CPDF_PL_SINGLE (integer)
CPDF_PL_1COLUMN (integer)
CPDF_PL_2LCOLUMN (integer)
CPDF_PL_2RCOLUMN (integer)

Examples

Example 395. Simple ClibPDF Example

<?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, 50);
cpdf_end_text($cpdf);
cpdf_moveto($cpdf, 50, 50);
cpdf_lineto($cpdf, 740, 330);
cpdf_stroke($cpdf);
cpdf_finalize_page($cpdf, 1);
cpdf_finalize($cpdf);
Header("Content-type: application/pdf");
cpdf_output_buffer($cpdf);
cpdf_close($cpdf);
?>


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:

Example 396. pdfclock example from pdflib 2.0 distribution

<?php
$radius
= 200;
$margin = 20;
$pagecount = 40;

$pdf = cpdf_open(0);
cpdf_set_creator($pdf, "pdf_clock.php");
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);
?>


See Also

See also the PDFlib extension documentation.

Table of Contents

cpdf_add_annotation — Adds annotation
cpdf_add_outline — Adds bookmark for current page
cpdf_arc — Draws an arc
cpdf_begin_text — Starts text section
cpdf_circle — Draw a circle
cpdf_clip — Clips to current path
cpdf_close — Closes the pdf document
cpdf_closepath_fill_stroke — Close, fill and stroke current path
cpdf_closepath_stroke — Close path and draw line along path
cpdf_closepath — Close path
cpdf_continue_text — Output text in next line
cpdf_curveto — Draws a curve
cpdf_end_text — Ends text section
cpdf_fill_stroke — Fill and stroke current path
cpdf_fill — Fill current path
cpdf_finalize_page — Ends page
cpdf_finalize — Ends document
cpdf_global_set_document_limits — Sets document limits for any pdf document
cpdf_import_jpeg — Opens a JPEG image
cpdf_lineto — Draws a line
cpdf_moveto — Sets current point
cpdf_newpath — Starts a new path
cpdf_open — Opens a new pdf document
cpdf_output_buffer — Outputs the pdf document in memory buffer
cpdf_page_init — Starts new page
cpdf_place_inline_image — Places an image on the page
cpdf_rect — Draw a rectangle
cpdf_restore — Restores formerly saved environment
cpdf_rlineto — Draws a line
cpdf_rmoveto — Sets current point
cpdf_rotate_text — Sets text rotation angle
cpdf_rotate — Sets rotation
cpdf_save_to_file — Writes the pdf document into a file
cpdf_save — Saves current environment
cpdf_scale — Sets scaling
cpdf_set_action_url — Sets hyperlink
cpdf_set_char_spacing — Sets character spacing
cpdf_set_creator — Sets the creator field in the pdf document
cpdf_set_current_page — Sets current page
cpdf_set_font_directories — Sets directories to search when using external fonts
cpdf_set_font_map_file — Sets fontname to filename translation map when using external fonts
cpdf_set_font — Select the current font face and size
cpdf_set_horiz_scaling — Sets horizontal scaling of text
cpdf_set_keywords — Sets the keywords field of the pdf document
cpdf_set_leading — Sets distance between text lines
cpdf_set_page_animation — Sets duration between pages
cpdf_set_subject — Sets the subject field of the pdf document
cpdf_set_text_matrix — Sets the text matrix
cpdf_set_text_pos — Sets text position
cpdf_set_text_rendering — Determines how text is rendered
cpdf_set_text_rise — Sets the text rise
cpdf_set_title — Sets the title field of the pdf document
cpdf_set_viewer_preferences — How to show the document in the viewer
cpdf_set_word_spacing — Sets spacing between words
cpdf_setdash — Sets dash pattern
cpdf_setflat — Sets flatness
cpdf_setgray_fill — Sets filling color to gray value
cpdf_setgray_stroke — Sets drawing color to gray value
cpdf_setgray — Sets drawing and filling color to gray value
cpdf_setlinecap — Sets linecap parameter
cpdf_setlinejoin — Sets linejoin parameter
cpdf_setlinewidth — Sets line width
cpdf_setmiterlimit — Sets miter limit
cpdf_setrgbcolor_fill — Sets filling color to rgb color value
cpdf_setrgbcolor_stroke — Sets drawing color to rgb color value
cpdf_setrgbcolor — Sets drawing and filling color to rgb color value
cpdf_show_xy — Output text at position
cpdf_show — Output text at current position
cpdf_stringwidth — Returns width of text in current font
cpdf_stroke — Draw line along path
cpdf_text — Output text with parameters
cpdf_translate — Sets origin of coordinate system

Code Examples / Notes » ref.cpdf

puterasalji

I've finally found a way to display text
<?php
$radius = 200;
$margin = 20;
$pagecount = 1;
$pdf = cpdf_open(0);
 cpdf_page_init($pdf, $pagecount+1, 0, 2 * ($radius + $margin), 2 * ($radius + $margin), 1.0);
 cpdf_translate($pdf, $radius + $margin, $radius + $margin);
 cpdf_begin_text($pdf);
 cpdf_set_font($pdf, "Arial", 30, "NULL");
 cpdf_set_text_rendering($pdf, 1);
 cpdf_text($pdf, "Yahoo!!", -198, 50);
 cpdf_end_text($pdf);
 /* minute strokes*/
 for ($alpha = 0; $alpha < 90; $alpha += 6)
   {
   cpdf_setrgbcolor($pdf,9.0,9.0,0.0);
   cpdf_rotate($pdf, 6.0);
   cpdf_moveto($pdf, $radius, 0.0);
   cpdf_lineto($pdf, $radius-$margin/3, 0.0);
   cpdf_stroke($pdf);
   }
cpdf_finalize($pdf);
Header("Content-type: application/pdf");
cpdf_output_buffer($pdf);
cpdf_close($pdf);
?>
I'm not sure why, but the text appeared only after I've pasted the minute strokes draw function from clock.php example. I user the cpdf_translate to begin the x,y coordinate in the middle of the document


Change Language


Follow Navioo On Twitter
.NET Functions
Apache-specific Functions
Alternative PHP Cache
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BBCode Functions
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Class/Object Functions
Classkit Functions
ClibPDF Functions [deprecated]
COM and .Net (Windows)
Crack Functions
Character Type Functions
CURL
Cybercash Payment Functions
Credit Mutuel CyberMUT functions
Cyrus IMAP administration Functions
Date and Time Functions
DB++ Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
enchant Functions
Error Handling and Logging Functions
Exif Functions
Expect Functions
File Alteration Monitor Functions
Forms Data Format Functions
Fileinfo Functions
filePro Functions
Filesystem Functions
Filter Functions
Firebird/InterBase Functions
Firebird/Interbase Functions (PDO_FIREBIRD)
FriBiDi Functions
FrontBase Functions
FTP Functions
Function Handling Functions
GeoIP Functions
Gettext Functions
GMP Functions
gnupg Functions
Net_Gopher
Haru PDF Functions
hash Functions
HTTP
Hyperwave Functions
Hyperwave API Functions
i18n Functions
IBM Functions (PDO_IBM)
IBM DB2
iconv Functions
ID3 Functions
IIS Administration Functions
Image Functions
Imagick Image Library
IMAP
Informix Functions
Informix Functions (PDO_INFORMIX)
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
JSON Functions
KADM5
LDAP Functions
libxml Functions
Lotus Notes Functions
LZF Functions
Mail Functions
Mailparse Functions
Mathematical Functions
MaxDB PHP Extension
MCAL Functions
Mcrypt Encryption Functions
MCVE (Monetra) Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Microsoft SQL Server Functions
Microsoft SQL Server and Sybase Functions (PDO_DBLIB)
Mohawk Software Session Handler Functions
mSQL Functions
Multibyte String Functions
muscat Functions
MySQL Functions
MySQL Functions (PDO_MYSQL)
MySQL Improved Extension
Ncurses Terminal Screen Control Functions
Network Functions
Newt Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Object property and method call overloading
Oracle Functions
ODBC Functions (Unified)
ODBC and DB2 Functions (PDO_ODBC)
oggvorbis
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions [deprecated]
Oracle Functions (PDO_OCI)
Output Control Functions
Ovrimos SQL Functions
Paradox File Access
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF Functions
PDO Functions
Phar archive stream and classes
PHP Options&Information
POSIX Functions
Regular Expression Functions (POSIX Extended)
PostgreSQL Functions
PostgreSQL Functions (PDO_PGSQL)
Printer Functions
Program Execution Functions
PostScript document creation
Pspell Functions
qtdom Functions
Radius
Rar Functions
GNU Readline
GNU Recode Functions
RPM Header Reading Functions
runkit Functions
SAM - Simple Asynchronous Messaging
Satellite CORBA client extension [deprecated]
SCA Functions
SDO Functions
SDO XML Data Access Service Functions
SDO Relational Data Access Service Functions
Semaphore
SESAM Database Functions
PostgreSQL Session Save Handler
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
SQLite Functions (PDO_SQLITE)
Secure Shell2 Functions
Statistics Functions
Stream Functions
String Functions
Subversion Functions
Shockwave Flash Functions
Swish Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
Unicode Functions
URL Functions
Variable Handling Functions
Verisign Payflow Pro Functions
vpopmail Functions
W32api Functions
WDDX Functions
win32ps Functions
win32service Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XMLReader functions
XMLWriter Functions
XSL functions
XSLT Functions
YAZ Functions
YP/NIS Functions
Zip File Functions
Zlib Compression Functions
eXTReMe Tracker