?
Solved

Urgent help for pdf

Posted on 2005-04-18
3
Medium Priority
?
658 Views
Last Modified: 2008-01-09
I am trying to open a pdf. I downloaded fpdf class from a site and tried to do the first tutorial but getting the following mistakes:

Warning: setfont(helveticab.php): failed to open stream: No such file or directory in /home/dsgmotor/public_html/FPDF153/fpdf.php on line 550

Warning: setfont(helveticab.php): failed to open stream: No such file or directory in /home/dsgmotor/public_html/FPDF153/fpdf.php on line 550

Warning: setfont(): Failed opening 'helveticab.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/dsgmotor/public_html/FPDF153/fpdf.php on line 550
FPDF error: Could not include font metric file

The code i have is just as follows:

<?php
require('/home/dsgmotor/public_html/FPDF153/fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

Maybe its the path?
0
Comment
Question by:act1ve
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
Promethyl earned 2000 total points
ID: 13808386
Verify /home/dsgmotor/public_html/FPDF153/font/helveticab.php exists.

Then make sure it is world readable/executable...  chmod 0555 the php files in the font folder. If apache is nobody and file is owned by somebody (presumbably DSGMotors) then the file might not be found on this basis.

Other that that, your invocation seems correct.

Related functions; pardon me, "methods".

function _getfontpath()
{
      if(!defined('FPDF_FONTPATH') && is_dir(dirname(__FILE__).'/font'))
            define('FPDF_FONTPATH',dirname(__FILE__).'/font/');
      return defined('FPDF_FONTPATH') ? FPDF_FONTPATH : '';
}

function SetFont($family,$style='',$size=0)
{
      //Select a font; size given in points
      global $fpdf_charwidths;

      $family=strtolower($family);
      if($family=='')
            $family=$this->FontFamily;
      if($family=='arial')
            $family='helvetica';
      elseif($family=='symbol' || $family=='zapfdingbats')
            $style='';
      $style=strtoupper($style);
      if(strpos($style,'U')!==false)
      {
            $this->underline=true;
            $style=str_replace('U','',$style);
      }
      else
            $this->underline=false;
      if($style=='IB')
            $style='BI';
      if($size==0)
            $size=$this->FontSizePt;
      //Test if font is already selected
      if($this->FontFamily==$family && $this->FontStyle==$style && $this->FontSizePt==$size)
            return;
      //Test if used for the first time
      $fontkey=$family.$style;
      if(!isset($this->fonts[$fontkey]))
      {
            //Check if one of the standard fonts
            if(isset($this->CoreFonts[$fontkey]))
            {
                  if(!isset($fpdf_charwidths[$fontkey]))
                  {
                        //Load metric file
                        $file=$family;
                        if($family=='times' || $family=='helvetica')
                              $file.=strtolower($style);
                        include($this->_getfontpath().$file.'.php');
                        if(!isset($fpdf_charwidths[$fontkey]))
                              $this->Error('Could not include font metric file');
                  }
                  $i=count($this->fonts)+1;
                  $this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]);
            }
            else
                  $this->Error('Undefined font: '.$family.' '.$style);
      }
      //Select it
      $this->FontFamily=$family;
      $this->FontStyle=$style;
      $this->FontSizePt=$size;
      $this->FontSize=$size/$this->k;
      $this->CurrentFont=&$this->fonts[$fontkey];
      if($this->page>0)
            $this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}

0
 
LVL 6

Expert Comment

by:alextr2003fr
ID: 13809169
From the documentation : (install.txt)
Metric files can be accessed from three different locations:
- the directory defined by the FPDF_FONTPATH constant (if this constant is defined)
- the font directory located in the directory containing fpdf.php (as it is the case in this archive)
- the directories accessible through include()
Here is an example defining FPDF_FONTPATH (note the mandatory final slash):
define('FPDF_FONTPATH','/home/www/font/');
require('fpdf.php');
If the files are not accessible, the SetFont() method will produce the following error:
FPDF error: Could not include font metric file

maybe you should move the file helveticab.php in same directory where your fpdf.php is? for instance
try to copy helveticab.php in /home/dsgmotor/public_html/FPDF153/ folder
0
 
LVL 7

Expert Comment

by:Promethyl
ID: 13816476
What was the problem?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question