GE_NUM, int $PAGE_COUNT, self $pdf, FontMetrics $fontMetrics ) use ($callback) { eval($callback); }); return; } $this->processPageScript($callback); } public function page_text($x, $y, $text, $font, $size, $color = [0, 0, 0], $word_space = 0.0, $char_space = 0.0, $angle = 0.0) { $this->processPageScript(function (int $pageNumber, int $pageCount) use ($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle) { $text = str_replace( ["{PAGE_NUM}", "{PAGE_COUNT}"], [$pageNumber, $pageCount], $text ); $this->text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle); }); } public function page_line($x1, $y1, $x2, $y2, $color, $width, $style = []) { $this->processPageScript(function () use ($x1, $y1, $x2, $y2, $color, $width, $style) { $this->line($x1, $y1, $x2, $y2, $color, $width, $style); }); } /** * @return int */ public function new_page() { $this->_page_number++; $this->_page_count++; $ret = $this->_pdf->newPage(); $this->_pages[] = $ret; return $ret; } protected function processPageScript(callable $callback): void { $pageNumber = 1; foreach ($this->_pages as $pid) { $this->reopen_object($pid); $fontMetrics = $this->_dompdf->getFontMetrics(); $callback($pageNumber, $this->_page_count, $this, $fontMetrics); $this->close_object(); $pageNumber++; } } public function stream($filename = "document.pdf", $options = []) { if (headers_sent()) { die("Unable to stream pdf: headers already sent"); } if (!isset($options["compress"])) $options["compress"] = true; if (!isset($options["Attachment"])) $options["Attachment"] = true; $debug = !$options['compress']; $tmp = ltrim($this->_pdf->output($debug)); header("Cache-Control: private"); header("Content-Type: application/pdf"); header("Content-Length: " . mb_strlen($tmp, "8bit")); $filename = str_replace(["\n", "'"], "", basename($filename, ".pdf")) . ".pdf"; $attachment = $options["Attachment"] ? "attachment" : "inline"; header(Helpers::buildContentDispositionHeader($attachment, $filename)); echo $tmp; flush(); } public function output($options = []) { if (!isset($options["compress"])) $options["compress"] = true; $debug = !$options['compress']; return $this->_pdf->output($debug); } /** * Returns logging messages generated by the Cpdf class * * @return string */ public function get_messages() { return $this->_pdf->messages; } }