Pop\Pdf\Pdf::setStrokeWidth PHP Method

setStrokeWidth() public method

Method to set the width and dash properties of paths in the PDF.
public setStrokeWidth ( integer $w = null, integer $dash_len = null, integer $dash_gap = null ) : Pdf
$w integer
$dash_len integer
$dash_gap integer
return Pdf
    public function setStrokeWidth($w = null, $dash_len = null, $dash_gap = null)
    {
        if (null === $w || $w == false || $w == 0) {
            $this->stroke = false;
            $this->strokeWidth = null;
            $this->strokeDashLength = null;
            $this->strokeDashGap = null;
        } else {
            $this->stroke = true;
            $this->strokeWidth = $w;
            $this->strokeDashLength = $dash_len;
            $this->strokeDashGap = $dash_gap;
            // Set stroke to the $w argument, or else default it to 1pt.
            $new_str = "\n{$w} w\n";
            // Set the dash properties of the stroke, or else default it to a solid line.
            $new_str .= null !== $dash_len && null !== $dash_gap ? "[{$dash_len} {$dash_gap}] 0 d\n" : "[] 0 d\n";
            $co_index = $this->getContentObject();
            $this->objects[$co_index]->setStream($new_str);
        }
        return $this;
    }

Usage Example

Exemplo n.º 1
0
<?php

require_once '../../bootstrap.php';
use Pop\Color\Space\Rgb;
use Pop\Pdf\Pdf;
try {
    $pdf = new Pdf('new_test.pdf');
    $pdf->import('../assets/pdfs/hospital.pdf');
    $pdf->setFillColor(new Rgb(128, 200, 50));
    $pdf->setStrokeColor(new Rgb(0, 255, 0));
    $pdf->setStrokeWidth(8);
    $pdf->drawCircle(500, 500, 100);
    $pdf->setFillColor(new Rgb(215, 101, 12));
    $pdf->setStrokeColor(new Rgb(0, 0, 0));
    $pdf->setStrokeWidth(2, 5, 5);
    $pdf->drawRectangle(50, 150, 175, 50);
    $pdf->setPage(2);
    $pdf->setFillColor(new Rgb(12, 101, 215));
    $pdf->setStrokeColor(new Rgb(0, 0, 128));
    $pdf->setStrokeWidth(5);
    $pdf->drawRectangle(150, 650, 400, 100);
    $pdf->addFont('Courier');
    $pdf->setFillColor(new Rgb(12, 255, 12));
    $pdf->addText(10, 300, 18, 'Hello World Again!!!', 'Courier');
    $pdf->addUrl(10, 300, 380, 18, 'http://www.popphp.org/');
    $pdf->setFillColor(new Rgb(128, 200, 50));
    $pdf->setStrokeColor(new Rgb(0, 255, 0));
    $pdf->setStrokeWidth(8);
    $pdf->drawCircle(500, 500, 100);
    $pdf->addPage('Legal');
    $pdf->setFillColor(new Rgb(128, 200, 50));