Skip to content

Commit cf5f6f8

Browse files
committed
Adds the print expression in Image
1 parent 47bf478 commit cf5f6f8

File tree

2 files changed

+45
-39
lines changed

2 files changed

+45
-39
lines changed

src/Image.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function generate($obj = null)
3232
//$data->hyperlinkReferenceExpression=$this->analyse_expression($data->hyperlinkReferenceExpression);
3333
$data->hyperlinkReferenceExpression=trim(str_replace(array('"',''),"",$data->hyperlinkReferenceExpression));
3434
// echo $text;
35+
$printWhenExpression = $obj->get_expression($data->reportElement->printWhenExpression, $row);
3536

3637
$arraydata = [
3738
"type" => "Image",
@@ -45,7 +46,8 @@ public function generate($obj = null)
4546
"hidden_type" => "image",
4647
"linktarget" => $data["hyperlinkTarget"] . "",
4748
"border" => 0,
48-
"fitbox" => false
49+
"fitbox" => false,
50+
"printWhenExpression" => $printWhenExpression . "",
4951
];
5052
if (isset($data->box)) {
5153
$arraydata["border"] = StaticText::formatBox($data->box);

src/PdfProcessor.php

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function resetY_axis($arraydata) {
9797
}
9898

9999
public function SetY_axis($arraydata) {
100-
if ((JasperPHP\Instructions::$y_axis + (int) $arraydata['y_axis']) <= JasperPHP\Instructions::$arrayPageSetting["pageHeight"]) {
100+
if ((JasperPHP\Instructions::$y_axis + (int)$arraydata['y_axis']) <= JasperPHP\Instructions::$arrayPageSetting["pageHeight"]) {
101101
JasperPHP\Instructions::$y_axis = JasperPHP\Instructions::$y_axis + (int)$arraydata['y_axis'];
102102
}
103103
}
@@ -214,43 +214,47 @@ public function Ellipse($arraydata) {
214214

215215
public function Image($arraydata) {
216216
//echo $arraydata["path"];
217-
$path = $arraydata["path"];
218-
$imgtype = mb_substr($path, -3);
219-
$arraydata["link"] = $arraydata["link"] . "";
220-
if ($imgtype == 'jpg')
221-
$imgtype = "JPEG";
222-
elseif ($imgtype == 'png' || $imgtype == 'PNG')
223-
$imgtype = "PNG";
224-
// echo $path;
225-
$imagePath = str_replace(array('"','\\','/'),array('',DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR) ,$path);
226-
//not full patch?
227-
if (!file_exists($imagePath)) {
228-
$imagePath = getcwd().DIRECTORY_SEPARATOR.$imagePath;
229-
}
230-
if (file_exists($imagePath)) {
231-
232-
//echo $imagePath;
233-
//exit;
234-
JasperPHP\Instructions::$objOutPut->Image($imagePath, $arraydata["x"] + JasperPHP\Instructions::$arrayPageSetting["leftMargin"], $arraydata["y"] + JasperPHP\Instructions::$y_axis, $arraydata["width"], $arraydata["height"], $imgtype, $arraydata["link"], '', false, 300, '', false, false, $arraydata["border"] , $arraydata["fitbox"]);
235-
}elseif( mb_substr($path, 0, 4) == 'http'){
236-
// echo $path;
237-
///exit;
238-
JasperPHP\Instructions::$objOutPut->Image($path, $arraydata["x"] + JasperPHP\Instructions::$arrayPageSetting["leftMargin"], $arraydata["y"] + JasperPHP\Instructions::$y_axis, $arraydata["width"], $arraydata["height"], $imgtype, $arraydata["link"], '', false, 300, '', false, false, $arraydata["border"] , $arraydata["fitbox"]);
239-
} elseif (mb_substr($path, 0, 21) == "data:image/jpg;base64") {
240-
$imgtype = "JPEG";
241-
//echo $path;
242-
$img = str_replace('data:image/jpg;base64,', '', $path);
243-
$imgdata = base64_decode($img);
244-
JasperPHP\Instructions::$objOutPut->Image('@' . $imgdata, $arraydata["x"] + JasperPHP\Instructions::$arrayPageSetting["leftMargin"], $arraydata["y"] + JasperPHP\Instructions::$y_axis, $arraydata["width"], $arraydata["height"], '', '' , '', false, 300, '', false, false, $arraydata["border"] ,$arraydata["fitbox"]);
245-
} elseif (mb_substr($path, 0, 22) == "data:image/png;base64,") {
246-
$imgtype = "PNG";
247-
// JasperPHP\Pdf::$pdfOutPut->setImageScale(PDF_IMAGE_SCALE_RATIO);
248-
249-
$img = str_replace('data:image/png;base64,', '', $path);
250-
$imgdata = base64_decode($img);
251-
252-
253-
JasperPHP\Instructions::$objOutPut->Image('@' . $imgdata, $arraydata["x"] + JasperPHP\Instructions::$arrayPageSetting["leftMargin"], $arraydata["y"] + JasperPHP\Instructions::$y_axis, $arraydata["width"], $arraydata["height"], '', $arraydata["link"], '', false, 300, '', false, false, 0 ,$arraydata["fitbox"]);
217+
$this->print_expression($arraydata);
218+
if ($this->print_expression_result == true) {
219+
220+
$path = $arraydata["path"];
221+
$imgtype = mb_substr($path, -3);
222+
$arraydata["link"] = $arraydata["link"] . "";
223+
if ($imgtype == 'jpg')
224+
$imgtype = "JPEG";
225+
elseif ($imgtype == 'png' || $imgtype == 'PNG')
226+
$imgtype = "PNG";
227+
// echo $path;
228+
$imagePath = str_replace(array('"', '\\', '/'), array('', DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $path);
229+
//not full patch?
230+
if (!file_exists($imagePath)) {
231+
$imagePath = getcwd() . DIRECTORY_SEPARATOR . $imagePath;
232+
}
233+
if (file_exists($imagePath)) {
234+
235+
//echo $imagePath;
236+
//exit;
237+
JasperPHP\Instructions::$objOutPut->Image($imagePath, $arraydata["x"] + JasperPHP\Instructions::$arrayPageSetting["leftMargin"], $arraydata["y"] + JasperPHP\Instructions::$y_axis, $arraydata["width"], $arraydata["height"], $imgtype, $arraydata["link"], '', false, 300, '', false, false, $arraydata["border"], $arraydata["fitbox"]);
238+
} elseif (mb_substr($path, 0, 4) == 'http') {
239+
// echo $path;
240+
///exit;
241+
JasperPHP\Instructions::$objOutPut->Image($path, $arraydata["x"] + JasperPHP\Instructions::$arrayPageSetting["leftMargin"], $arraydata["y"] + JasperPHP\Instructions::$y_axis, $arraydata["width"], $arraydata["height"], $imgtype, $arraydata["link"], '', false, 300, '', false, false, $arraydata["border"], $arraydata["fitbox"]);
242+
} elseif (mb_substr($path, 0, 21) == "data:image/jpg;base64") {
243+
$imgtype = "JPEG";
244+
//echo $path;
245+
$img = str_replace('data:image/jpg;base64,', '', $path);
246+
$imgdata = base64_decode($img);
247+
JasperPHP\Instructions::$objOutPut->Image('@' . $imgdata, $arraydata["x"] + JasperPHP\Instructions::$arrayPageSetting["leftMargin"], $arraydata["y"] + JasperPHP\Instructions::$y_axis, $arraydata["width"], $arraydata["height"], '', '', '', false, 300, '', false, false, $arraydata["border"], $arraydata["fitbox"]);
248+
} elseif (mb_substr($path, 0, 22) == "data:image/png;base64,") {
249+
$imgtype = "PNG";
250+
// JasperPHP\Pdf::$pdfOutPut->setImageScale(PDF_IMAGE_SCALE_RATIO);
251+
252+
$img = str_replace('data:image/png;base64,', '', $path);
253+
$imgdata = base64_decode($img);
254+
255+
256+
JasperPHP\Instructions::$objOutPut->Image('@' . $imgdata, $arraydata["x"] + JasperPHP\Instructions::$arrayPageSetting["leftMargin"], $arraydata["y"] + JasperPHP\Instructions::$y_axis, $arraydata["width"], $arraydata["height"], '', $arraydata["link"], '', false, 300, '', false, false, 0, $arraydata["fitbox"]);
257+
}
254258
}
255259
}
256260

0 commit comments

Comments
 (0)