Ejemplo n.º 1
0
 public function testSetGetTopMargin()
 {
     $this->model->setTopMargin(10);
     $this->assertSame(10, $this->model->getTopMargin());
 }
Ejemplo n.º 2
-1
 /**
  * @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;
 }