Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #117-#118 #119

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function generate($obj = null)
//$data->hyperlinkReferenceExpression=$this->analyse_expression($data->hyperlinkReferenceExpression);
$data->hyperlinkReferenceExpression=trim(str_replace(array('"',''),"",$data->hyperlinkReferenceExpression));
// echo $text;
$printWhenExpression = $obj->get_expression($data->reportElement->printWhenExpression, $row);

$arraydata = [
"type" => "Image",
Expand All @@ -45,7 +46,8 @@ public function generate($obj = null)
"hidden_type" => "image",
"linktarget" => $data["hyperlinkTarget"] . "",
"border" => 0,
"fitbox" => false
"fitbox" => false,
"printWhenExpression" => $printWhenExpression . "",
];
if (isset($data->box)) {
$arraydata["border"] = StaticText::formatBox($data->box);
Expand Down
80 changes: 42 additions & 38 deletions src/PdfProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function resetY_axis($arraydata) {
}

public function SetY_axis($arraydata) {
if ((JasperPHP\Instructions::$y_axis + (int) $arraydata['y_axis']) <= JasperPHP\Instructions::$arrayPageSetting["pageHeight"]) {
if ((JasperPHP\Instructions::$y_axis + (int)$arraydata['y_axis']) <= JasperPHP\Instructions::$arrayPageSetting["pageHeight"]) {
JasperPHP\Instructions::$y_axis = JasperPHP\Instructions::$y_axis + (int)$arraydata['y_axis'];
}
}
Expand Down Expand Up @@ -214,43 +214,47 @@ public function Ellipse($arraydata) {

public function Image($arraydata) {
//echo $arraydata["path"];
$path = $arraydata["path"];
$imgtype = mb_substr($path, -3);
$arraydata["link"] = $arraydata["link"] . "";
if ($imgtype == 'jpg')
$imgtype = "JPEG";
elseif ($imgtype == 'png' || $imgtype == 'PNG')
$imgtype = "PNG";
// echo $path;
$imagePath = str_replace(array('"','\\','/'),array('',DIRECTORY_SEPARATOR,DIRECTORY_SEPARATOR) ,$path);
//not full patch?
if (!file_exists($imagePath)) {
$imagePath = getcwd().DIRECTORY_SEPARATOR.$imagePath;
}
if (file_exists($imagePath)) {

//echo $imagePath;
//exit;
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"]);
}elseif( mb_substr($path, 0, 4) == 'http'){
// echo $path;
///exit;
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"]);
} elseif (mb_substr($path, 0, 21) == "data:image/jpg;base64") {
$imgtype = "JPEG";
//echo $path;
$img = str_replace('data:image/jpg;base64,', '', $path);
$imgdata = base64_decode($img);
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"]);
} elseif (mb_substr($path, 0, 22) == "data:image/png;base64,") {
$imgtype = "PNG";
// JasperPHP\Pdf::$pdfOutPut->setImageScale(PDF_IMAGE_SCALE_RATIO);

$img = str_replace('data:image/png;base64,', '', $path);
$imgdata = base64_decode($img);


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"]);
$this->print_expression($arraydata);
if ($this->print_expression_result == true) {

$path = $arraydata["path"];
$imgtype = mb_substr($path, -3);
$arraydata["link"] = $arraydata["link"] . "";
if ($imgtype == 'jpg')
$imgtype = "JPEG";
elseif ($imgtype == 'png' || $imgtype == 'PNG')
$imgtype = "PNG";
// echo $path;
$imagePath = str_replace(array('"', '\\', '/'), array('', DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), $path);
//not full patch?
if (!file_exists($imagePath)) {
$imagePath = getcwd() . DIRECTORY_SEPARATOR . $imagePath;
}
if (file_exists($imagePath)) {

//echo $imagePath;
//exit;
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"]);
} elseif (mb_substr($path, 0, 4) == 'http') {
// echo $path;
///exit;
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"]);
} elseif (mb_substr($path, 0, 21) == "data:image/jpg;base64") {
$imgtype = "JPEG";
//echo $path;
$img = str_replace('data:image/jpg;base64,', '', $path);
$imgdata = base64_decode($img);
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"]);
} elseif (mb_substr($path, 0, 22) == "data:image/png;base64,") {
$imgtype = "PNG";
// JasperPHP\Pdf::$pdfOutPut->setImageScale(PDF_IMAGE_SCALE_RATIO);

$img = str_replace('data:image/png;base64,', '', $path);
$imgdata = base64_decode($img);


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"]);
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,12 @@ public static function process($arraydata){

$text = $jasperObj->get_expression($field->objElement->textFieldExpression,$row);
//change font for height row
$font = $field->objElement->textElement->font->attributes();
//$this->SetFont(array("font"=> $font->fontName, "fontstyle"=> (isset($font->isBold)?"B":""), "fontsize"=>$font->size));
JasperPHP\Instructions::addInstruction(array("type"=>"SetFont","font"=> $font->fontName, "fontstyle"=> (isset($font->isBold)?"B":""), "fontsize"=>$font->size));
JasperPHP\Instructions::runInstructions();
if($field->objElement->textElement->font) {
$font = $field->objElement->textElement->font->attributes();
//$this->SetFont(array("font"=> $font->fontName, "fontstyle"=> (isset($font->isBold)?"B":""), "fontsize"=>$font->size));
JasperPHP\Instructions::addInstruction(array("type"=>"SetFont","font"=> $font->fontName, "fontstyle"=> (isset($font->isBold)?"B":""), "fontsize"=>$font->size));
JasperPHP\Instructions::runInstructions();
}
$height_new = $pdf->getStringHeight($width_column,$text)*$lineHeightRatio;
//return default font
//$this->SetFont($fontDefault);
Expand Down