Location: PHPKode > scripts > PHP DocWriter > php-docwriter/examples/ex7.php
<?
require_once('../lib/include.php');
import('phpdocwriter.pdw_document');
import('phpdocwriter.pdw_drawing');

$sxw = new pdw_document();
$sxw->SetLanguage('en', 'EN');
$sxw->SetStdFont ("Times New Roman",10);
$sxw->SetFileName ('drawings');

// Pages and templates
$sxw->AddPageDef(array('name'=>'Standard'));
$sxw->AddPage();
$sxw->Write('Insert some rectangles,ellipses and paths');
$sxw->Ln();
$sxw->Write('The script randomly generates 20 rectangles with different positions, sizes, colors and corner radius.');
$sxw->Ln(2);

$svgwidth=17;
$svgheight=10;
srand((double) microtime() * 1000000);
for ($i = 0; $i < 20; $i+=1)
{
	//avoid getting a range 0..0 for rand function
	$x = floor(rand(0,$svgwidth-1));
	$y = floor(rand(0,$svgheight-1));
	//avoid getting rect outside of viewBox
	$width = floor(rand(1,$svgwidth-$x));
	$height = floor(rand(1,$svgheight-$y));
	$red = dechex(floor(rand(0,255)));
	$blue = dechex(floor(rand(0,255)));
	$green = dechex(floor(rand(0,255)));
	$color = '#'.$red.$blue.$green;
	$radius = floor(rand(0,180));
	$r_i = new pdw_draw_rectangle ($sxw,array('w'=>$width,'h'=>$height,'x'=>$x,'y'=>$y,'fillcolor'=>$color,'radius'=>$radius,'stroke'=>'none'));
	$r_i->Insert();
}
$sxw->Ln(6);

$el1 = new pdw_draw_ellipse ($sxw,array('w'=>14.289,'h'=>3.918,'x'=>1.072,'y'=>0.737,'fillgradient'=>'Ellipsoid blue grey/light blue','strokewidth'=>'0.1'));
$el1->Insert();

