PHP  
downloads | documentation | faq | getting help | | php.net sites | links 
search for in the  
previousoverloadpdf_add_annotationnext
Last updated: Tue, 28 May 2002
view this page in Printer friendly version | English | Brazilian Portuguese | Czech | Dutch | French | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

LXXV. PDF functions

Introduction

The PDF functions in PHP can create PDF files using the PDFlib library created by . PDFlib is available for download at , but requires that you purchase a license for commercial use. The and libraries are required to compile this extension. Please see the PDFlib installation section for more information about compiling PDF support into PHP.

The documentation in this section is only meant to be an overview of the available functions in the PDFlib library and should not be considered an exhaustive reference. Please consult the documentation included in the source distribution of PDFlib for the full and detailed explanation of each function here. It provides a very good overview of what PDFlib is capable of doing and contains the most up-to-date documentation of all functions.

All of the functions in PDFlib and the PHP module have identical function names and parameters. You will need to understand some of the basic concepts of PDF and PostScript to efficiently use this extension. All lengths and coordinates are measured in PostScript points. There are generally 72 PostScript points to an inch, but this depends on the output resolution. Please see the PDFlib documentation included with the source distribution of PDFlib for a more thorough explanation of the coordinate system used.

Please note that most of the PDF functions require a pdf object as it's first parameter. Please see the examples below for more information.

Huomaa: An alternative PHP module for PDF document creation based on ClibPDF is available. Please see the ClibPDF section for details. Note that ClibPDF has a slightly different API compared to PDFlib.

Confusion with old PDFlib versions

Starting with PHP 4.0.5, the PHP extension for PDFlib is officially supported by PDFlib GmbH. This means that all the functions described in the PDFlib manual (V3.00 or greater) are supported by PHP 4 with exactly the same meaning and the same parameters. Only the return values may differ from the PDFlib manual, because the PHP convention of returning FALSE was adopted. For compatibility reasons this binding for PDFlib still supports the old functions, but they should be replaced by their new versions. PDFlib GmbH will not support any problems arising from the use of these deprecated functions.

Taulu 1. Deprecated functions and its replacements

Old functionReplacement
pdf_put_image()Not needed anymore.
pdf_execute_image()Not needed anymore.
pdf_get_annotation()pdf_get_bookmark() using the same parameters.
pdf_get_font()pdf_get_value() passing "font" as the second parameter.
pdf_get_fontsize()pdf_get_value() passing "fontsize" as the second parameter.
pdf_get_fontname()pdf_get_parameter() passing "fontname" as the second parameter.
pdf_set_info_creator()pdf_set_info() passing "Creator" as the second parameter.
pdf_set_info_title()pdf_set_info() passing "Title" as the second parameter.
pdf_set_info_subject()pdf_set_info() passing "Subject" as the second parameter.
pdf_set_info_author()pdf_set_info() passing "Author" as the second parameter.
pdf_set_info_keywords()pdf_set_info() passing "Keywords" as the second parameter.
pdf_set_leading()pdf_set_value() passing "leading" as the second parameter.
pdf_set_text_rendering()pdf_set_value() passing "textrendering" as the second parameter.
pdf_set_text_rise()pdf_set_value() passing "textrise" as the second parameter.
pdf_set_horiz_scaling()pdf_set_value() passing "horizscaling" as the second parameter.
pdf_set_text_matrix()Not available anymore
pdf_set_char_spacing()pdf_set_value() passing "charspacing" as the second parameter.
pdf_set_word_spacing()pdf_set_value() passing "wordspacing" as the second parameter.
pdf_set_transition()pdf_set_parameter() passing "transition" as the second parameter.
pdf_open()pdf_new() plus an subsequent call of pdf_open_file()
pdf_set_font()pdf_findfont() plus an subsequent call of pdf_setfont()
pdf_set_duration()pdf_set_value() passing "duration" as the second parameter.
pdf_open_gif()pdf_open_image_file() passing "gif" as the second parameter.
pdf_open_jpeg()pdf_open_image_file() passing "jpeg" as the second parameter.
pdf_open_tiff()pdf_open_image_file() passing "tiff" as the second parameter.
pdf_open_png()pdf_open_image_file() passing "png" as the second parameter.
pdf_get_image_width()pdf_get_value() passing "imagewidth" as the second parameter and the image as the third parameter.
pdf_get_image_height()pdf_get_value() passing "imageheight" as the second parameter and the image as the third parameter.

PDFlib 3.x Installation Hints

When using version 3.x of PDFlib, you should configure PDFlib with the option --enable-shared-pdflib.

Issues with older versions of PDFlib

Any version of PHP 4 after March 9, 2000 does not support versions of PDFlib older than 3.0.

PDFlib 3.0 or greater is supported by PHP 3.0.19 and later.

Examples

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 to get started. It creates test.pdf with one page. The page contains the text "Times Roman outlined" in an outlined, 30pt font. The text is also underlined.

Esimerkki 1. Creating a PDF document with PDFlib

