Pop\Pdf\Pdf::import PHP Method

import() public method

Method to import either an entire PDF, or a page of a PDF, and the related data.
public import ( string $pdf, integer | string | array $pg = null ) : Pdf
$pdf string
$pg integer | string | array
return Pdf
    public function import($pdf, $pg = null)
    {
        // Create a new PDF Import object.
        $pdfi = new Import($pdf, $pg);
        // Shift the imported objects indices based on existing indices in this PDF.
        $pdfi->shiftObjects($this->lastIndex($this->objects) + 1);
        // Fetch the imported objects.
        $importedObjs = $pdfi->returnObjects($this->parent);
        // Loop through the imported objects, adding the pages or objects as applicable.
        foreach ($importedObjs as $key => $value) {
            if ($value['type'] == 'page') {
                // Add the page object.
                $this->objects[$key] = new Object\Page($value['data']);
                // Finalize related page variables and objects.
                $this->curPage = null === $this->curPage ? 0 : $this->lastIndex($this->pages) + 1;
                $this->pages[$this->curPage] = $key;
                $this->objects[$this->parent]->count += 1;
            } else {
                // Else, add the content object.
                $this->objects[$key] = new Object\Object($value['data']);
            }
        }
        foreach ($pdfi->pages as $value) {
            $this->objects[$this->parent]->kids[] = $value;
        }
        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));
All Usage Examples Of Pop\Pdf\Pdf::import