Exemple #1
25
 /**
  * Handle handler
  *
  * @return void
  */
 public function handle()
 {
     $dompdf = new Dompdf();
     $dompdf->loadHtml($this->input);
     $dompdf->setPaper('letter');
     $dompdf->render();
     //Page numbers
     $font = $dompdf->getFontMetrics()->getFont("Arial", "bold");
     $dompdf->getCanvas()->page_text(16, 770, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, array(0, 0, 0));
     echo $dompdf->output();
 }
Exemple #2
0
 /**
  * The class constructor.
  *
  * The base protocol, host & path are initialized to those of
  * the current script.
  */
 function __construct(Dompdf $dompdf)
 {
     $this->_dompdf = $dompdf;
     $this->setFontMetrics($dompdf->getFontMetrics());
     $this->_styles = array();
     $this->_loaded_files = array();
     list($this->_protocol, $this->_base_host, $this->_base_path) = Helpers::explode_url($_SERVER["SCRIPT_FILENAME"]);
     $this->_page_styles = array("base" => null);
 }
 /**
  * @param Dompdf $pdf
  * @param PdfOptions $pdfOptions
  * @param $position
  * @return Dompdf
  */
 private function processPageLines(Dompdf $pdf, PdfOptions $pdfOptions, $position)
 {
     $pageLines = 'header' === $position ? $pdfOptions->getHeaderLines() : $pdfOptions->getFooterLines();
     $canvas = $pdf->getCanvas();
     $pageWidth = $canvas->get_width();
     $pageHeight = 'header' === $position ? $pdfOptions->getTopMargin() : $canvas->get_height() - $pdfOptions->getBottomMargin();
     $previousHeight = 5;
     // margin
     $pageCount = $canvas->get_page_count();
     $pageNumberMap = ['/{PAGE_COUNT}/', '/{PAGE_NUM}/'];
     $fontMetric = $pdf->getFontMetrics();
     /* @var $line \UthandoDomPdf\Model\PdfTextLine */
     foreach ($pageLines as $line) {
         $font = $fontMetric->getFont($line->getFont()->getFamily(), $line->getFont()->getWeight());
         $size = $line->getFont()->getSize();
         $text = $line->getText();
         $fontHeight = $fontMetric->getFontHeight($font, $size);
         $textWidth = $canvas->get_text_width(preg_replace($pageNumberMap, $pageCount, $text), $font, $size);
         if ('header' === $position) {
             $startY = $pageHeight + $previousHeight + $fontHeight;
         } else {
             $startY = $pageHeight - $previousHeight - $fontHeight;
         }
         $startX = $this->getPosition($pageWidth, $textWidth, $line->getPosition(), $pdfOptions);
         $canvas->page_text($startX, $startY, $text, $font, $size, [0, 0, 0]);
         $previousHeight += $fontHeight + 1;
         // +1 is the line spacing
     }
     return $pdf;
 }