出售域名  LinuxTags


ClibPDF Functions [deprecated]

简介

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: 本扩展已被移动到 » PECL 库中且自以下版本起不再被绑定到 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.

需求

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.

安装

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].

运行时配置

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

预定义常量

以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。

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)

范例

Example#1 Simple ClibPDF Example

<?php
$cpdf 
cpdf_open(0);
cpdf_page_init($cpdf105958421.0);
cpdf_add_outline($cpdf0001"Page 1");
cpdf_begin_text($cpdf);
cpdf_set_font($cpdf"Times-Roman"30"WinAnsiEncoding");
cpdf_set_text_rendering($cpdf1);
cpdf_text($cpdf"Times Roman outlined"5050);
cpdf_end_text($cpdf);
cpdf_moveto($cpdf5050);
cpdf_lineto($cpdf740330);
cpdf_stroke($cpdf);
cpdf_finalize_page($cpdf1);
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#2 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+10* ($radius $margin), * ($radius $margin), 1.0);
  
  
cpdf_set_page_animation($pdf40.5000);  /* wipe */
  
  
cpdf_translate($pdf$radius $margin$radius $margin);
  
cpdf_save($pdf);
  
cpdf_setrgbcolor($pdf0.00.01.0);
  
  
/* minute strokes */
  
cpdf_setlinewidth($pdf2.0);
  for (
$alpha 0$alpha 360$alpha += 6) {
    
cpdf_rotate($pdf6.0);
    
cpdf_moveto($pdf$radius0.0);
    
cpdf_lineto($pdf$radius-$margin/30.0);
    
cpdf_stroke($pdf);
  }
  
  
cpdf_restore($pdf);
  
cpdf_save($pdf);
 
  
/* 5 minute strokes */
  
cpdf_setlinewidth($pdf3.0);
  for (
$alpha 0$alpha 360$alpha += 30) {
    
cpdf_rotate($pdf30.0);
    
cpdf_moveto($pdf$radius0.0);
    
cpdf_lineto($pdf$radius-$margin0.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/20.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.80.0);
  
cpdf_lineto($pdf, -$radius/10$radius/20);
  
cpdf_closepath($pdf);
  
cpdf_fill($pdf);
  
cpdf_restore($pdf);

  
/* draw second hand */
  
cpdf_setrgbcolor($pdf1.00.00.0);
  
cpdf_setlinewidth($pdf2);
  
cpdf_save($pdf);
  
cpdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0));
  
cpdf_moveto($pdf, -$radius/50.0);
  
cpdf_lineto($pdf$radius0.0);
  
cpdf_stroke($pdf);
  
cpdf_restore($pdf);

  
/* draw little circle at center */
  
cpdf_circle($pdf00$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 the PDFlib extension documentation.

Table of Contents


出售域名  LinuxTags