Example #1
0
function CreateTilingPattern($doc)
{
    $writer = new ElementWriter();
    $builder = new ElementBuilder();
    // Create a new pattern content stream - a heart. ------------
    $writer->Begin($doc->GetSDFDoc());
    $builder->PathBegin();
    $builder->MoveTo(0, 0);
    $builder->CurveTo(500, 500, 125, 625, 0, 500);
    $builder->CurveTo(-125, 625, -500, 500, 0, 0);
    $heart = $builder->PathEnd();
    $heart->SetPathFill(true);
    // Set heart color to red.
    $heart->GetGState()->SetFillColorSpace(ColorSpace::CreateDeviceRGB());
    $heart->GetGState()->SetFillColor(new ColorPt(1.0, 0.0, 0.0));
    $writer->WriteElement($heart);
    $pattern_dict = $writer->End();
    // Initialize pattern dictionary. For details on what each parameter represents please
    // refer to Table 4.22 (Section '4.6.2 Tiling Patterns') in PDF Reference Manual.
    $pattern_dict->PutName("Type", "Pattern");
    $pattern_dict->PutNumber("PatternType", 1);
    // TilingType - Constant spacing.
    $pattern_dict->PutNumber("TilingType", 1);
    // This is a Type1 pattern - A colored tiling pattern.
    $pattern_dict->PutNumber("PaintType", 1);
    // Set bounding box
    $pattern_dict->PutRect("BBox", -253, 0, 253, 545);
    // Create and set the matrix
    $pattern_mtx = new Matrix2D(0.04, 0.0, 0.0, 0.04, 0.0, 0.0);
    $pattern_dict->PutMatrix("Matrix", $pattern_mtx);
    // Set the desired horizontal and vertical spacing between pattern cells,
    // measured in the pattern coordinate system.
    $pattern_dict->PutNumber("XStep", 1000);
    $pattern_dict->PutNumber("YStep", 1000);
    return $pattern_dict;
    // finished creating the Pattern resource
}
Example #2
0
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;
}
// 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));
// yellow