Пример #1
0
 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;
 }
Пример #2
0
 /**
  * Get a configured instance of PDFLib
  * @return \PDFlib
  * @throws Exception
  */
 protected function getPdf()
 {
     $pdf = new \PDFlib();
     if ($this->_licenseKey) {
         try {
             $pdf->set_option("license={$this->_licenseKey}");
         } catch (PDFlibException $e) {
             throw new Exception("Unable to validate PDFLib license key, check that your PDFLib version is compatible with your key: " . $e->getMessage());
         }
     }
     //This means we must check return values of load_font() etc.
     $pdf->set_option("errorpolicy=exception");
     //  open new PDF file in memory
     $pdf->begin_document("", "");
     $pdf->set_info("Creator", "Jazzee");
     $pdf->set_info("Author", "Jazzee Open Application Platform");
     return $pdf;
 }