<?php
$pdf = pdf_new();
pdf_open_file($pdf, "test.pdf");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Test for PHP wrapper of PDFlib 2.0");
pdf_set_info($pdf, "Creator", "See Author");
pdf_set_info($pdf, "Subject", "Testing");
pdf_begin_page($pdf, 595, 842);
pdf_add_outline($pdf, "Page 1");
pdf_set_font($pdf, "Times-Roman", 30, "host");
pdf_set_value($pdf, "textrendering", 1);
pdf_show_xy($pdf, "Times Roman outlined", 50, 750);
pdf_moveto($pdf, 50, 740);
pdf_lineto($pdf, 330, 740);
pdf_stroke($pdf);
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
echo "<A HREF=getpdf.php>finished</A>";
?>

The script getpdf.php just returns the pdf document.

<?php
$len = filesize($filename);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=foo.pdf");
readfile($filename);
?>

The PDFlib distribution contains a more complex example which creates a page with an analog clock. Here we use the in memory creation feature of PDFlib to alleviate the need to use temporary files. The example, converted to PHP from the PDFlib example, is as follows: (The same example is available in the CLibPDF documentation.)

Esimerkki 2. pdfclock example from PDFlib distribution

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

$pdf = pdf_new();

if (!pdf_open_file($pdf, "")) {
    print error;
    exit;
};

pdf_set_parameter($pdf, "warning", "true");

pdf_set_info($pdf, "Creator", "pdf_clock.php");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Analog Clock");

while($pagecount-- > 0) {
    pdf_begin_page($pdf, 2 * ($radius + $margin), 2 * ($radius + $margin));

    pdf_set_parameter($pdf, "transition", "wipe");
    pdf_set_value($pdf, "duration", 0.5);
  
    pdf_translate($pdf, $radius + $margin, $radius + $margin);
    pdf_save($pdf);
    pdf_setrgbcolor($pdf, 0.0, 0.0, 1.0);

    /* minute strokes */
    pdf_setlinewidth($pdf, 2.0);
    for ($alpha = 0; $alpha < 360; $alpha += 6) {
        pdf_rotate($pdf, 6.0);
        pdf_moveto($pdf, $radius, 0.0);
        pdf_lineto($pdf, $radius-$margin/3, 0.0);
        pdf_stroke($pdf);
    }

    pdf_restore($pdf);
    pdf_save($pdf);

    /* 5 minute strokes */
    pdf_setlinewidth($pdf, 3.0);
    for ($alpha = 0; $alpha < 360; $alpha += 30) { 
        pdf_rotate($pdf, 30.0);
        pdf_moveto($pdf, $radius, 0.0);
        pdf_lineto($pdf, $radius-$margin, 0.0);
        pdf_stroke($pdf);
    }

    $ltime = getdate();

    /* draw hour hand */
    pdf_save($pdf);
    pdf_rotate($pdf,-(($ltime['minutes']/60.0)+$ltime['hours']-3.0)*30.0);
    pdf_moveto($pdf, -$radius/10, -$radius/20);
    pdf_lineto($pdf, $radius/2, 0.0);
    pdf_lineto($pdf, -$radius/10, $radius/20);
    pdf_closepath($pdf);
    pdf_fill($pdf);
    pdf_restore($pdf);

    /* draw minute hand */
    pdf_save($pdf);
    pdf_rotate($pdf,-(($ltime['seconds']/60.0)+$ltime['minutes']-15.0)*6.0);
    pdf_moveto($pdf, -$radius/10, -$radius/20);
    pdf_lineto($pdf, $radius * 0.8, 0.0);
    pdf_lineto($pdf, -$radius/10, $radius/20);
    pdf_closepath($pdf);
    pdf_fill($pdf);
    pdf_restore($pdf);

    /* draw second hand */
    pdf_setrgbcolor($pdf, 1.0, 0.0, 0.0);
    pdf_setlinewidth($pdf, 2);
    pdf_save($pdf);
    pdf_rotate($pdf, -(($ltime['seconds'] - 15.0) * 6.0));
    pdf_moveto($pdf, -$radius/5, 0.0);
    pdf_lineto($pdf, $radius, 0.0);
    pdf_stroke($pdf);
    pdf_restore($pdf);

    /* draw little circle at center */
    pdf_circle($pdf, 0, 0, $radius/30);
    pdf_fill($pdf);

    pdf_restore($pdf);

    pdf_end_page($pdf);

    # to see some difference
    sleep(1);
}

pdf_close($pdf);

$buf = pdf_get_buffer($pdf);
$len = strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=foo.pdf");
print $buf;

pdf_delete($pdf);
?>

