TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Create pdf (http://www.talkphp.com/advanced-php-programming/4937-create-pdf.html)

dhaval 09-11-2009 10:21 AM

Create pdf
 
Hi friends,

I am trying to create pdf through php
even i've done all the step which is necessary
before to create pdf file through php
below is my code for creating

$user=$HTTP_POST_VARS['userName'];
$pdf=pdf_new();
pdf_open_file($pdf,'F:\Program Files\xampp\htdocs\Dhaval\Dhaval.pdf');
pdf_set_info($pdf,"Author",'Dhaval');
pdf_set_info($pdf,'Title','All Rounder');
pdf_set_info($pdf,'All Rounder','Dhaval');
pdf_set_info($pdf,'subject','Success');
pdf_begin_page($pdf,595,842);
$arial=pdf_findfont($pdf,'Arial','host',1);
pdf_setfont($pdf,$arial,14);
$jpg_image=pdf_open_jpeg($pdf,'chess-en.jpg');
pdf_place_image($pdf,$jpg_image,200,300,1.0);
pdf_close_image($pdf,$jpg_image);
pdf_end_page($pdf);
pdf_close($pdf);
echo "<a href='F:\Program Files\xampp\htdocs\Dhaval\Dhaval.pdf'>Open PDF in new window</a>";

but it shows below error

Fatal error: Uncaught exception 'PDFlibException' with message 'Metrics data for font 'Arial' not found' in F:\Program Files\xampp\htdocs\Dhaval\pdf_file.php:10 Stack trace: #0 F:\Program Files\xampp\htdocs\Dhaval\pdf_file.php(10): pdf_findfont(Resource id #2, 'Arial', 'host', 1) #1 {main} thrown in F:\Program Files\xampp\htdocs\Dhaval\pdf_file.php on line 10

so please help me to solve it.

Randy 09-11-2009 02:12 PM

Now i am not the best coder myself so I may be wrong if so somebody else please correct me but im going to do my best here.

Looking at the error its the font that is missing meaning that the script is unable to find the fonts that you listed here:

PHP Code:

$arial=pdf_findfont($pdf,'Arial','host',1); 

For font be sure to have something included like this:

PHP Code:

// Locate Font Directory
$fontdir "C:\WINDOWS\Fonts";
// Font Name Parameters
pdf_set_parameter($pdf"FontOutline""arialMyName=$fontdir\arial.ttf");
// Find Font
$arial PDF_findfont($pdf,"arialMyName","host",);
// Set font size and font name
pdf_setfont($pdf$arial10); 

Note: Credit for my given code goes to the php manual located here.

Cheers,
Randy

dhaval 09-11-2009 02:33 PM

Hi,
First of all Thanks for your help
actually exactly what I want to do is
make pdf of FCKeditor's value
well now made pdf but how to get FCKeditor's
value and make its pdf
so, please help me to fix it out.

Thanks in advance

Randy 09-11-2009 03:34 PM

Glad that part helped there and for the getting FCKeditor to work should be quite simple.

To do that you just take your FCKeditor form field set the name of it set the form to GET or POST which ever you prefer, create a variable with it and then use the pdf_show command.

Something like this.
Note: this is quick it would be easier to help with your fckeditor code

Top of the page that your form goes to (what the action="" goes to)
PHP Code:

$text $_GET['fckeditor_field']; 

Then for when you create the pdf something like this should work.

PHP Code:

pdf_show($pdf$text); 

or if you want there is the pdf_show_xy
PHP Code:

pdf_show_xy($pdf$textXLOCYLOC); 

basically that one lets you define locations for using the x and y axis numbers.

Hope that helps, if not just post your code and im sure me or some other members can help.

dhaval 09-12-2009 06:36 AM

Hi,
Thanks again for your valuable reply
with your help the problem has been solved :)
but still something remains i want to put image also
in pdf but it doesn't show.
what to do?

Randy 09-12-2009 07:17 AM

to do that basically do the same as with fckeditor, create the variable (same command in the other post simply change the name of the field and variable name as image)

and use the following:

PHP Code:

pdf_fit_image($pdf$image$x$y); 

here is what each does, note i did not include the string.
Quote:

pdf_fit_image(resource, int, float-x, float-y, string)
string basically lets you modify the image such as string etc..

Read the manual at the following link if you want some help with the string, that is not my cup of tea.
http://us3.php.net/manual/en/function.pdf-fit-image.php

Glad to be helping :D

dhaval 09-12-2009 08:34 AM

hi,
it doesn't work yar
i think it can't get the right path
cause when i tried to echo image it doesn's show
and fatal error comes like below

Fatal error: Uncaught exception 'PDFlibException' with message 'pdf_fit_image() expects parameter 2 to be long, string given' in F:\Program Files\xampp\htdocs\Dhaval\cpdf1.php:62 Stack trace: #0 F:\Program Files\xampp\htdocs\Dhaval\cpdf1.php(62): pdf_fit_image(Resource id #2, 'F:\Program Files\xampp\htdocs\Dhaval\cpdf1.php on line 62

:(

dhaval 09-12-2009 08:37 AM

if you don't mind, may i have your gmail ID so we can chat and i can show you exactly what i did

Randy 09-12-2009 06:19 PM

I have sent you a pm with my gmail id.

Randy 09-12-2009 07:06 PM

Alright, in my pm said i'd be busy all day which is true but im taking a break right now and found out what you have to do.

you have to use the pdf_open_image_file first to open the image file then you use the pdf_fit_image.

PHP Code:

pdf_open_image_file($pdf$imagetype$filename$string$intparam); 

variables are defined in order below:
resource, imagetype (gif, jpg, png, etc..), name of image, string type, int

can't really explain much cause you basiccaly just stick that in between the information given above as far as i can tell, plus i have never input an image im running with the php manual.

pcsimke 09-20-2010 10:57 AM

$slika = pdf_load_image($pdf,"gif","D:\\xampp\\htdocs\\teli me.gif","");


path needs to look somthing like this D:\\xampp\\htdocs\\telime.gif


note the \\

this worked for me


All times are GMT. The time now is 02:26 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0