Hi,
It might be too long after last message on this discussion but I thought it might be usefull to somebody else.
I am using FengOffice 1.7.5 and tried to produce PDF reports with Greek characters: all the Greek characters were missing from the PDF file.
It seems that the problem lies in application/controllers/ReportingController.class.php and the function generatePDFReport($report, $results). In version 1.7.5 lines 963, 1005 and 1028 look like:
$YYYY = iconv(mb_internal_encoding(), "ISO-8859-1", html_entity_decode($XXXX, ENT_COMPAT));
.
At situations like this it is really usefull to add a line like:
Logger::log("INTERNAL ENCODING = " . mb_internal_encoding(),Logger::INFO);
after one of those lines, produce a PDF report and check the output in cache/log.php (check for lines marked with INFO). In my case it confirmed that I use UTF-8 and what lines did was to convert UTF-8 to ISO-8859-1 which is not really what one would like to do for Greek or Chinese.
After some investigation i figured out that the implementation of generatePDFReport($report, $results) is non-UTF-8 for a good reason: the PDF library shipped with FengOffice is NOT a UTF-8 compatible library. There is a UTF-8 alternative version tfpdf. It is easy to use it since you simply have to download it to the libraries folder and edit the function generatePDFReport($report, $results):
$pdf = new tFPDF();
and
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',$fontSize);
In my case this solution did not work since the font definition files (e.g.
library/tfpdf/font/unifont/dejavusans.cw.dat
library/tfpdf/font/unifont/dejavusans.mtx.php)
are generated on the fly for the first time and I was getting problems I could not bother to resolve.
I decided to use the TCPDF library which seems to have a better Unicode support (well, I have seen it on other php based systems and at first I tried to cheat using its font definitions with TFPDF but this seemed more complicated than switching to TCPDF).
The solution is relatively simple:
1. Unzip the library downloaded from in the libraries folder
2. Change the function generatePDFReport($report, $results)
function generatePDFReport($report, $results){
$types = self::get_report_column_types($report->getId());
eval('$managerInstance = ' . $report->getObjectType() . "::instance();");
$externalCols = $managerInstance->getExternalColumns();
$filename = str_replace(' ', '_',$report->getName()).date('_YmdHis');
$pageLayout = $_POST['pdfPageLayout'];
$fontSize = $_POST['pdfFontSize'];
include_once(LIBRARY_PATH . '/tcpdf/config/lang/eng.php');
include_once(LIBRARY_PATH . '/tcpdf/tcpdf.php');
$pdf = new TCPDF($pageLayout, 'mm', 'A4', true, 'UTF-8', false);
$pdf->setTitle($report->getName());
$pdf->SetFont('dejavusans','',$fontSize);
$pdf->AddPage();
$pdf->Cell(80);
$report_title = html_entity_decode($report->getName(), ENT_COMPAT);
$pdf->Cell(30, 10, $report_title);
$pdf->Ln(20);
$colSizes = array();
$maxValue = array();
$fixed_col_sizes = array();
foreach($results['rows'] as $row) {
$i = 0;
foreach($row as $k => $value){
if(!isset($maxValue[$i])) $maxValue[$i] = '';
if ($k == 't.state'){
$value = ($value != '') ? lang('completed') : lang('open task status');
}
if(strlen(strip_tags($value)) > strlen($maxValue[$i])){
$maxValue[$i] = strip_tags($value);
}
$i++;
}
}
$k=0;
foreach ($maxValue as $str) {
$col_title_len = $pdf->GetStringWidth($results['columns'][$k]);
//file_put_contents('log.txt', ' tit:'.$results['columns'][$k], FILE_APPEND);
$colMaxTextSize = max($pdf->GetStringWidth($str), $col_title_len);
$db_col = $results['columns'][$k];
$colType = array_var($types, array_var($results['db_columns'], $db_col, ''), '');
if($colType == DATA_TYPE_DATETIME && !($report->getObjectType() == 'ProjectEvents' && $results['db_columns'][$db_col] == 'start')){
$colMaxTextSize = $colMaxTextSize / 2;
if ($colMaxTextSize < $col_title_len) $colMaxTextSize = $col_title_len;
}
$fixed_col_sizes[$k] = $colMaxTextSize;
$k++;
}
$fixed_col_sizes = self::fix_column_widths(($pageLayout=='P'?172:260), $fixed_col_sizes);
$max_char_len = array();
$i = 0;
foreach($results['columns'] as $col){
$colMaxTextSize = $fixed_col_sizes[$i];
$colFontSize = $colMaxTextSize + 5;
$colSizes[$i] = $colFontSize ;
$col_name = html_entity_decode($col, ENT_COMPAT);
$pdf->Cell($colFontSize, 7, $col_name);
$max_char_len[$i] = self::get_max_length_from_pdfsize($pdf, $colFontSize);
$i++;
}
$lastColX = $pdf->GetX();
$pdf->Ln();
$pdf->Line($pdf->GetX(), $pdf->GetY(), $lastColX, $pdf->GetY());
foreach($results['rows'] as $row) {
$i = 0;
$more_lines = array();
$col_offsets = array();
foreach($row as $k => $value){
if($k == 'link'){
$value = strip_tags($value);
$cell = $value;
}else{
$cell = $this->format_value_to_print($k, $value, $types[$k], $report->getObjectType());
}
if($report->getObjectType() == 'ProjectTasks' && $k == 't.state'){
$cell = ($cell != '--') ? lang('completed') : lang('open task status');
}
$cell = html_entity_decode($cell, ENT_COMPAT);
$splitted = self::split_column_value($cell, $max_char_len[$i]);
$cell = $splitted[0];
if (count($splitted) > 1) {
array_shift($splitted);
$ml = 0;
foreach ($splitted as $sp_val) {
if (!isset($more_lines[$ml]) || !is_array($more_lines[$ml])) $more_lines[$ml] = array();
$more_lines[$ml][$i] = $sp_val;
$ml++;
}
$col_offsets[$i] = $pdf->x;
}
$pdf->Cell($colSizes[$i],7,$cell);
$i++;
}
foreach ($more_lines as $ml_values) {
$pdf->Ln();
foreach ($ml_values as $col_idx => $col_val) {
$pdf->SetX($col_offsets[$col_idx]);
$pdf->Cell($colSizes[$col_idx],7,$col_val);
}
}
$pdf->Ln();
$pdf->SetDrawColor(220, 220, 220);
$pdf->Line($pdf->GetX(), $pdf->GetY(), $lastColX, $pdf->GetY());
$pdf->SetDrawColor(0, 0, 0);
}
$filename = ROOT."/tmp/".gen_id().".pdf";
$pdf->Output($filename, "F");
download_file($filename, "application/pdf", $report->getName(), true);
unlink($filename);
die();
}