Feng Forum

Support => How To's => : wmcheung February 18, 2011, 06:41:50 AM

: Export CSV and PDF Problem in Reporting
: wmcheung February 18, 2011, 06:41:50 AM
In Reporting section, I try to load the report and export it. There are two export functions - Export to CSV  and Export to PDF.

I did try to export both functions in different browsers. The results are listed below:

===================================================================
Web BrowserExport to CSVExport to PDF
IE 8No response
No response
Google ChromeCSV file is extracted
No response
Mozilla FirefoxCSV file is extracted
No response

===================================================================

Anyone know how to fix this export function?

: Re: Export CSV and PDF Problem in Reporting
: franponce87 February 21, 2011, 01:49:52 PM
In Google Chrome and Mozilla Firefox (and most browsers), when you hit the 'Export to PDF' button, you should notice a new button below, on the left, which says 'Export'.. This has been made on purpose as this way you may select some more PDF settings.

Regarding the issues with IE8, those are another tale.. We are aware of them and we might fix them for a future version, but for the time being we are focusing on other things which we consider more important.

Should you want and be able to fix them, please let us know and we will be happy to add your fix to the application.

Best regards,
Francisco
: Re: Export CSV and PDF Problem in Reporting
: wmcheung February 21, 2011, 10:41:01 PM
Hi franponce87,

I did know there is another 'Export' button. When I click on it, it did try loading sth. then nothing happen in Google Chrome and Mozilla Firefox.

For IE 8, after clicking the 'Export' button, it will load another page and it will call the print dialog to prompt.

I did make change to a file called <feng_install>/language/en_us/lang.js. As I got an error shown in the tab before in one of the browsers mentioned. But I can't remember which browser show the error.

I add a line
'_download' : 'Download file',

However, this just makes the error not display again, still no PDF file to prompt for saving.
: Re: Export CSV and PDF Problem in Reporting
: franponce87 February 23, 2011, 11:00:51 AM
This is odd, I do not have such problem (except for IE8). Which FO version are you using? 1.7.3.1?

Best regards,
Francisco
: Re: Export CSV and PDF Problem in Reporting
: wmcheung February 25, 2011, 12:32:58 AM
Yes, I'm using FO 1.7.3.1. The following environments also are not working to export the PDF file.

I have installed the html to pdf plugin, will this affect?

Under Windows 7:
Chrome Version 9.0.597.98
Mozilla Firefox Version 3.6.13

Under Fedora 14:
Mozilla Firefox Version 3.6.10
: Re: Export CSV and PDF Problem in Reporting
: franponce87 February 25, 2011, 09:59:53 AM
I have exactly the same versions of Chrome and Firefox.. but I do not have that problem.
You ought to check out the log.php file and look for the errors there which may lead you to a proper solution.

Best regards,
Francisco
: Re: Export CSV and PDF Problem in Reporting
: wmcheung March 09, 2011, 04:48:13 AM
I did try again to test on IE8

I found that I can export the csv file

For IE7, when I click on 'Export to CSV', the page will reload and then prompt the Print dialog. If I click on 'Export to PDF', the page will reload to show Page Layout option and a 'Export' button. Clicking on 'Export' button, the Print dialog prompt.

As I have installed CutePDF, thus, I try to choose CutePDF to export the PDF file. I have attached the pdf file output. The layout of the PDF is just a web page layout, and didn't apply the Layout setting I set before.

For Chrome, do the same test. CSV file can be exported but still no response when clicking on 'Export' button.
: Re: Export CSV and PDF Problem in Reporting
: wmcheung March 09, 2011, 04:51:02 AM
hi franponce87,

I found the following error in log.php

ERROR: Error: String functions are overloaded by mbstring in '/srv/www/htdocs/feng/library/utf8/utf8.php' on line 39 (error code: 256)

ERROR: Error: iconv(): Detected an illegal character in input string in '/srv/www/htdocs/feng/application/controllers/ReportingController.class.php' on line 936 (error code: 8)

ERROR: Error: Undefined variable: genid in '/srv/www/htdocs/feng/application/views/reporting/view_custom_report.php' on line 123 (error code: 8)


any suggestion?
: Re: Export CSV and PDF Problem in Reporting
: wmcheung March 09, 2011, 07:28:43 AM

