Jump to content

Recommended Posts

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>" 
?> 

Link to comment
https://forums.phpfreaks.com/topic/65300-simple-pdf-generation-from-php/
Share on other sites

[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]

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

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.";
        }
    }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.