Sis�llys
pdf_add_annotation -- Deprecated: Adds annotation
pdf_add_bookmark -- Adds bookmark for current page
pdf_add_launchlink -- Add a launch annotation for current page
pdf_add_locallink -- Add a link annotation for current page
pdf_add_note -- Add a note annotation for current page
pdf_add_outline -- Deprecated: Adds bookmark for current page
pdf_add_pdflink -- Adds file link annotation for current page
pdf_add_thumbnail -- Adds thumbnail for current page
pdf_add_weblink -- Adds weblink for current page
pdf_arc -- Draws an arc (counterclockwise)
pdf_arcn -- Draws an arc (clockwise)
pdf_attach_file -- Adds a file attachement for current page
pdf_begin_page -- Starts new page
pdf_begin_pattern -- Starts new pattern
pdf_begin_template -- Starts new template
pdf_circle -- Draws a circle
pdf_clip -- Clips to current path
pdf_close -- Closes a pdf object
pdf_close_image -- Closes an image
pdf_close_pdi --  Close the input PDF document
pdf_close_pdi_page --  Close the page handle
pdf_closepath -- Closes path
pdf_closepath_fill_stroke -- Closes, fills and strokes current path
pdf_closepath_stroke -- Closes path and draws line along path
pdf_concat -- Concatenate a matrix to the CTM
pdf_continue_text -- Outputs text in next line
pdf_curveto -- Draws a curve
pdf_delete -- Deletes a PDF object
pdf_end_page -- Ends a page
pdf_end_pattern -- Finish pattern
pdf_end_template -- Finish template
pdf_endpath -- Deprecated: Ends current path
pdf_fill -- Fills current path
pdf_fill_stroke -- Fills and strokes current path
pdf_findfont -- Prepare font for later use with pdf_setfont().
pdf_get_buffer -- Fetch the buffer containig the generated PDF data.
pdf_get_font -- Deprecated: font handling
pdf_get_fontname -- Deprecated: font handling
pdf_get_fontsize -- Deprecated: font handling
pdf_get_image_height -- Returns height of an image
pdf_get_image_width -- Returns width of an image
pdf_get_majorversion --  Returns the major version number of the PDFlib
pdf_get_minorversion --  Returns the minor version number of the PDFlib
pdf_get_parameter -- Gets certain parameters
pdf_get_pdi_parameter -- Get some PDI string parameters
pdf_get_pdi_value -- Gets some PDI numerical parameters
pdf_get_value -- Gets certain numerical value
pdf_initgraphics -- Resets graphic state
pdf_lineto -- Draws a line
pdf_makespotcolor -- Makes a spotcolor
pdf_moveto -- Sets current point
pdf_new -- Creates a new pdf object
pdf_open -- Deprecated: Open a new pdf object
pdf_open_CCITT -- Opens a new image file with raw CCITT data
pdf_open_file -- Opens a new pdf object
pdf_open_gif -- Deprecated: Opens a GIF image
pdf_open_image -- Versatile function for images
pdf_open_image_file -- Reads an image from a file
pdf_open_jpeg -- Deprecated: Opens a JPEG image
pdf_open_memory_image -- Opens an image created with PHP's image functions
pdf_open_pdi --  Opens a PDF file
pdf_open_pdi_page --  Prepare a page
pdf_open_png --  Deprecated: Opens a PNG image
pdf_open_tiff -- Deprecated: Opens a TIFF image
pdf_place_image -- Places an image on the page
pdf_place_pdi_page -- Places an image on the page
pdf_rect -- Draws a rectangle
pdf_restore -- Restores formerly saved environment
pdf_rotate -- Sets rotation
pdf_save -- Saves the current environment
pdf_scale -- Sets scaling
pdf_set_border_color -- Sets color of border around links and annotations
pdf_set_border_dash -- Sets dash style of border around links and annotations
pdf_set_border_style -- Sets style of border around links and annotations
pdf_set_char_spacing -- Deprecated: Sets character spacing
pdf_set_duration -- Deprecated: Sets duration between pages
pdf_set_font -- Deprecated: Selects a font face and size
pdf_set_horiz_scaling -- Sets horizontal scaling of text
pdf_set_info -- Fills a field of the document information
pdf_set_info_author --  Fills the author field of the document
pdf_set_info_creator --  Fills the creator field of the document
pdf_set_info_keywords --  Fills the keywords field of the document
pdf_set_info_subject --  Fills the subject field of the document
pdf_set_info_title --  Fills the title field of the document
pdf_set_leading -- Deprecated: Sets distance between text lines
pdf_set_parameter -- Sets certain parameters
pdf_set_text_pos -- Sets text position
pdf_set_text_rendering -- Deprecated: Determines how text is rendered
pdf_set_text_rise -- Deprecated: Sets the text rise
pdf_set_text_matrix -- Deprecated: Sets the text matrix
pdf_set_value -- Sets certain numerical value
pdf_set_word_spacing -- Depriciated: Sets spacing between words
pdf_setcolor -- Sets fill and stroke color
pdf_setdash -- Sets dash pattern
pdf_setflat -- Sets flatness
pdf_setfont -- Set the current font
pdf_setgray -- Sets drawing and filling color to gray value
pdf_setgray_fill -- Sets filling color to gray value
pdf_setgray_stroke -- Sets drawing color to gray value
pdf_setlinecap -- Sets linecap parameter
pdf_setlinejoin -- Sets linejoin parameter
pdf_setlinewidth -- Sets line width
pdf_setmatrix -- Sets current transformation matrix
pdf_setmiterlimit -- Sets miter limit
pdf_setpolydash -- Sets complicated dash pattern
pdf_setrgbcolor -- Sets drawing and filling color to rgb color value
pdf_setrgbcolor_fill -- Sets filling color to rgb color value
pdf_setrgbcolor_stroke -- Sets drawing color to rgb color value
pdf_show -- Output text at current position
pdf_show_boxed -- Output text in a box
pdf_show_xy -- Output text at given position
pdf_skew -- Skews the coordinate system
pdf_stringwidth -- Returns width of text using current font
pdf_stroke -- Draws line along path
pdf_translate -- Sets origin of coordinate system
User Contributed Notes
PDF functions
add a note about notes