$fillgradient='Axial light red/white';
$let_p = 'm347 229c0 113 0 226 0 341 11 0 18 2 27 2 32 0 55-9 65-25s20-48 20-97c0-37 0-73 0-111 0-46-7-74-22-89s-44-21-90-21zm-347-229c116 0 233 0 349 0 96 0 170 9 221 21s88 37 114 65 43 62 52 103 14 102 14 187c0 37 0 76 0 114 0 87-9 149-27 187s-49 69-97 90-109 34-185 34c-32 0-62 0-94 0 0 178 0 358 0 538-114 0-231 0-347 0 0-446 0-893 0-1339z';
$let_r = 'm333 19c-3 48-7 94-12 143 48-102 118-157 210-162 0 127 0 256 0 386-62 0-106 7-134 25s-46 39-53 69-11 97-11 203c0 144 0 287 0 434-111 0-222 0-333 0 0-366 0-731 0-1098 111 0 222 0 333 0z';
$pa1 = new pdw_draw_path ($sxw,array('w'=>0.751,'h'=>1.341,'x'=>3.42,'y'=>1.96,'fillgradient'=>$fillgradient,'data'=>$let_p));
$pa1->Insert();
$pa2 = new pdw_draw_path ($sxw,array('w'=>0.801,'h'=>1.341,'x'=>4.27,'y'=>1.96,'fillgradient'=>$fillgradient,'data'=>'m799 0c0 446 0 893 0 1339-115 0-231 0-347 0 0-187 0-374 0-563-34 0-67 0-105 0 0 187 0 374 0 563-116 0-231 0-347 0 0-446 0-893 0-1339 116 0 231 0 347 0 0 159 0 318 0 480 34 0 69 0 105 0 0-161 0-319 0-480 116 0 232 0 347 0z'));
$pa2->Insert();
$pa3 = new pdw_draw_path ($sxw,array('w'=>0.751,'h'=>1.341,'x'=>5.211,'y'=>1.96,'fillgradient'=>$fillgradient,'data'=>$let_p));
$pa3->Insert();
$pa4 = new pdw_draw_path ($sxw,array('w'=>0.808,'h'=>1.341,'x'=>6.359,'y'=>1.96,'fillgradient'=>$fillgradient,'data'=>'m347 229c0 293 0 586 0 880 50 0 82-10 94-29s16-75 16-165c0-172 0-345 0-520 0-60-2-99-5-116s-13-30-27-37-40-13-78-13zm-347-229c85 0 171 0 259 0 168 0 283 9 341 23s106 41 136 76 51 76 58 118 12 129 12 256c0 155 0 310 0 467 0 122-7 201-18 242s-31 72-60 95-61 39-102 48-104 14-187 14c-146 0-293 0-439 0 0-446 0-893 0-1339z'));
$pa4->Insert();
$pa5 = new pdw_draw_path ($sxw,array('w'=>0.767,'h'=>1.136,'x'=>7.274,'y'=>2.182,'fillgradient'=>$fillgradient,'data'=>'m432 321c0-55-3-92-9-106s-19-21-38-21-34 7-41 21-11 51-11 106c0 166 0 330 0 496 0 53 4 86 11 102s19 23 39 23 33-7 39-21 10-46 10-94c0-167 0-335 0-506zm334 83c0 90 0 178 0 268 0 101-6 171-15 217s-31 90-65 131-74 68-123 88-111 26-177 26c-74 0-136-7-187-23s-91-40-120-74-49-70-61-118-18-116-18-210 0-185 0-280c0-103 11-182 34-238s61-105 118-140 130-51 220-51c74 0 140 11 192 34s96 51 126 86 49 72 60 111 16 95 16 173z'));
$pa5->Insert();
$pa6 = new pdw_draw_path ($sxw,array('w'=>0.75,'h'=>1.136,'x'=>8.14,'y'=>2.182,'fillgradient'=>$fillgradient,'data'=>'m748 434c-106 0-210 0-316 0 0-42 0-85 0-127s-2-74-9-90-21-23-40-23-32 7-39 21-11 44-11 92c0 171 0 344 0 519 0 38 6 67 16 86s23 30 44 30 37-11 46-32 13-58 13-114c0-43 0-87 0-131 98 0 197 0 296 0 0 88-4 153-9 198s-25 88-56 134-71 81-122 104-113 33-185 33c-96 0-170-16-224-46s-96-77-118-135-34-142-34-247 0-209 0-313c0-93 9-164 28-211s58-89 120-127 136-55 222-55 163 18 224 55 103 84 124 139 30 138 30 240z'));
$pa6->Insert();
$pa7 = new pdw_draw_path ($sxw,array('w'=>1.379,'h'=>1.341,'x'=>8.929,'y'=>1.96,'fillgradient'=>$fillgradient,'data'=>'m1378 0c-52 446-103 893-154 1339-146 0-291 0-436 0-40-207-75-439-105-702-14 113-46 345-97 702-143 0-288 0-431 0-51-446-102-893-155-1339 111 0 224 0 337 0 12 155 23 310 35 467 13 150 25 300 37 450 13-233 44-538 95-917 122 0 242 0 364 0 3 39 16 185 37 443 12 167 25 337 39 508 19-325 51-641 95-951 113 0 224 0 339 0z'));
$pa7->Insert();
$pa8 = new pdw_draw_path ($sxw,array('w'=>0.533,'h'=>1.118,'x'=>10.366,'y'=>2.182,'fillgradient'=>$fillgradient,'data'=>$let_r));
$pa8->Insert();
$pa9 = new pdw_draw_path ($sxw,array('w'=>0.346,'h'=>1.341,'x'=>10.971,'y'=>1.96,'fillgradient'=>$fillgradient,'viewbox'=>'0 0 346 1341','data'=>'m344 242c0 365 0 730 0 1097-113 0-228 0-344 0 0-365 0-730 0-1097 115 0 229 0 344 0zm0-242c0 58 0 116 0 175-113 0-228 0-344 0 0-59 0-117 0-175 115 0 229 0 344 0z'));
$pa9->Insert();
$pa10 = new pdw_draw_path ($sxw,array('w'=>0.513,'h'=>1.245,'x'=>11.381,'y'=>2.055,'fillgradient'=>$fillgradient,'data'=>'m407 0c0 56 0 113 0 173 30 0 60 0 90 0 0 58 0 116 0 174-30 0-60 0-90 0 0 195 0 390 0 586 0 72 4 113 11 120s39 14 94 14c0 58 0 117 0 177-45 0-89 0-135 0-75 0-130-4-162-11s-62-19-86-42-41-50-48-80-9-99-9-208c0-185 0-369 0-556-23 0-47 0-72 0 0-58 0-116 0-174 25 0 49 0 72 0 0-57 0-115 0-173 111 0 223 0 335 0z'));
$pa10->Insert();
$pa11 = new pdw_draw_path ($sxw,array('w'=>0.769,'h'=>1.136,'x'=>11.942,'y'=>2.182,'fillgradient'=>$fillgradient,'data'=>'m432 409c0-26 0-53 0-81 0-56-2-93-9-109s-19-25-37-25-37 7-44 21-7 51-7 113c0 27 0 53 0 81 32 0 64 0 97 0zm335 178c-144 0-289 0-432 0 0 78 0 157 0 239 0 47 4 79 11 95s21 21 40 21c27 0 43-9 51-28s13-57 13-111c0-48 0-96 0-145 106 0 211 0 317 0 0 28 0 55 0 81 0 67-5 120-12 157s-30 74-60 116-72 73-120 92-108 30-182 30-132-9-187-28-95-49-125-85-51-74-63-118-18-104-18-185c0-106 0-212 0-321 0-95 14-169 39-226s69-99 127-127 127-44 204-44c94 0 172 16 233 53s103 83 127 141 37 141 37 247c0 49 0 97 0 146z'));
$pa11->Insert();
$pa12 = new pdw_draw_path ($sxw,array('w'=>0.534,'h'=>1.118,'x'=>12.818,'y'=>2.182,'fillgradient'=>$fillgradient,'data'=>$let_r));
$pa12->Insert();

if (isset ($_REQUEST["format"]) && $_REQUEST["format"]!='') $sxw->SetExportFilter ($_REQUEST["format"]);
if (isset ($_REQUEST["zip"]) && ($_REQUEST["zip"] == 1)) $sxw->CompressOutput();

$sxw->_debug();
$sxw->Output();

exit;
?>
Return current item: PHP DocWriter