By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,666 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,666 IT Pros & Developers. It's quick & easy.

FPDF Header Problem

P: n/a
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_FONTPATH','font/');
require('fpdf.php');

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,'Header Output',1,1,'C');
//Line break
$this->Ln(20);
}
}
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Times','',10);
$pdf->Cell(40,40,"Test Output");
$pdf->Output();
?>
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


Phillip T. Murphy wrote:
Not sure if this is the correct forum, but since FPDF is a PHP script, I
thought I would give it a try...
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.....
$pdf=new FPDF();

You need:

$pdf->Open();

here
$pdf->AddPage();
$pdf->SetFont('Times','',10);
$pdf->Cell(40,40,"Test Output");
$pdf->Output();
?>


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
***

Jul 17 '05 #2

P: n/a
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
$pdf=new FPDF();

You need:

$pdf->Open();

here
$pdf->AddPage();
$pdf->SetFont('Times','',10);
$pdf->Cell(40,40,"Test Output");
$pdf->Output();
?>


Jul 17 '05 #3

P: n/a

"Al C." <no*************@adams-blake.no.spam.com> wrote in message
news:10*************@news20.forteinc.com...
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


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
Jul 17 '05 #4

P: n/a
Phillip T. Murphy wrote:

"Al C." <no*************@adams-blake.no.spam.com> wrote in message
news:10*************@news20.forteinc.com...
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


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


See:
http://fpdf.org/en/tutorial/tuto2.htm

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.

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.