07-Oct-1999 12:10

My recipie:

1) untar pdflib-2.01.tar.gz
$./configure
$ make
$ make install

2) set a symlink 
$ ln -s /usr/local/lib/libpdf2.01.so /usr/local/lib/libpdf.so
You need to do this 'cause the PHP configure checks for pdflib with a
little C-program, compiling it and linking with library named libpdf (!)

2)
$ldconfig
this updates the info about dynamic library on your system (think about
the magic phrase  "Reboot  Windows "  )   ;-) 

3) go to cvs.php.net and checkout the source tree. 
You can find How-To on 

4) configure your php: 
$make 

Stop your Apache server with apachectl stop (don't forget it!!!!!)

$make install

$apachectl start
 and 
 .......... have happy time hacking with pdflib/php ! ;-> 

Luk.


10-Dec-1999 08:18

The php mailinglist reported a problem with the
installation of pdflib 2.01. The file pdf.h which is to be copied e.g.
into /usr/local/include will end up as /usr/local/include if the directory
/usr/local/include does not exist already. This is because configure of
php to fail, since it can't find pdf.h


17-Jan-2000 04:21

When pdflib2.01 is installed on a HPUX-10.20 system (perhaps others as
well?), the libs end with .sl not .so which means that you should use
"ln -s /usr/local/lib/libpdf2.01.sl /usr/local/lib/libpdf.sl"
instead!


24-Jul-2000 03:03

You need the to get the latest pdf.c file from the CVS tree:
php4/ext/pdf/pdf.c


And make sure that you have patched pdflib 3.01, or you will have problem
writing pdf to file(httpd core dumps). 


27-Jul-2000 04:28

After a couple of hours of trial and error, I've finally gotten PHP
4.0.1pl2, Apache 1.3.12, and PDF 3.01 to all work together.� Here are the
steps I followed.

Downloaded the above from the following sites:
PDFlib: www.pdflib.com
Apache: www.apache.org
PHP: www.php.net

I also downloaded the following:
PDFlib patch: 
Latest PHP pdf.c: 

After untarring the archives I did the following:
In PDF directory:
Applied PDF patch.
./configure --enable-cxx --with-tiffauxlib=-ljpeg --with-tifflib=/usr/lib
--with-zlib=/usr/lib --with-pnglib=/usr/lib --enable-shared
--enable-static --enable-shared-pdflib
make
make install

In Apache source directory:
./configure --prefix=/www/apache --with-perl=/usr/bin/perl
--enable-module=so --enable-module=rewrite
make
make install

In PHP direcotry
Copied over new pdf.c file.
./configure --with-mysql --with-apxs=/www/apache/bin/apxs
--enable-track-vars --with-zlib-dir --with-jpeg-dir=/usr/lib
--with-png-dir=/usr/lib --with-tiff-dir=/usr/lib --with-pdflib
make
make install

From there I configured httpd.conf as outlined in the PHP docs.� Hope this
helps.


05-Aug-2000 03:28

Here are a couple of other notes I made when compiling in PDF 3.x support.

The PDF patch does not work, or at least I was unable to get it to work
using 'patch'.  You have to manually make changes to the pdf file.  Simply
look at the patch file to see what line to delete and add.  Lines with a
plus in front of them should be added while lines with a minus should be
deleted.

After compiling the PDF library, make sure '/usr/local/lib' appears in
/etc/ld.so.conf.  Also, it's probably a good idea to run 'ldconfig' once
the PDF library has been compiled.

Hope this helps.


30-Aug-2000 10:38

Just FYI, I just find pdflib-3.0.1 and pdflib-3.0.2 does't work with
php-4.0.2 in my certain condition. Fortunately pdflib-3.0 does fine.

I'm runing Solaris 7 on a Sun Sparc, apache-1.3.12. DSO php-4.0.1pl2 or
php-4.0.2 works well without pdflib support. But when I install
pdflib-3.0.2, there's no DSO library made, which will cause php
configuration failed, in /usr/local/lib, nor does pdflib-3.0.1, no matter
how do I adjust the configure line parameters.

I have to back to pdflib-3.0, it works like a magic.


14-Sep-2000 08:52

For PdfLib.dll v2.01 look 

@boas.anthro.mnsu.edu
02-Oct-2000 12:53

My process to get this all working:

I use debian, so I used dselect to make sure that I had libtiff and
libjpeg.

Compile pdflib 3.02 "./configure --enabled-shared-pdflib --enable-cxx
--enable-static --enable-shared --with-tifflib=/usr/lib
--with-tiffauxlib=-ljpeg"

"make" then "make test" and "make install"

Edit /etc/ld.so.conf and include the line "/usr/local/lib"

"ln -s /usr/lib/libtiff.so.3.5.4 /usr/lib/libtiff.so"
"ln -s /usr/lib/libjpeg.so.62.0.0 /usr/lib/libjpeg.so"

"ldconfig"

Recompile PHP with "--with-pdflib"

If that doesn't work, make sure to check the last few lines of config.log
("tail -n 25 config.log") and look for errors.  Worked finally
for me with PHP 4.0.2.


16-Oct-2000 11:06

There seems to be a [known] bug in
pdflib-3.0.1 where file descriptors
are overwritten, resulting in an
apache segfault when accessing pdf
functions. The bug is documented in
the changelog of pdflib-3.0.2,
which cures this problem. (Thanks to
Jani for catching this.)


29-Oct-2000 12:36

[Editor's note: See the section "Security" in the manual for more
information on this and other security matters]

The script getpdf.php should only be used to learn the concept of passing
a file through a script and not actually used to perform this task.  In
its current state, there is a large security flaw which enables many files
(including all your php source) to be viewed by anyone.

For example 
shows the servers machines password file.


03-Nov-2000 12:24

PHPLIB (3.0.2)

after compiling and installing pdflib3.0.2, it defaults to /usr/local/lib
and creates symlinks that the ./configure of PHP doesnot want to
recognize...

Simply run :
rm /usr/local/lib/libpdf.so.1
rm /usr/local/lib/libpdf.so
mv /usr/local/lib/libpdf.so.1.0.0 /usr/local/lib/libpdf.so.1

and everything will go right : -)


