Skip to content

Instantly share code, notes, and snippets.

@Nakira
Last active February 4, 2020 16:26
Show Gist options
  • Save Nakira/c395084fc3105420fa0691e2b0b81cfa to your computer and use it in GitHub Desktop.
Save Nakira/c395084fc3105420fa0691e2b0b81cfa to your computer and use it in GitHub Desktop.
interletter.php
<?php
require('interletter.php');
$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',9);
$pdf->Cell(85,4,"EXAMPLE OF FUNCTION USAGE",1,1,'C');
$pdf->Write(4,"\nSource: http://www.swg-fr.com\n\n");
$text=file_get_contents('ex.txt');
$pdf->Interletter(0.5, 'custom interlettering', 100, 100, 1, 1, 'C');
$pdf->Output();
<?php
require('fpdf.php');
class PDF extends FPDF
{
function Interletter($interletter, $textLine, $w, $h, $x, $y, $align)
{
$ecart = $interletter;
$lineWidth = 0.0;
foreach (str_split($textLine) as $letter) {
$lineWidth += $this->GetStringWidth($letter);
}
$lineWidth += (strlen($textLine) - 1) * $ecart;
$computexX = $x;//default is L
if ($align == 'R') {
$computexX = $x + ($w - $lineWidth);
} else if ($align == 'C') {
$computexX = $x + (($w / 2) - ($lineWidth / 2));
}
$this->SetXY($computexX, $y);
$this->_out(sprintf('%.3F Tc', $ecart * $this->k));
$this->Cell($w, $h, $textLine, 0, 0, 'L');
$this->_out('BT 0 Tc ET');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment