0

I am using FPDF with PHP Barcode for creating a PDF-attached mail from form with the below code:

  // -------------------------------------------------- //
  //                      USEFUL
  // -------------------------------------------------- //
    class eFPDF extends FPDF{
    function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0)
    {
        $font_angle+=90+$txt_angle;
        $txt_angle*=M_PI/180;
        $font_angle*=M_PI/180;

        $txt_dx=cos($txt_angle);
        $txt_dy=sin($txt_angle);
        $font_dx=cos($font_angle);
        $font_dy=sin($font_angle);

        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',$txt_dx,$txt_dy,$font_dx,$font_dy,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
        if ($this->ColorFlag)
            $s='q '.$this->TextColor.' '.$s.' Q';
        $this->_out($s);
    }
  }


  // -------------------------------------------------- //
  //                  PROPERTIES
  // -------------------------------------------------- //

  $fontSize = 10;
  $marge    = 10;   // between barcode and hri in pixel
  $x        = 430;  // barcode center
  $y        = 660;  // barcode center
  $height   = 25;   // barcode height in 1D ; module size in 2D
  $width    = 1;    // barcode height in 1D ; not use in 2D
  $angle    = 0;   // rotation in degrees

  $code     = ''.$_POST['barcode'].''; // barcode, of course ;)
  $type     = 'code128';
  $black    = '000000'; // color in hexa


  // -------------------------------------------------- //
  //            ALLOCATE FPDF RESSOURCE
  // -------------------------------------------------- //

  $pdf = new eFPDF('P', 'pt');
  $pdf->AddPage();
  $pdf->Image('e-invitation-gr.jpg',0,0,600);



  // -------------------------------------------------- //
  //                      BARCODE
  // -------------------------------------------------- //

  $data = Barcode::fpdf($pdf, $black, $x, $y, $angle, $type, array('code'=>$code), $width, $height);

  // -------------------------------------------------- //
  //                      HRI
  // -------------------------------------------------- //

  $pdf->SetFont('Arial','B',$fontSize);
  $pdf->SetTextColor(0, 0, 0);
  $len = $pdf->GetStringWidth($data['hri']);
  Barcode::rotate(-$len / 2, ($data['height'] / 2) + $fontSize + $marge, $angle, $xt, $yt);
  $pdf->TextWithRotation($x + $xt, $y + $yt, $data['hri'], $angle);
  $pdf->SetY(610);
$pdf->SetX(370);
$txt=''.$_POST['surname'].'  '.$_POST['name'].'';
$field = iconv('UTF-8', 'cp1252', $txt);
  $pdf->Cell(0,0,$field);
 $pdf->SetY(630);
$pdf->SetX(390);
  $pdf->Cell(0,0,''.$_POST['company_name'].'');


// email stuff (change data below)
$company_name =$_REQUEST['company_name'];
$surname =$_REQUEST['surname'];
$mail =$_REQUEST['mail'];
$email =$_REQUEST['mail'];
$name= $_REQUEST['name'];

I have tested all the possible solutions but iconv doesn't work at all and UTF8 decode shows ???? characters.

Is there anyway to make it with FPDF or should I change plugin?

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
  • i have also tried iconv('UTF-8', 'windows-1252', html_entity_decode($str)); but nothing shows on pdf mail – aristeidhsP Sep 10 '16 at 22:59
  • The problem is solved by using tFPDF (a branch of FPDF) and having a font WITH the language character range you need (i.e., WindowsHelvetica.ttf does not have Chinese). Greek, however, should be auto-supported by tFPDF. Take a look at my answer here: https://stackoverflow.com/a/56429391/2430549 – HoldOffHunger Jun 04 '19 at 16:42

2 Answers2

1

Forget fpdf and turn to tfpdf to get the solution. From latest fpdf document about font. It supports charators as below
cp1250 (Central Europe)
cp1251 (Cyrillic)
cp1252 (Western Europe)
cp1253 (Greek)
cp1254 (Turkish)
cp1255 (Hebrew)
cp1257 (Baltic)
cp1258 (Vietnamese)
cp874 (Thai)
ISO-8859-1 (Western Europe)
ISO-8859-2 (Central Europe)
ISO-8859-4 (Baltic)
ISO-8859-5 (Cyrillic)
ISO-8859-7 (Greek)
ISO-8859-9 (Turkish)
ISO-8859-11 (Thai)
ISO-8859-15 (Western Europe)
ISO-8859-16 (Central Europe)
KOI8-R (Russian)
KOI8-U (Ukrainian).

Robert
  • 63
  • 9
0

This may help:

class PDF extends FPDF {

    function Cell( $w, $h = 0, $t = '', $b = 0, $l = 0, $a = '', $f = false, $y = '' ) {

        parent::Cell( $w, $h, iconv( 'UTF-8', 'windows-1252', $t ), $b, $l, $a, $f, $y );

    }

}
GDY
  • 2,872
  • 1
  • 24
  • 44