04-Dec-2000 05:37

Having trouble getting MS IE to display your PDFs?

As [email protected] kindly wrote in the ClidPDF man page:

"I found out MSIE _REQUIRES_ a correctly set Content-Length header to
be sent beside Content-Type to correctly display PDFs"


10-Jan-2001 10:55

After digging around in pdf.c I found two very useful undocumented PDF
functions.

pdf_add_pdflink(int pdfdoc, double llx, double lly, double urx, double
ury, string filename, int page, string dest)
Adds link to pdf document

void pdf_add_weblink(int pdfdoc, double llx, double lly, double urx,
double ury, string url)
Adds link to web resource

enjoy them.
kill-9 
www.kill-9.dk


10-Jan-2001 11:40

Here is a short example to display PDF files without needing a
'redirection'.
Works also with IE thanks to the previous note.
Avoid spaces/newlines/whatever before and after the php script if you want
the file to be correctly handled as PDF.

Mathieu BOIS

pdftest.php :
&lt;?php
$filename="/tmp/test.pdf";
$fp=fopen($filename,"w");
//CREATE YOUR PDF FILE HERE
fclose($fp);

$fp2=fopen($filename,"r");
header("Content-Length: ".filesize($filename)); // for IE to
work
header("Content-type: application/pdf");
fpassthru($fp2);
fclose($fp2);
?>


26-Jan-2001 09:43

To get around the IE problem with content-length, you can use the output
buffering feature with PHP 4:

&lt;?php
header( "Content-type: application/pdf" );

// turn output buffering on
ob_start();
$pdf = PDF_open();

// create your pdf here.

PDF_close($pdf);

// get the length of the document
$length = ob_get_length();

// output content-length header
header("Content-Length: $length");

// send pdf to the browser, flushing and turning off output buffering
ob_end_flush();
?>

This works for me in NS 4.7 and IE 5


31-Jan-2001 02:27

just something from :
Quite Important!!!

Just to have it in the archive I am responding to myself.

I managed to get it to compile. The problem lies with the PDFlib and the
options you compile it with. I was seeing some errors in reference to
the png functions inside the PDFlib being undefined. I decided to
recompile without PNG support. (--with-pnglib=no). Even though my system
has PNGlib in /usr/local/lib. I tried it both ways and disabling the PNG
support seemed to be the way to go.

After recompiling, PHP is no longer stopped on pdf_show_boxed.

HTH somebody...

Tom Walsh

> System: BSDi 4.1
> 
> Trying to compile PHP4.0 with PDFlib support. I have downloaded the
> latest PDFlib (version 3.0) and compiled it. When I run the 
> ./configure
> script I am getting an error message on PDF_show_boxed. It is 
> telling me
> something to the effect that you must have libjpeg and libtiff
> installed.
> 
> I have compiled libtiff (v3.5.5) and libjpeg (v6). I have also
> recompiled PDFlib with the libtiff switch
> (--with-libtiff=/usr/local/lib).
> 
> I keep getting the same error message.
> 
> I have tried forcing PDFlib to look at /usr/local/lib
> (--with-pdflib=/dir) and still the same error message.
> 
> Any help is appreciated.
> 
> As an aside: I find that PDFlib function and actually all things PDF
> like to be very poorly documented.
> 
> Tom Walsh
> 
> --


09-Feb-2001 02:59

Ok, with the 3.03 version of pdflib, there's a bug in the library that
throw an error when you try to create the Pdf direct in memory using:

pdf_open();

You can fix this with the patch published in the pdflib page at:



After aplying the patch and recompiled the pdflib, you don't need to
recompile the php, just restart the webserver and you are ready to go, at
least it work for me =)
I use Linux, Apache and PHP as DSO.

