shamuntoha Posted October 10, 2008 Share Posted October 10, 2008 I have a php code running, i can create pdf file with text informations for the moment only. But how can i embed a A4 background image gif, jpg, etc. And in front of the background apply the following text ? Any reference? <?php /* * This is an example of my first PDF test * Worked by NuSphere PHPed * Manualy downloaded library from * http://pecl4win.php.net/ext.php/php_pdf.dll */ /* * Stage - 1 * Resource create for PDF library */ $pdf = PDF_new(); /* * Stage - 2 * Save where? Path to create the file. */ pdf_open_file($pdf, "d:\heloworld.pdf"); /* * Stage - 3 * Page diemention (A4) */ pdf_begin_page($pdf, 595, 842); /* * Stage - 4 * path of your TTF font directory * can also use pdf_load_font(); * http://uk3.php.net/manual/en/function.pdf-findfont.php */ $fontdir = "C:\WINDOWS\Fonts"; pdf_set_parameter($pdf, "FontOutline", "arialMyName=$fontdir\arial.ttf"); $arial = PDF_findfont($pdf,"arialMyName","host",0 ); /* * Stage - 5 * Set font size and font name */ pdf_setfont($pdf, $arial, 10); /* * Stage - 6 * print text */ pdf_show_xy($pdf, "Hellow World? ",50, 750); pdf_show_xy($pdf, "Test 1, 2, 3, 4 working. ", 50,730); /* * Stage - 7 * end page */ pdf_end_page($pdf); /* * Stage - 8 * close and save file */ pdf_close($pdf); ?> Quote Link to comment Share on other sites More sharing options...
shamuntoha Posted October 10, 2008 Author Share Posted October 10, 2008 Attached the file example. Background image with logo and table borders shape, and Black lines are database values. How we do this ? [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
shamuntoha Posted October 10, 2008 Author Share Posted October 10, 2008 Any idea how to fix it? $image is having the problem. PHP: 5.0.3: Fatal error: Uncaught exception 'PDFlibException' with message 'Handle parameter 'image' has bad value 0' in C:\Inetpub\wwwroot\tst.php:35 Stack trace: #0 C:\Inetpub\wwwroot\tst.php(35): pdf_fit_image(Resource id #2, 0, 10, 10, 'scale 0.5') #1 {main} thrown in C:\Inetpub\wwwroot\tst.php on line 35 Code: if (($image = PDF_load_image($pdf, "jpeg", "C:\Inetpub\wwwroot\img\addcallback.JPG", 0)) == -1) { fprintf(stderr,"Error: Couldn't read image file.\n"); } else { PDF_fit_image($pdf, $image, 10, 10, "scale 0.5"); PDF_close_image($pdf, $image); } Quote Link to comment Share on other sites More sharing options...
shamuntoha Posted October 10, 2008 Author Share Posted October 10, 2008 Where should be the fatal error ? C/C++ Manual Function prototype: int PDF_load_image(PDF *p, const char *imagetype, const char *filename, int reserved, const char *optlist) void PDF_fit_image(PDF *p, int im, float x, float y, const char *optlist) void PDF_close_image(PDF *p, int image) PHP Trying : //PDF *p; $pdf = PDF_new(); $image = PDF_load_image($pdf, "jpeg", "c:\picture.jpg", 0); PDF_fit_image($pdf, $image, 1.5, 1.5, "scale 0.5"); PDF_close_image($pdf, $image); Quote Link to comment Share on other sites More sharing options...
shamuntoha Posted October 10, 2008 Author Share Posted October 10, 2008 Working with this: http://www.fpdf.org/ Great job.... 1. GD enable. 2. php_pdf.dll and following code.... <?php require('../fpdf.php'); class PDF extends FPDF { //Page header function Header() { //Logo $this->Image('logo_pb.png',10,8,300, 500); //Arial bold 15 $this->SetFont('Arial','B',15); //Move to the right $this->Cell(80); //Title $this->Cell(30,10,'Title',1,0,'C'); //Line break $this->Ln(20); } //Page footer function Footer() { //Position at 1.5 cm from bottom $this->SetY(-15); //Arial italic 8 $this->SetFont('Arial','I',; //Page number $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); } } //Instanciation of inherited class $pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); $pdf->SetFont('Times','',12); for($i=1;$i<=40;$i++) $pdf->Cell(0,10,'Printing line number '.$i,0,1); $pdf->Output(); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.