ERROR: Error: String functions are overloaded by mbstring in '/srv/www/htdocs/feng/library/utf8/utf8.php' on line 39 (error code: 256)
I can resolve this error by updating php.ini
:
[mstring]
mbstring.internal_encoding = UTF-8
mbstring.func_overload = 0

ERROR: Error: Undefined variable: genid in '/srv/www/htdocs/feng/application/views/reporting/view_custom_report.php' on line 123 (
This error I have tried to update <FengOffice install>/application/views/reporting/view_custom_report.php
:
function format_value_to_print($col, $value, $type, $obj_type, $textWrapper='', $dateformat='Y-m-d', $genid='')Add $genid='' at the end of the function to avoid undefined variable error.

Now, I can use chrome to export PDF, however, the format has some problem.
Please see the attachment.

Is it possible to resolve?
: Re: Export CSV and PDF Problem in Reporting
: franponce87 March 11, 2011, 11:21:22 AM
About this error:
ERROR: Error: iconv(): Detected an illegal character in input string in '/srv/www/htdocs/feng/application/controllers/ReportingController.class.php' on line 936 (error code: 8)

Have you fixed this by updating mbstring library?

Regarding the PDF, it is as though as a couple of documents in there have a weird name (with enters? or special chars may be?) and that is why it has so many line breaks. Could you please report it in the Mantis Bug Tracker, taking into account this detail?

Thanks for your feedback! Looking forward to knowing your answer regarding the iconv() error.

Best regards,
Francisco

: Re: Export CSV and PDF Problem in Reporting
: wmcheung March 14, 2011, 04:13:00 AM
hi Francisco,

this problem is not fixed yet.

Some files contain Chinese characters, it is no problem to view those file name in Feng Office UI, however, the exported PDF cannot display those Chiese characters and change them to '?'.

I wonder whether it is related to the encoding and font use.
I check in the file <fengoffice>application/controllers/ReportingController.class.php

I found that
:
$pdf->SetFont('Arial', '', $fontsize);
Whether 'Arial' supports Chinese characters?

:
$cell = iconv(mb_internal_encoding(), "ISO-8859-1", html_entity_decode($cell, ENT_COMPAT));
For the encoding, whether 'ISO-8859-1' supports Chinese characters?



: Re: Export CSV and PDF Problem in Reporting
: franponce87 March 14, 2011, 01:05:39 PM
Actually that is a good question. I do not use Chinese characters at all so I honestly have no idea if they are supported or not. If you could investigate a bit more on this issue and try fixing, we would patch the fix for a future release.

Best regards,
Francisco
: Re: Export CSV and PDF Problem in Reporting
: foefldev March 09, 2012, 09:53:22 AM
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();
}
: Re: Export CSV and PDF Problem in Reporting
: johncartom March 17, 2012, 03:43:47 AM
i think you can wait for some time or someting problem in Interent Explorar....
: Re: Export CSV and PDF Problem in Reporting
: andrewscott132 March 18, 2012, 03:43:46 AM
I did know there is another 'Export' option. When I press on it, it did try running sth. then nothing occur in The search engines Firefox and Mozilla Firefox.

For IE 8, after pressing the 'Export' option, it will fill another web page and it will call the list dialogue to immediate.

I did make modify to a computer file known as <feng_install>/language/en_us/lang.js. As I got one proven in the tab before in one of the surfers described. But I can't keep in mind which technique display the mistake.
: Re: Export CSV and PDF Problem in Reporting
: adamlevine76 March 24, 2012, 04:09:40 AM
I did know there is another 'Export' option. When I press on it, it did try running sth. then nothing occur in The search engines Firefox and Mozilla Firefox.

For IE 8, after pressing the 'Export' option, it will fill another web page and it will contact the list dialogue to immediate.

I did create modify to a computer file known as <feng_install>/language/en_us/lang.js. As I got one proven in the tab before in one of the surfers described. But I can't keep in mind which technique display the mistake.
: Re: Export CSV and PDF Problem in Reporting
: rachelmcadams591 April 01, 2012, 06:47:24 AM
I did know there is another 'Export' option. When I press on it, it did try running sth. then nothing occur in The search engines Firefox and Mozilla Firefox.

For IE 8, after pressing the 'Export' option, it will fill another web page and it will contact the list dialogue to immediate.

I did create modify to a computer file known as <feng_install>/language/en_us/lang.js. As I got one proven in the tab before in one of the surfers described. But I can't keep in mind which technique display the mistake.