FPDF Header Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phillip T. Murphy

    FPDF Header Problem

    Not sure if this is the correct forum, but since FPDF is a PHP script, I
    thought I would give it a try...

    I am having a problem getting ANYTHING to print in a header using the FPDF
    functions. I can get text to go into the main body of the PDF file, but
    nothing into a header. I have messed with this for several hours, seached
    the web and no luck. Any help would be greatly appreciated.

    Here is my script - which prints "Test Output" in a PDF file with no header
    at all. Any suggestions?

    <?php
    define('FPDF_FO NTPATH','font/');
    require('fpdf.p hp');

    class PDF extends FPDF
    {
    //Page header
    function Header()
    {
    //Arial bold 15
    $this->SetFont('Arial ','B',15);
    //Move to the right
    $this->Cell(80);
    //Title
    $this->Cell(30,10,'He ader Output',1,1,'C' );
    //Line break
    $this->Ln(20);
    }
    }


    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Times ','',10);
    $pdf->Cell(40,40,"Te st Output");
    $pdf->Output();
    ?>


  • Al C.

    #2
    Re: FPDF Header Problem



    Phillip T. Murphy wrote:
    [color=blue]
    > Not sure if this is the correct forum, but since FPDF is a PHP script, I
    > thought I would give it a try...[/color]

    You really should post this on the Forum page of fpdf.org. They have a great
    group of peope there and Oliver (author) of PDF is also there all the time.

    Anyway.....


    [color=blue]
    > $pdf=new FPDF();[/color]


    You need:

    $pdf->Open();

    here
    [color=blue]
    > $pdf->AddPage();
    > $pdf->SetFont('Times ','',10);
    > $pdf->Cell(40,40,"Te st Output");
    > $pdf->Output();
    > ?>[/color]

    For our Jaya123 web-system (www.jaya123.com) I've written tens of thousands of
    lines of code using the FPDF class so I know a few things.
    Hope this helps.

    Al C.
    _______________ _______________ _______________ _____________
    Adams-Blake Company, Inc.
    ***
    JAYA123 - the web-based total-office system for the
    small biz. Order entry, billing, bookkeeping, etc. for $14.95
    a month. Perfect for the small business or start-up.
    See demo at: http://www.jaya123.com
    ***

    Comment

    • Al C.

      #3
      Re: FPDF Header Problem - correction

      ooops, Previous answer is not it as you don't need Open(). Your problem is
      that you need:

      $pdf=new PDF();

      Leave off the "F". By using the "F" you are instantiating a new FPDF class.
      However PDF (no F) EXTENDS the FPDF and has a function with YOUR header
      stuff. The FPDF header is actually empty and expects to be overriden. When
      you just do $pdf=new FPDF(); you don't get the extension but only an empy
      header function.

      -Al


      [color=blue][color=green]
      >> $pdf=new FPDF();[/color]
      >
      >
      > You need:
      >
      > $pdf->Open();
      >
      > here
      >[color=green]
      >> $pdf->AddPage();
      >> $pdf->SetFont('Times ','',10);
      >> $pdf->Cell(40,40,"Te st Output");
      >> $pdf->Output();
      >> ?>[/color][/color]

      Comment

      • Phillip T. Murphy

        #4
        Re: FPDF Header Problem - correction


        "Al C." <no.spam.acanto n@adams-blake.no.spam.c om> wrote in message
        news:10n3tudrga l0ta9@news20.fo rteinc.com...[color=blue]
        > ooops, Previous answer is not it as you don't need Open(). Your problem is
        > that you need:
        >
        > $pdf=new PDF();
        >
        > Leave off the "F". By using the "F" you are instantiating a new FPDF
        > class.
        > However PDF (no F) EXTENDS the FPDF and has a function with YOUR header
        > stuff. The FPDF header is actually empty and expects to be overriden. When
        > you just do $pdf=new FPDF(); you don't get the extension but only an empy
        > header function.
        >
        > -Al[/color]

        Al, Thank you! Wow, I am not sure I would have figured that out on my own,
        ever. As a matter of of fact, I don't see any mention of what you pointed
        out in the documentation anywhere.

        Thanks again!

        Phillip


        Comment

        • Al C.

          #5
          Re: FPDF Header Problem - correction

          Phillip T. Murphy wrote:
          [color=blue]
          >
          > "Al C." <no.spam.acanto n@adams-blake.no.spam.c om> wrote in message
          > news:10n3tudrga l0ta9@news20.fo rteinc.com...[color=green]
          >> ooops, Previous answer is not it as you don't need Open(). Your problem is
          >> that you need:
          >>
          >> $pdf=new PDF();
          >>
          >> Leave off the "F". By using the "F" you are instantiating a new FPDF
          >> class.
          >> However PDF (no F) EXTENDS the FPDF and has a function with YOUR header
          >> stuff. The FPDF header is actually empty and expects to be overriden. When
          >> you just do $pdf=new FPDF(); you don't get the extension but only an empy
          >> header function.
          >>
          >> -Al[/color]
          >
          > Al, Thank you! Wow, I am not sure I would have figured that out on my own,
          > ever. As a matter of of fact, I don't see any mention of what you pointed
          > out in the documentation anywhere.
          >
          > Thanks again!
          >
          > Phillip[/color]

          See:


          This example makes use of the Header() and Footer() methods to process page
          headers and footers. They are called automatically. They already exist in the
          FPDF class but do nothing, therefore we have to extend the class and override
          them.

          Comment

          Working...