Greettings and excuse my english, but it's not my mother language and is a
little late now ;-)
Ernesto Domato.


19-Feb-2001 06:52

You're trying to configure php with support for pdflib. You get the
following error: 

checking whether to include Pdflib 3.x support... yes 
checking for PDF_show_boxed in -lpdf... no 
configure: error: pdflib extension requires at least pdflib 3.x.

You may also need libtiff and libjpeg. If so, what you need is to install

libjpeg-devel-6b-10.rpm

I don't know what source tarball has those development libraries or if
it's some make option I'm not aware of in the latest jpegsrc.v6b.tar.gz

When I installed that rpm both php and apache configured and compiled
perfectly...


23-Feb-2001 10:18

I added the manually patched the file, configured with ./configure
--enable-shared-pdflib and nothing else, and used this modification of the
php page shown above:

&lt;?
header( "Content-type: application/x-pdf" );
$f = fopen("/tmp/test", "w");
$pdf = PDF_open($f);
//$pdf = PDF_new();
PDF_set_info_author($pdf, "Luca Perugini");
PDF_set_info_title($pdf, "Brochure for FlyStore");
PDF_set_info_creator($pdf, "See Author");
PDF_set_info_subject($pdf, "FlyStore");
PDF_begin_page($pdf, 595, 842);
PDF_add_outline($pdf, "Item".$data[1]);
PDF_set_font($pdf, "Helvetica-Bold" , 20, winansi);
PDF_set_text_rendering($pdf, 0);
PDF_show_xy($pdf, "OMG its a pdf on the fly!",50,780);
if (!isset($name)) {
$name = "Test Name";
}
if (!isset($age)) {
$age = "Test Age";
}
PDF_show_xy($pdf, "Your Name : $name" .$data[1], 100, 700);

PDF_show_xy($pdf, "Age : $age" .$data[2], 100, 620);

PDF_stroke($pdf);
PDF_end_page($pdf);
PDF_close($pdf);
fclose($f);
header("Content-length: " . filesize("test"));
$f = fopen("/tmp/test", "r");
fpassthru($f);
fclose($f);
?>

Only then did it work for me.


13-Mar-2001 09:49

My php compiled ok, but phpinfo() forgot about phplib. I figured out the
libtiff on my box was not the right version. Very offset, I edited
manually configure file and erase all -ltiff or replace them with bogus
-lpng. Don-t care if -lpng wa duplicate. Php works fine now, with pdflib
and without tiff support.


30-Mar-2001 12:41

Same as [email protected] only more info!!!!

(comments below are true as of 4.0.4pl1).
I kept banging my head on the "samples" that use PDF_new(). If
you check 
out the source tree comments on PDF_new(), PDF_delete(), and
PDF_open_file() and
you will see they are only available in the CVS tree.

The solution:

$fd = fopen("somefile","w"); $pdf = PDF_open($fd);
[...]
PDF_close($pdf); fclose($f);

You can't use PDF_new(), PDF_delete(), or PDF_open_file() until the
current CVS
source code tree is branched into a version release at least newer than
4.0.4pl1!


17-Apr-2001 09:10

If you still can't get your pdf files to show up in IE 5.5, here is
something I found on phpBuilder:

1. Be sure to install the SR 1 for IE 5.5 
2. Be sure your running Adobe Acrobat 4.0 (not 3.0). 
3. Open Adobe Acrobat 4.0 by itself. 
4. Click on File 
5. Click on Preferences 
6. Click on General 
7. Deselect the option to: Web Browser Integration 

That should do it. This does not correct the problem of opening the files
directly in IE, but it's a great work around....and it works.


01-May-2001 06:42

To continue on the internet explorer (Iexplorer, IE) requirements, instead
of content-length, a simple:
header("Accept-Ranges: bytes");

is enough for the getpdf.php file working right. Even Netscape will
without error with this modification.

Aurelien


01-May-2001 09:10

An FYI for anybody else looking for pdflib help.  I got php-4.0.5 and built
pdflib-4.0.0 with 

'./configure' \
'--enable-cxx' \
'--enable-shared' \
'--enable-shared-pdflib'

I did make, make install and both make and make install complained that
there is  no makefile in pdflib-4.0.0/bind/php.  It works anyway, so dont
worry bout it. 
Then in php I used --with-pdflib=/usr/local and it works, this was
performed on a FreeBSD 4.2 Release machine


06-May-2001 08:11

If you just have a look into the rep given, you'll see a nice readme.txt
saying you how to make this link working


27-May-2001 02:27

When I use
$text='<align="center"><strong>Text
text!</strong></div>
'; .... and then $num=pdf_show_boxed($pdfdoc, $text ....) I get a problem with PHP: after 30 sek. says PHP... Timiout reached. With other text (without HTML Tags) it works fine. Were is a problem here? Thanx for Answer.


27-May-2001 04:08

With php-4.0.5 and pdflib-4.0.1 there is an error in the php source code
ext/pdf/pdf.c with function pdf_close_pdi_page wanting 3 args instead of
2.

