public function format(Node $node, Document $document)
 {
     $parent = $node->getParent();
     if ($node->getWidth() === null && !$node->isInline() && $node->getFloat() === Node::FLOAT_NONE) {
         $parentWidth = $parent->getWidthWithoutPaddings();
         $marginLeft = $node->getMarginLeft();
         $marginRight = $node->getMarginRight();
         $node->setWidth($parentWidth - ($marginLeft + $marginRight));
         $node->setRelativeWidth('100%');
     } elseif ($node->isInline()) {
         $node->setWidth(0);
     }
     if ($node->getHeight() === null) {
         $node->setHeight(0);
     }
     $paddingLeft = $node->getPaddingLeft();
     $paddingRight = $node->getPaddingRight();
     $paddingTop = $node->getPaddingTop();
     $paddingBottom = $node->getPaddingBottom();
     $prefferedWidth = $node->getRealWidth() + $paddingLeft + $paddingRight;
     $parent = $node->getParent();
     $parentWidth = $parent ? $parent->getWidthWithoutPaddings() : null;
     if ($parent && $parentWidth < $prefferedWidth) {
         $prefferedWidth = $parentWidth;
     }
     $node->setWidth($prefferedWidth);
     $node->setHeight($node->getRealHeight() + $paddingTop + $paddingBottom);
 }
 public function format(Node $node, Document $document)
 {
     if (!$node instanceof Page) {
         throw new InvalidArgumentException('ElasticPageFormatter works only with PHPPdf\\Core\\Node\\Page class.');
     }
     $lastChild = null;
     foreach ($node->getChildren() as $child) {
         if (!$lastChild || $lastChild->getDiagonalPoint()->getY() - $lastChild->getMarginBottom() > $child->getDiagonalPoint()->getY() - $child->getMarginBottom()) {
             $lastChild = $child;
         }
     }
     $lastNodeYCoord = $lastChild ? $lastChild->getDiagonalPoint()->getY() - $lastChild->getMarginBottom() : $node->getRealHeight();
     $height = $node->getRealHeight() - $lastNodeYCoord + $node->getMarginBottom();
     $translate = $node->getRealHeight() - $height;
     $node->setPageSize($node->getRealWidth(), $height);
     foreach ($node->getChildren() as $child) {
         $child->translate(0, $translate);
     }
     $node->removeGraphicsContext();
 }
Example #3
0
 private function getHeight(Node $node)
 {
     if ($this->useRealDimension) {
         return $node->getRealHeight();
     }
     return $node->getHeight();
 }