<?php
require('fpdf.php');
class PDF extends FPDF
{
function subWrite($h, $txt, $link='', $subFontSize=12, $subOffset=0)
{
// resize font
$subFontSizeold = $this->FontSizePt;
$this->SetFontSize($subFontSize);
// reposition y
$subOffset = ((($subFontSize - $subFontSizeold) / $this->k) * 0.3) + ($subOffset / $this->k);
$subX = $this->x;
$subY = $this->y;
$this->SetXY($subX, $subY - $subOffset);
//Output text
$this->Write($h, $txt, $link);
// restore y position
$subX = $this->x;
$subY = $this->y;
$this->SetXY($subX, $subY + $subOffset);
// restore font size
$this->SetFontSize($subFontSizeold);
}
}
?>
<?php
require('subwrite.php');
$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->Write(5,'Hello World!');
$pdf->SetX(100);
$pdf->Write(5,"This is standard text.\n");
$pdf->Ln(12);
$pdf->subWrite(10,'H','',33);
$pdf->Write(10,'ello World!');
$pdf->SetX(100);
$pdf->Write(10,"This is text with a capital first letter.\n");
$pdf->Ln(12);
$pdf->subWrite(5,'Y','',6);
$pdf->Write(5,'ou can also begin the sentence with a small letter. And word wrap also works if the line is too long!');
$pdf->SetX(100);
$pdf->Write(5,"This is text with a small first letter.\n");
$pdf->Ln(12);
$pdf->Write(5,'The world has a lot of km');
$pdf->subWrite(5,'2','',6,4);
$pdf->SetX(100);
$pdf->Write(5,"This is text with a superscripted letter.\n");
$pdf->Ln(12);
$pdf->Write(5,'The world has a lot of H');
$pdf->subWrite(5,'2','',6,-3);
$pdf->Write(5,'O');
$pdf->SetX(100);
$pdf->Write(5,"This is text with a subscripted letter.\n");
$pdf->Output();
?>
View the result