To fix, copy the section for this function from the pdflib source 
bind/php/ext/pdf/pdf.c  and then it will compile.


Section from the pdflib source reproduced below:

/* {{{ proto void pdf_close_pdi(int pdf, int doc);
 * Close all open page handles, and close the input PDF document. */
PHP_FUNCTION(pdf_close_pdi) {
        zval **arg1, **arg2;
        PDF *pdf;
 
        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1,
&arg2) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
 
        ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object",
le_pdf);
 
        convert_to_long_ex(arg2);
 
        PDF_close_pdi(pdf,
                Z_LVAL_PP(arg2)-PDFLIB_PDI_OFFSET);
 
        RETURN_TRUE;
}


12-Jun-2001 03:36

With PHP-4.0.5 and PDFLib 4.0.1 the Error that do not compile in the php
compiling..

The error function in pdf.c is no PHP_FUNCTION(pdf_close_pdi) but
PHP_FUNCTION(pdf_close_pdi_page)

patch pdf.c in php-4.0.5. Like as below

PHP_FUNCTION(pdf_close_pdi_page) {
	zval **arg1, **arg2;
	PDF *pdf;

	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1,
&arg2) == FAILURE) {
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(pdf, PDF *, arg1, -1, "pdf object",
le_pdf);

	convert_to_long_ex(arg2);

	PDF_close_pdi_page(pdf,
		Z_LVAL_PP(arg2)-PDFLIB_IMAGE_OFFSET);

	RETURN_TRUE;
}


02-Jul-2001 06:23

I'm running Apache 1.3.20+PHP 4.0.6+PDFLib 4.0.1 and the 1st example given
above doesn't seem to work.  When I try it, I get:

Fatal error: PDFlib error: function 'PDF_set_info' must not be called in
'object' scope in
/usr/local/apache/htdocs/restricted/accounting/pdftest.php on line 4

Removing the filename and replacing it with "" seems to make the
page work fine again.


04-Jul-2001 02:37

In reply to [email protected] comment about the 
"Fatal error: PDFlib error: function 'PDF_set_info' must not be
called in 'object' scope"

The reason why you get this error is because the directory you are saving
to does not have write permission.  Make sure that Apache (or whatever
webserver you are using) can actully write to your directory.


12-Jul-2001 10:33

PDFLIB 3.0 won't work with PHP 4.0.6 because this version makes use of the
"imagewarning" parameter, available only from PDFLIB version
3.01. PDFLIB 3.03 works fine for me with PHP 4.0.6.

13-Jul-2001 07:09
The demo version for windows (.dll) is purely for testing as their
enourmous watermark spanning the entire page diagnolly makes it completely
useless for anything else (that is what their liscensing suggests, I just
wanted to let everyone know in case you got comfortable with the
open-source concept.)


29-Jul-2001 02:06

To make PDFlib PDFlib 4.0.1 work under PHP 4.0.6, you need to add the file
libpdf_php.so manually to the PHP extension library (as defined in
php.ini).

The file can be downloaded from www.pdflib.com. Just add it manually after
all the compiling stuff is done.


02-Aug-2001 10:20

Try these tutorials:
************************************




************************************


02-Sep-2001 10:13

I thought the whole beauty of PHP was the fact that it is free.  So to find
out how much the PDFlib licence will cost me was quite a shock.  Is there
not a free API for building PDF documents ?

Cheers

Justing


14-Sep-2001 09:40

Hi,

yes there is a free one:



Hope that helps a bit


10-Jan-2002 11:44

You can also try  for a
completely free PDF-generating class. Not complete yet, but very
promising!


10-Feb-2002 06:21

Right from their site:
The �Aladdin Free Public License�

 In short and non-legal terms:

* you may develop free software with PDFlib, provided you make all of your
own source code publicly available
 * you may develop software for your own use with PDFlib as long as you
don't sell it
 * you may redistribute PDFlib non-commercially
 * you may redistribute PDFlib on digital media for a fee if the complete
contents of the media are freely redistributable.


05-Mar-2002 09:22

Is there a way to open a exiting pdf file  and add some text to it?


27-Mar-2002 03:56

Load extension, open a PDF, add a font, modify PDF in memory and send
it to browser:

