function CreateGroup2($doc, $layer) { $writer = new ElementWriter(); $writer->Begin($doc->GetSDFDoc()); // Create a path object in the shape of a heart. $builder = new ElementBuilder(); $builder->PathBegin(); // start constructing the path $builder->MoveTo(306, 396); $builder->CurveTo(681, 771, 399.75, 864.75, 306, 771); $builder->CurveTo(212.25, 864.75, -69, 771, 306, 396); $builder->ClosePath(); $element = $builder->PathEnd(); // the path geometry is now specified. // Set the path FILL color space and color. $element->SetPathFill(true); $gstate = $element->GetGState(); $gstate->SetFillColorSpace(ColorSpace::CreateDeviceCMYK()); $gstate->SetFillColor(new ColorPt(1.0, 0.0, 0.0, 0.0)); // cyan // Set the path STROKE color space and color. $element->SetPathStroke(true); $gstate->SetStrokeColorSpace(ColorSpace::CreateDeviceRGB()); $gstate->SetStrokeColor(new ColorPt(1.0, 0.0, 0.0)); // red $gstate->SetLineWidth(20); $gstate->SetTransform(0.5, 0.0, 0.0, 0.5, 280.0, 300.0); $writer->WriteElement($element); $grp_obj = $writer->End(); // Indicate that this form (content group) belongs to the given layer (OCG). $grp_obj->PutName("Subtype", "Form"); $grp_obj->Put("OC", $layer); $grp_obj->PutRect("BBox", 0, 0, 1000, 1000); // Set the clip box for the content. return $grp_obj; }
$writer->End(); // save changes to the current page $doc->PagePushBack($page); // Start a new page ------------------------------------ // Construct and draw a path object using different styles $page = $doc->PageCreate(new Rect(0.0, 0.0, 612.0, 794.0)); $writer->Begin($page); // begin writing to this page $builder->Reset(); // Reset the GState to default $builder->PathBegin(); // start constructing the path $builder->MoveTo(306, 396); $builder->CurveTo(681, 771, 399.75, 864.75, 306, 771); $builder->CurveTo(212.25, 864.75, -69, 771, 306, 396); $builder->ClosePath(); $element = $builder->PathEnd(); // the path is now finished $element->SetPathFill(true); // the path should be filled // Set the path color space and color $gstate = $element->GetGState(); $gstate->SetFillColorSpace(ColorSpace::CreateDeviceCMYK()); $gstate->SetFillColor(new ColorPt(1.0, 0.0, 0.0, 0.0)); // cyan $gstate->SetTransform(0.5, 0.0, 0.0, 0.5, -20.0, 300.0); $writer->WritePlacedElement($element); // Draw the same path using a different stroke color $element->SetPathStroke(true); // this path is should be filled and stroked $gstate->SetFillColor(new ColorPt(0.0, 0.0, 1.0, 0.0));