public function __construct(Document $doc, $canvas = null) { if (self::DEBUG) { echo __FUNCTION__ . "\n"; } $dimensions = $doc->getDimensions(); $w = $dimensions["width"]; $h = $dimensions["height"]; if (!$canvas) { $canvas = new \PDFlib(); /* all strings are expected as utf8 */ $canvas->set_option("stringformat=utf8"); $canvas->set_option("errorpolicy=return"); /* open new PDF file; insert a file name to create the PDF on disk */ if ($canvas->begin_document("", "") == 0) { die("Error: " . $canvas->get_errmsg()); } $canvas->set_info("Creator", "PDFlib starter sample"); $canvas->set_info("Title", "starter_graphics"); $canvas->begin_page_ext($w, $h, ""); } // Flip PDF coordinate system so that the origin is in // the top left rather than the bottom left $canvas->setmatrix(1, 0, 0, -1, 0, $h); $this->width = $w; $this->height = $h; $this->canvas = $canvas; }