<?php
  // no cache headers:
  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  header("Last-Modified: ".gmdate("D, d M Y
H:i:s")." GMT");
  header("Cache-Control: no-store, no-cache, must-revalidate");
  header("Cache-Control: post-check=0, pre-check=0", false);
  header("Pragma: no-cache");

  $ext_name="libpdf_php.so";
    // libpdf_php.so is the PDFLIB for SunOS by "PDFlib GmbH"
    // visit 

  // if the extension is not automatically loaded by Apache
  // dl() will try to load it on demand:
  if (!extension_loaded($ext_name) && !@dl($ext_name))
  {
    ?>
    <table width="100%"
border="0"><tr><td align="center">
      <table style="border: solid #f0f0f0 2px;"><tr>
        <td valign="middle" style="padding: 20px;
margin: 0px;">
          <p style="font-family: arial; font-size: 12px;
">
          <b>Sorry,</b>
&nbsp;
A PDF can not be generated right now.
The administrator has been informed and will fix this as soon as possible.
Please try again later.

</td></tr></table> </td></tr></table> <?php mail('[email protected]','Error: PDFLib not found', 'Called by script:\n '.$SCRIPT_FILENAME.'?'.$QUERY_STRING, "From: [email protected]\n"); exit; } // verify that extension is usable // unique serial number: srand(microtime()*10000); $usnr= gmdate("Ymd-His-").rand(1000,9999).'-'; $pdf_file=$usnr.'result.pdf'; $src_file='source.pdf'; // create pdf object $pdf = pdf_new(); pdf_open_file($pdf); pdf_set_parameter($pdf, 'serial', 'if-you-have-one'); // fonts to embed, they are in the folder of this file: pdf_set_parameter($pdf, 'FontAFM', 'TradeGothic=Tg______.afm'); pdf_set_parameter($pdf, 'FontOutline', 'TradeGothic=Tg______.pfb'); pdf_set_parameter($pdf, 'FontPFM', 'TradeGothic=Tg______.pfm'); // load the source file: $src_doc =pdf_open_pdi($pdf,$src_file,'', 0); $src_page =pdf_open_pdi_page($pdf,$src_doc,1,''); $src_width =pdf_get_pdi_value($pdf,'width' ,$src_doc,$src_page,0); $src_height=pdf_get_pdi_value($pdf,'height',$src_doc,$src_page,0); pdf_begin_page($pdf, $src_width, $src_height); { // place the sourcefile to the background of the actual page: pdf_place_pdi_page($pdf,$src_page,0,0,1,1); pdf_close_pdi_page($pdf,$src_page); // modify the page: pdf_set_font($pdf, 'TradeGothic', 8, 'host'); pdf_show_xy($pdf, 'Now: '.gmdate("Y-m-d H:i:s"),50,50); } pdf_end_page($pdf); pdf_close($pdf); // prepare output: $pdfdata = pdf_get_buffer($pdf); // to echo the pdf-data $pdfsize = strlen($pdfdata); // IE requires the datasize // real datatype headers: header('Content-type: application/pdf'); header('Content-disposition: attachment; filename="'.$pdf_file.'"'); header('Content-length: '.$pdfsize); echo $pdfdata; exit; // keep this one so no #13#10 or #32 will be written ?>


06-May-2002 09:22

If you're wondering how to highlight words inside a PDF file, take a look
at this script I've written (doesn't need PDFLib)



It's a whole lot harder than you think. (Rarely has no much code been
written that does so little, that's what I say :-) Worth looking at if you
want to do searches inside a PDF.


07-Jun-2002 07:11

Well it's nice to have a PDF function under PHP, but for several problems
PDFlib is useless. Here my problem I need a solution that create a PDF
file after I've had transformed a XML file with XSLT to XSL-FO. Executing
Apache-FOP with the "system" Command is not quite well.
Therefore I need to create a seperate channel to create PDFs. The
usability for transforming XML with XSLT in this case is poor. For
standealone project this lib could be quite usefull, but for XSLT
transforming I think a C++-dll-wrapper for XSL-FO->PDF after
XML->XSLT->XSL-FO is more usefull. Or what do you think about it?


11-Jun-2002 09:23

Hope it can help someone:

	$pdf = pdf_new();
	//pdf_open_file($pdf,"");
	if (!pdf_open_file($pdf, "")) {
			print error;
			exit;	
	}
	

             PDF_set_parameter($pdf, "resourcefile",
"/usr/local/pdflib/fonts/pdflib.upr");
	PDF_set_parameter($pdf,"prefix","/usr/local/pdflib/fonts");

	pdf_begin_page($pdf, 595, 842);
	pdf_add_outline($pdf, "Page 1");

	//pdf_set_font($pdf, "Times-Roman", 30, "host");
             // set chinese characters,
	$font = pdf_findfont($pdf, "MHei-Medium",
"B5pc-H",0);
	if ($font) {
		pdf_setfont($pdf, $font, 30);
	}	

	pdf_set_value($pdf, "textrendering",0);
	pdf_show_xy($pdf, "���� 100 Roman outlined", 50, 750);

	pdf_set_font($pdf, "Times-Roman", 30, "host");
	pdf_show_xy($pdf, "���� Times Roman outlined", 50, 600);
	pdf_moveto($pdf, 50, 740);
	pdf_lineto($pdf, 330, 740);
	pdf_stroke($pdf);
	pdf_end_page($pdf);
	pdf_close($pdf);

	$buf = pdf_get_buffer($pdf);
	$len = strlen($buf);

	header("Content-type: application/pdf");
	header("Content-Length: $len");
	header("Content-Disposition: inline; filename=foo.pdf");
	print $buf;

	pdf_delete($pdf);


02-Jul-2002 01:02

Hi Guys

How can you encrypt a pdf document so that it is write protected.  You can
read it, but can't make modifications to the file, except if you have the
password.

Apparently this is a new feature that was added in Adobe Acrobat 5.0.

Thx

add a note about notes
previousoverloadpdf_add_annotationnext
Last updated: Tue, 28 May 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sat Jul 6 04:18:21 2002 CEST