/** * Invokes drawing procedure. * * Formats each of node, retreives drawing tasks and executes them. * * @param array $pages Array of pages to draw */ public function draw($pages) { if ($this->isProcessed()) { throw new LogicException(sprintf('Pdf has alredy been drawed.')); } $this->processed = true; if (is_array($pages)) { $pageCollection = new PageCollection(); foreach ($pages as $page) { if (!$page instanceof Page) { throw new DrawingException(sprintf('Not all elements of passed array are PHPPdf\\Core\\Node\\Page type. One of them is "%s".', get_class($page))); } $pageCollection->add($page); } } elseif ($pages instanceof PageCollection) { $pageCollection = $pages; } else { throw new InvalidArgumentException(sprintf('Argument of draw method must be an array of pages or PageCollection object, "%s" given.', get_class($pages))); } $pageCollection->format($this); $tasks = $pageCollection->getAllDrawingTasks($this); $this->invokeTasks($tasks); }