Trouble w/ cpdf Images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrmachoman
Forum Newbie
Posts: 5
Joined: Sat Jan 22, 2005 6:36 pm

Trouble w/ cpdf Images

Post by mrmachoman »

OS: XP
PHP: v5.022
Serv: Apache 1.3

Somebody please help. Im trying to get PHP to create images in a pdf document. Im new to the cpdf set of commands so I'm not sure if Im doing something wrong. I can create the PDF with text and generate graphics, however when I try to bring in an image (e.g. png,jpg) It will not display. The two commands Im having problems with are
cpdf_place_inline_image - which gives me an error of Call to undefined function cpdf_place_inline_image()
and
cpdf_import_jpeg - which does not display an image at all in the PDF. However all other pieces of the PDF display correctly.

All other aspects work correctly. After hours of research my only guess is that I need to build PHP w/ gd. I am currently running gd2 but cannot find Windows dll for the older versions (i.e. 1.3 or 1.8) for testing. I am also creating images "on the fly" so I need gd2 support and supposedly gd and gd2 are not compatible.

Here is a sample of the code I'm using. The text and line display but the image does not.

Code: Select all

<?php
$file="test.jpg";
$cpdf = cpdf_open(0);
cpdf_page_init($cpdf, 1, 0, 792, 612, 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_import_jpeg($cpdf,$file,10,10,0,0,0,0,0,1);
cpdf_finalize_page($cpdf, 1);
cpdf_finalize($cpdf);
Header("Content-type: application/pdf");
cpdf_output_buffer($cpdf);
cpdf_close($cpdf);
?>
Notes: Yes the image is in the same directory. As I understand this code works on Linux but not Win-doze.
Post Reply