0

I was trying to create PDF file using Tcpdf engine and CakePDF plugin.

It works ok, but I don't have Polish characters - despite of setting coding to UTF-8.

This is my function for creating PDF and sending it as response object:-

public function create_pdf($id=null)
{
    $this->request->allowMethod(['post', 'create_pdf']);
    $CakePdf = new \CakePdf\Pdf\CakePdf();
    $billboard = $this->Billboards->get($id,['contain' => ['Clients','Photos']]);
    $CakePdf->viewVars(array('billboard' => $billboard));

    $CakePdf->template('create_pdf');
    $CakePdf->encoding('UTF-8');
    $pdf = $CakePdf->output();
    $this->response->body($pdf);
    $this->response->type('pdf');
    $this->response->download('tomart_billboard_'.$id.'.pdf');
    return $this->response;
}

Here is my configuration of CakePDF plugin:-

Configure::write('CakePdf', [
    'engine' => 'CakePdf.Tcpdf',
    'margin' => [
        'bottom' => 15,
        'left' => 0,
        'right' => 0,
        'top' => 0
    ],
    'orientation' => 'landscape',
    'download' => true
]);

Template create_pdf.ctp has encoding set to UTF-8 as well.

In place of Polish characters I have "?" character.

I'm using latest version of Tcpdf, CakePDF and CakePHP 3.

drmonkeyninja
  • 8,490
  • 4
  • 31
  • 59
GamaPL
  • 97
  • 1
  • 2
  • 11
  • Maybe the used font for PDF creation doesn't contain accents or doesn't support all required characters, have you checked that or tried to configure TCPDF to use another font? – Oops D'oh Aug 07 '15 at 21:27
  • Thanks for tip, but it doesnt work - still there are "???" characters instead of Polish letter in generated PDF. I've checked database - it is set to UTF-8 mode, also variable with data string is detected as UTF-8 string. Now i really dont know what to do. – GamaPL Aug 10 '15 at 06:45
  • 1
    Maybe there is a useful answer [here](http://stackoverflow.com/questions/5333702/tcpdf-utf-8-lithuanian-symbols-not-showing-up) already? – Oops D'oh Aug 11 '15 at 00:00
  • Thanks! Changing font to dejavusans resolved my problem. One more time - big thanks! – GamaPL Aug 12 '15 at 06:50

0 Answers0