JQuery Code:
First you get active object of canvas the go throw
dataArray.push({
"objFlipX" : obj_Tshirt_canv.item(i).getFlipX(),
"objFlipY" : obj_Tshirt_canv.item(i).getFlipY(),
"objWidth" : obj_Tshirt_canv.item(i).getWidth(),
"bojHeight" : obj_Tshirt_canv.item(i).getHeight(),
"objOriginX" : obj_Tshirt_canv.item(i).getLeft(),
"objOriginY" : obj_Tshirt_canv.item(i).getTop(),
"objImgSrc" : obj_Tshirt_canv.item(i).getSrc(),
"objAngel" : obj_Tshirt_canv.item(i).getAngle(),
"objScalex" : obj_Tshirt_canv.item(i).getScaleX(),
"objScaley" : obj_Tshirt_canv.item(i).getScaleY(),
"objType" : 'image'
});
$.ajax({
url : " ",
type : "POST",
data : {
dataArray : dataArray
},
cache : false,
success : function(data) {
alert("data update successfully");
hideLoder();
},
error : function(xhr, status, error) {
alert("Not Successfull");
}
});
Now crate php file and create object of fpdf like
require ('fpdf.php');
$aaa = $_REQUEST['action'];
$aaa();
function createpdf() {
$size = Array(840, 990);
$data = $_REQUEST['dataArray'];
$width = 280;
$height = 330;
$_actualratioWid = 840/$width;
$_actualratioHig = 990/$height;
$fpdfObj = new FPDF("p", "pt", $size);
$fpdfObj -> AddPage();
foreach ($data as $key => $value) {
$x = $value[objOriginX] * $_actualratioWid;
$y = $value[objOriginY] * $_actualratioHig;
$height = $value[bojHeight] * $_actualratioHig;
$width = $value[objWidth] * $_actualratioHig;
$_flipx = ($value[objFlipX]);
$_flipy = ($value[objFlipY]);
$imgsrc = $value[objImgSrc];
$dataTppe = $value[objType];
$rotation = $value[objAngel];
$color=$value[objcol];
$randomString = MyStringr();
$_filename1 = $_SERVER["DOCUMENT_ROOT"] . "path" . $randomString . ".png";
if ($value[objType] === 'text' && $value[objval] != " ") {//new code to be imp
$image_src = $_SERVER["DOCUMENT_ROOT"] . " path". $randomString . ".png";
exec('convert -background transparent -depth 8 -size 500 -fill "' . $color .'" -pointsize 70 label:"' . $value[objval] .'" "'. $image_src.'"');
$fpdfObj -> Image($image_src, $x, $y);
} else {// work done
$imgsrc = str_replace(" path", $_SERVER["DOCUMENT_ROOT"], $imgsrc);
if ($_flipx == "false" && $_flipy == "false") {
$fpdfObj -> Image($imgsrc, $x, $y, $height, $width);
} else if ($_flipy == "true" && $_flipx == "false") {
exec(' convert "' . $value[objImgSrc] . '" -flip ' . $_filename1);
$fpdfObj -> Image($_filename1, $x, $y, $height, $width);
}
else if($_flipx== "true" && $_flipy=="false")
{ exec(' convert "' . $value[objImgSrc] . '" -flop ' . $_filename1);
$fpdfObj -> Image($_filename1, $x, $y, $height, $width);
}
}//end else
}//foreach
while (true)//generate random file name when cart is added by user in tool
{
$filename = uniqid('AddCart', true) . '.pdf';`enter code here`
if (!file_exists(sys_get_temp_dir() . $filename))
break;
}
$fpdfObj -> Output($_SERVER["DOCUMENT_ROOT"] . "path " . $filename);
}//end createpdf()
function MyStringr()//return random file name
{
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randstring = '';
for ($i = 0; $i < 10; $i++) {
$randstring = $characters[rand(0, strlen($characters))];
}
return $randstring;
}
我沒有使用PHP,但JavaScript和jspdf庫。你有使用這些的解決方案嗎? – Kode