sayedsohail Posted August 16, 2007 Share Posted August 16, 2007 Hi everyone, when i run this script, it say 'Metrics data for font 'Arial' not found', i don't know what's wrong in the code. Please help. The code found at (tutorial) http://www.devarticles.com/c/a/PHP/Use-PHP-to-Create-Dynamic-pdf-Files/1/. <?php $user = $HTTP_POST_VARS["userName"]; $pdf = pdf_new(); pdf_open_file($pdf, "C:\bennyboy.pdf"); pdf_set_info($pdf, "Author", "Ben Shepherd"); pdf_set_info($pdf, "Title", "Creating a pdf"); pdf_set_info($pdf, "Creator", "Ben Shepherd"); pdf_set_info($pdf, "Subject", "Creating a pdf"); pdf_begin_page($pdf, 595, 842); $arial = pdf_findfont($pdf, "Arial", "host", 1); pdf_setfont($pdf, $arial, 14); pdf_show_xy($pdf, "Hello Tinka",50, 400); $gif_image = pdf_open_gif($pdf, "../images/delete.gif"); pdf_place_image($pdf, $gif_image, 200, 300, 1.0); pdf_close_image($pdf, $gif_image); pdf_end_page($pdf); pdf_close($pdf); echo "<A HREF=\"C:\bennyboy.pdf\" TARGET=\"_blank\">Open pdf in a new window $user</A>" ?> Quote Link to comment https://forums.phpfreaks.com/topic/65300-simple-pdf-generation-from-php/ Share on other sites More sharing options...
sayedsohail Posted August 17, 2007 Author Share Posted August 17, 2007 anyone? ??? Quote Link to comment https://forums.phpfreaks.com/topic/65300-simple-pdf-generation-from-php/#findComment-326506 Share on other sites More sharing options...
Silverado_NL Posted August 17, 2007 Share Posted August 17, 2007 [code][code] Hi sayedsohail even though i never have used php to generate PDF file's, i might have an idea what your error is. i think you are missing the Font file that php uses to write those PDF files. you are using the C: path so i figured you are using Windows OS. you probely have to look for a Arial.ttf file in the c:/windows/fonts directory. if its not there, download it from somewhere, place it in the windows/fonts dir and restart your webserver. if that dont work, maybe you can try another Font style? some look alot like Arial, and some ARE arial, just named differently. try replacing the fonttype with ArialUnicode $arial = pdf_findfont($pdf, "Arial", "host", 1); pdf_setfont($pdf, $arial, 14); Will Be $font = pdf_findfont($pdf, "ArialUnicode ", "ArialUnicode ", 1); pdf_setfont($pdf, $font, 14); hope this helps. Silverado[/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/65300-simple-pdf-generation-from-php/#findComment-326510 Share on other sites More sharing options...
sayedsohail Posted August 17, 2007 Author Share Posted August 17, 2007 i copied the font file from windows directory inside the php files directory. still the same here is the errro: Fatal error: Uncaught exception 'PDFlibException' with message 'Metrics data for font 'Arial' not found' in C:\Program Files\xampp\htdocs\pdf\tutorial\tuto8.php:12 Stack trace: #0 C:\Program Files\xampp\htdocs\pdf\tutorial\tuto8.php(12): pdf_findfont(Resource id #2, 'Arial', 'host', 1) #1 {main} thrown in C:\Program Files\xampp\htdocs\pdf\tutorial\tuto8.php on line 12 Quote Link to comment https://forums.phpfreaks.com/topic/65300-simple-pdf-generation-from-php/#findComment-326733 Share on other sites More sharing options...
tippy_102 Posted August 18, 2007 Share Posted August 18, 2007 What happens if you try using one of the internal PDFlib fonts such as "Courier" or "Helvetica" ? Quote Link to comment https://forums.phpfreaks.com/topic/65300-simple-pdf-generation-from-php/#findComment-327292 Share on other sites More sharing options...
sayedsohail Posted August 18, 2007 Author Share Posted August 18, 2007 everything is solved when i started using ezpdf class, it works for me but i got a small problem, when writting pdfs to the disk, i wish to prompt if the file already exist, at the moment with this code, it just overwritting the existing file. if ($fp = fopen( "$temp_dir" . $fname . '.pdf', 'wb' )) { fwrite( $fp, $pdf->ezOutput() ); fclose( $fp ); echo "<HTML><SCRIPT>document.location='$file';</SCRIPT></HTML>"; } else { echo "Could not open file to save PDF. "; if (!is_writable( $temp_dir )) { "The files/temp directory is not writable. Check your file system permissions."; } } Quote Link to comment https://forums.phpfreaks.com/topic/65300-simple-pdf-generation-from-php/#findComment-327396 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.