Ulug'bek
Ulug'bek

Reputation: 2832

Generate PDF file in my web app by using php

I want to generate a PDF file in my web app. I am using php and I tried fpdf library I tried to create pdf by using following code:

<?php
require('fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Привет мир!');
$pdf->Output();
?>

It works when we use english characters inside file, but file encoding is ANSI and inside writen russian characters I get that error:

enter image description here

if I change file encoding to utf-8 get error:

FPDF error: Some data has already been output, can't send PDF file (output started at Z:\home\fpdf\www\tutorial\tuto1.php:1)

Who knows how to resolve the problem, please help me !

Upvotes: 1

Views: 435

Answers (1)

Taher
Taher

Reputation: 12040

$pdf->Cell(40,10, iconv('UTF-8', 'CP-1251', $str) );

Make sure you're saving your document as UTF8

Upvotes: 1

Related Questions