Skip to content

Export FAQs

Export FAQs

Q) How to export japanese multibyte characters (??? shown) ?

You need to change font of export for that.

Goto jqgrid_dist.php, Search for line

$pdf->SetFont('helvetica', '', 14);

and replace it with

$pdf->SetFont('cid0jp', '', 14);

For DejavuSans UTF8 font, following these steps:

1. Download the fonts archive (tcpdf_fonts_6_0_099.zip) from `http://sourceforge.net/projects/tcpdf/files/`
2. Extract the fonts in lib/inc/tcpdf/fonts
3. Set font in jqgrid_dist.php

$pdf->SetFont('dejavusans', '', 14, '', true);

For RTL languages text, html renderer must also be used along with rtl font.

$opt["export"]["render_type"] = "html";

In case of missing font, contact me back for updated lib.

^ Top

Q) How to override default PDF settings ?

You can use on_render_pdf event handler to get TCPDF object, and change settings accordingly. For e.g. to change font,

$e["on_render_pdf"] = array("set_pdf_format", null);
$g->set_events($e);

function set_pdf_format($arr)
{
    $pdf = $arr["pdf"];
    $data = $arr["data"];
    $pdf->SetFont('dejavusans', '', 10);
    $pdf->SetLineWidth(0.1);
}

^ Top

Q) Getting error on PDF export, "TCPDF ERROR: Some data has already been output, can't send PDF file"

There are usually 2 reasons for this.

1) Blank space character at start of grid file (new line etc) 2) Invisible BOM character at start of file

In case #1 will give header already sent error. #2 will push all data as html text.

White spaces can be removed by checking top and end of all included files. To remove invisible BOM character, i would recommend Notepad++ -> Open file -> Encoding menu -> Encode UTF without BOM

^ Top

Q) How to use custom export method (external-file) ?

You can use on_export event, to do your custom export working. An example is given below

// params are array(<function-name>,<class-object> or <null-if-global-func>,<continue-default-operation>)
$e["on_export"] = array("custom_export", NULL, false);
$g->set_events($e);

// custom on_export callback function. Set all useful data in session for custom export code file
function custom_export($param)
{
    $sql = $param["sql"]; // the SQL statement for export
    $grid = $param["grid"]; // the complete grid object reference

    if ($grid->options["export"]["format"] == "xls")
    {
        $_SESSION["phpgrid_sql"]=$sql;
        $_SESSION["phpgrid_filename"]=$grid->options["export"]["filename"];
        $_SESSION["phpgrid_heading"]=$grid->options["export"]["heading"];

        $cols_skip = array();
        $titles = array();

        foreach ($grid->options["colModel"] as $c)
        {
            if ($c["export"] === false)
                $cols_skip[] = $c["name"];

            $titles[$c["index"]] = $c["title"];
        }

        $_SESSION["phpgrid_cols_skip"]=serialize($cols_skip);
        $_SESSION["phpgrid_cols_title"]=serialize($titles);

        header("Location: my-export.php");
        die();
    }
}

In that redirected file (my-export.php), you can use all session variable to fetch data from DB and export as desired.

^ Top

Goto file 'lib/inc/tcpdf/class.easytable.php', at end of file, there are 2 empty function header() and footer(). You can put image and text there using TCPDF lib sample code: http://www.tcpdf.org/examples/example_003.phps

^ Top

Q) How to show Logo on exported PDF ?

You can check TCPDF documentation and modify class 'lib/inc/tcpdf/class.easytable.php', go to end of file, Have header function empty, You can put image and text. In similar way, one can put footer.

Also check this forum post.

^ Top

Q) How to show searched string as heading in PDF ?

$e["on_export"] = array("set_header", null,true);
$g->set_events($e);

function set_header($d)
{
    // search params
    $search_str = $d["grid"]->strip($_SESSION['jqgrid_filter_request']);
    $search_arr = json_decode($search_str,true);
    $gopr = $search_arr['groupOp'];
    $rule = $search_arr['rules'][0];

    if (!empty($rule["data"]))
        $d["grid"]->options["export"]["heading"] = $rule["data"];
}

^ Top

Q) How to can i resolve: Class 'ZipArchive' not found?

On blank export and on checking error_log if you see "PHP Fatal error: Class 'ZipArchive' not found in /home/user/public_html/phpgrid/lib/inc/excel/PHPExcel/Writer/Excel2007.php on line 225"

There are 2 options for fix.

First is it to install zip php extension that is required by phpexcel library. Other one is to rename 'PHPExcel' folder in /lib/inc/excel/ with '_PHPExcel'

If this path is not found, our system uses older excel exporting library which might work without zip extension.

^ Top