export image

Questionsexport image
afif asked 9 years ago

hi abu, i have problem to export image. excel and pdf file just showing image link, instead picture. thx…

6 Answers
Abu Ghufran answered 9 years ago

Images in export format is not supported.
You can have your custom export logic and page.
Refer demos/export/export-custom.php

kim answered 9 years ago

is it possible to provide exporting as PDF EXCEL and CSV in one grid toolbar simultaneously? I am able to display the icon(text) buttons on the toolbar,
but only one function will work when clicking on each one.
"export" => true,
"export_excel" => true, // export excel button
"export_pdf" => true, // export pdf button
"export_csv" => true // export csv button

$grid["export"] = array("format" => "pdf", "filename" => "PDF Contracts", "heading" => "Test PDF Export", "range" => "filtered", "orientation" => "landscape", "paper" => "a4");
$grid["export"] = array("format" => "xsls", "filename" => "EXCEL Contracts", "heading" => "Test EXCEL Export", "sheetname" => "Contracts in EXCEL", "range" => "filtered");
$grid["export"] = array("format" => "csv", "filename" => "CSV Contracts", "heading" => "Test CSV Export", "range" => "filtered");

$e["on_render_pdf"] = array("set_pdf_format", null); //export as pdf file
$e["on_render_xls"] = array("set_xls_format", null); //export as excel file
$e["on_render_csv"] = array("set_csv_format", null); //export as csv file

function set_pdf_format($arr) {//function to PRINT PDF
$pdf = $arr["pdf"];
$data = $arr["data"];
$pdf->SetFont('helvetica', '', 8);
$pdf->SetCellWidths(array(10, 15, 10, 16, 12, 18, 15, 12, 20, 16, 20, 22, 16, 20, 18, 12, 10, 'auto'));
function set_xls_format($arr) {
$pdf = $arr["xls"];
$data = $arr["data"];

function set_csv_format($arr) {
$pdf = $arr["csv"];
$data = $arr["data"];

Abu Ghufran answered 9 years ago

For exporting multiple format, you only set general parameters in grid options.

$grid["export"] = array("filename"=>"my-file", "heading"=>"Export Test", "range" => "filtered");

And override the filename/headings in on_export callback handler.

$e["on_export"] = array("custom_export", null, false);

// custom on_export callback function
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"] == "excel")
$grid->options["export"]["filename"] = 'XLS-Contracts';
$grid->options["export"]["heading"] = 'Test XLS Contracts';


Sample code available here: http://pastebin.com/iDn8PUuj

Massimo Gagliardi answered 9 years ago

To export an image with PDF I did in this mode:
1. I modified the "class.TCPDF.EasyTable" adding those 2 lines:

if (strpos($cellData, 'jpg') > 0 || strpos($cellData, 'png') > 0)
$cellData = new PDFImage(substr($cellData, strrpos($cellData, '/') + 1), substr($cellData, 0, strrpos($cellData, '/') + 1));

after this existing line (รท line number 333):
$cellWidth = $this->_GetCellWidth($cellIndex); // get the cell width

2. in the table the image must be recorded with pathname/imagename.jpg (or .png) (the pathname can be relative or absolute)

Massimo Gagliardi

Abu Ghufran answered 9 years ago

Thanks Massimo for the solution.

For step1, Better position of PDFImage will be at line 70, in function constructor. This will also resolve the rowHeight issue.
Code snippet: http://hastebin.com/kisejocodu.php

Massimo Gagliardi answered 9 years ago

I done.
Thank you very much for the suggestion.

Your Answer

1 + 18 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?