<?php
require
(
'fpdf/fpdf.php'
);
class
PDF
extends
FPDF {
function
Header() {
global
$title
;
$this
->SetFont(
'Arial'
,
'B'
, 15);
$w
=
$this
->GetStringWidth(
$title
) + 6;
$this
->SetX((210 -
$w
) / 2);
$this
->SetDrawColor(0, 80, 180);
$this
->SetFillColor(105, 105, 105);
$this
->SetTextColor(255, 0, 0);
$this
->SetLineWidth(1);
$this
->Cell(
$w
, 9,
$title
, 1, 1,
'C'
, 1);
$this
->Ln(10);
}
function
Footer() {
$this
->SetY(-20);
$this
->SetFont(
'Arial'
,
'I'
, 10);
$this
->SetTextColor(128);
$this
->Cell(0, 10,
'Page '
.
$this
->PageNo(), 0, 0,
'C'
);
}
function
tutorialTitle(
$num
,
$label
) {
$this
->SetFont(
'Arial'
,
''
, 12);
$this
->SetFillColor(211, 211, 211);
$this
->Cell(0, 6,
"Chapter $num : $label"
, 0, 1,
'L'
, 1);
$this
->Ln(4);
}
function
tutorialContent(
$file
) {
$f
=
fopen
(
$file
,
'r'
);
$txt
=
fread
(
$f
,
filesize
(
$file
));
fclose(
$f
);
$this
->SetFont(
'Times'
,
''
, 12);
$this
->MultiCell(0, 5,
$txt
);
$this
->Ln();
$this
->SetFont(
''
,
'I'
);
$this
->Cell(0, 5,
'(end of content)'
);
}
function
showTutorial(
$num
,
$title
,
$file
) {
$this
->AddPage();
$this
->tutorialTitle(
$num
,
$title
);
$this
->tutorialContent(
$file
);
}
}
$pdf
=
new
PDF();
$title
=
'C Programming Language'
;
$pdf
->SetTitle(
$title
);
$pdf
->SetAuthor(
'gfg author name'
);
$pdf
->showTutorial(
1,
'C Language Introduction'
,
'cIntro.txt'
);
$pdf
->showTutorial(
2,
'C Programming Language Standard'
,
'cStandard.txt'
);
$pdf
->showTutorial(
3,
'Importance of function prototype in C'
,
'cPrototype.txt'
);
$pdf
->Output();
?>