Source of file DompdfWrapper.php

Size: 10,292 Bytes - Last Modified: 2023-11-16T22:56:03+01:00

/home/websites/teicee/packagist/site/phpdoc/conf/../vendor/teicee/dpdf-bundle/src/Traits/DompdfWrapper.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
<?php
namespace TIC\DpdfBundle\Traits;

use Dompdf\Dompdf;
use Dompdf\Css\Stylesheet;
use Dompdf\Frame\FrameTree;
use Dompdf\DOMDocument;
use Dompdf\DOMNode;

/**
 * Wrapper sur l'interface publique de la classe utilitaire Dompdf.
 * (permet d'exposer les méthodes dans un service Symfony)
 */
trait DompdfWrapper
{
    protected $dompdf;

    /**
     * Class constructor
     *
     * @param Options|array|null $options
     */
    public function construct($options = null)
    {
        $this->dompdf = new Dompdf($options);
    }


    public function loadDOM($doc, $quirksmode = false)
    {
        $this->dompdf->loadDOM($doc, $quirksmode);
    }

    /**
     * Loads an HTML file
     * Parse errors are stored in the global array _dompdf_warnings.
     *
     * @param string $file a filename or url to load
     * @param string $encoding Encoding of $file
     *
     * @throws Exception
     */
    public function loadHtmlFile($file, $encoding = null)
    {
        $this->dompdf->loadHtmlFile($file, $encoding);
    }

    /**
     * Loads an HTML string
     * Parse errors are stored in the global array _dompdf_warnings.
     *
     * @param string $str HTML text to load
     * @param string $encoding Encoding of $str
     */
    public function loadHtml($str, $encoding = null)
    {
        $this->dompdf->loadHtml($str, $encoding);
    }

    /**
     * @param DOMNode $node
     */
    public static function removeTextNodes(DOMNode $node)
    {
        $this->dompdf->removeTextNodes($node);
    }

    /**
     * Enable experimental caching capability
     *
     * @param string $cacheId
     */
    public function enableCaching($cacheId)
    {
        $this->dompdf->enableCaching($cacheId);
    }

    /**
     * @param string $value
     * @return bool
     */
    public function parseDefaultView($value)
    {
        return $this->dompdf->parseDefaultView($value);
    }

    /**
     * Renders the HTML to PDF
     */
    public function render()
    {
        $this->dompdf->render();
    }

    /**
     * Add meta information to the PDF after rendering.
     *
     * @param string $label Label of the value (Creator, Producer, etc.)
     * @param string $value The text to set
     */
    public function addInfo(string $label, string $value): void
    {
        $this->dompdf->addInfo($label, $value);
    }

    /**
     * Streams the PDF to the client.
     *
     * The file will open a download dialog by default. The options
     * parameter controls the output. Accepted options (array keys) are:
     *
     * 'compress' = > 1 (=default) or 0:
     *   Apply content stream compression
     *
     * 'Attachment' => 1 (=default) or 0:
     *   Set the 'Content-Disposition:' HTTP header to 'attachment'
     *   (thereby causing the browser to open a download dialog)
     *
     * @param string $filename the name of the streamed file
     * @param array $options header options (see above)
     */
    public function stream($filename = "document.pdf", $options = [])
    {
        $this->dompdf->stream($filename, $options);
    }

    /**
     * Returns the PDF as a string.
     *
     * The options parameter controls the output. Accepted options are:
     *
     * 'compress' = > 1 or 0 - apply content stream compression, this is
     *    on (1) by default
     *
     * @param array $options options (see above)
     *
     * @return string|null
     */
    public function output($options = [])
    {
        return $this->dompdf->output($options);
    }

    /**
     * Returns the underlying HTML document as a string
     *
     * @return string
     */
    public function outputHtml()
    {
        return $this->dompdf->outputHtml();
    }

    /**
     * Sets the paper size & orientation
     *
     * @param string|float[] $size 'letter', 'legal', 'A4', etc. {@link Dompdf\Adapter\CPDF::$PAPER_SIZES}
     * @param string $orientation 'portrait' or 'landscape'
     * @return $this
     */
    public function setPaper($size, $orientation = "portrait")
    {
        return $this->dompdf->setPaper($size, $orientation);
    }

    /**
     * Gets the paper size
     *
     * @return float[] A four-element float array
     */
    public function getPaperSize()
    {
        return $this->dompdf->getPaperSize();
    }

    /**
     * Gets the paper orientation
     *
     * @return string Either "portrait" or "landscape"
     */
    public function getPaperOrientation()
    {
        return $this->dompdf->getPaperOrientation();
    }

    /**
     * @param FrameTree $tree
     * @return $this
     */
    public function setTree(FrameTree $tree)
    {
        return $this->dompdf->setTree($tree);
    }

    /**
     * Returns the underlying {@link FrameTree} object
     *
     * @return FrameTree
     */
    public function getTree()
    {
        return $this->dompdf->getTree();
    }

    /**
     * Sets the protocol to use
     * FIXME validate these
     *
     * @param string $protocol
     * @return $this
     */
    public function setProtocol(string $protocol)
    {
        return $this->dompdf->setProtocol($protocol);
    }

    /**
     * Returns the protocol in use
     *
     * @return string
     */
    public function getProtocol()
    {
        return $this->dompdf->getProtocol();
    }

    /**
     * Sets the base hostname
     *
     * @param string $baseHost
     * @return $this
     */
    public function setBaseHost(string $baseHost)
    {
        return $this->dompdf->setBaseHost($baseHost);
    }

    /**
     * Returns the base hostname
     *
     * @return string
     */
    public function getBaseHost()
    {
        return $this->dompdf->getBaseHost();
    }

    /**
     * Sets the base path
     *
     * @param string $basePath
     * @return $this
     */
    public function setBasePath(string $basePath)
    {
        return $this->dompdf->setBasePath($basePath);
    }

    /**
     * Returns the base path
     *
     * @return string
     */
    public function getBasePath()
    {
        return $this->dompdf->getBasePath();
    }

    /**
     * Sets the default view
     *
     * @param string $defaultView The default document view
     * @param array $options The view's options
     * @return $this
     */
    public function setDefaultView($defaultView, $options)
    {
        return $this->dompdf->setDefaultView($defaultView, $options);
    }

    /**
     * Sets the HTTP context
     *
     * @param resource|array $httpContext
     * @return $this
     */
    public function setHttpContext($httpContext)
    {
        return $this->dompdf->setHttpContext($httpContext);
    }

    /**
     * Returns the HTTP context
     *
     * @return resource
     */
    public function getHttpContext()
    {
        return $this->dompdf->getHttpContext();
    }

    /**
     * Set a custom `Canvas` instance to render the document to.
     *
     * Be aware that the instance will be replaced on render if the document
     * defines a paper size different from the canvas.
     *
     * @param Canvas $canvas
     * @return $this
     */
    public function setCanvas(Canvas $canvas)
    {
        return $this->dompdf->setCanvas($canvas);
    }

    /**
     * Return the underlying Canvas instance (e.g. Dompdf\Adapter\CPDF, Dompdf\Adapter\GD)
     *
     * @return Canvas
     */
    public function getCanvas()
    {
        return $this->dompdf->getCanvas();
    }

    /**
     * @param Stylesheet $css
     * @return $this
     */
    public function setCss(Stylesheet $css)
    {
        return $this->dompdf->setCss($css);
    }

    /**
     * Returns the stylesheet
     *
     * @return Stylesheet
     */
    public function getCss()
    {
        return $this->dompdf->getCss();
    }

    /**
     * @param DOMDocument $dom
     * @return $this
     */
    public function setDom(DOMDocument $dom)
    {
        return $this->dompdf->setDom($dom);
    }

    /**
     * @return DOMDocument
     */
    public function getDom()
    {
        return $this->dompdf->getDom();
    }

    /**
     * @param Options $options
     * @return $this
     */
    public function setOptions(Options $options)
    {
        return $this->dompdf->setOptions($options);
    }

    /**
     * @return Options
     */
    public function getOptions()
    {
        return $this->dompdf->getOptions();
    }

    /**
     * Returns the callbacks array
     *
     * @return array
     */
    public function getCallbacks()
    {
        return $this->dompdf->getCallbacks();
    }

    /**
     * Define callbacks that allow modifying the document during render.
     *
     * The callbacks array should contain arrays with `event` set to a callback
     * event name and `f` set to a function or any other callable.
     *
     * The available callback events are:
     * * `begin_page_reflow`: called before page reflow
     * * `begin_frame`: called before a frame is rendered
     * * `end_frame`: called after frame rendering is complete
     * * `begin_page_render`: called before a page is rendered
     * * `end_page_render`: called after page rendering is complete
     * * `end_document`: called for every page after rendering is complete
     *
     * The function `f` receives three arguments `Frame $frame`, `Canvas $canvas`,
     * and `FontMetrics $fontMetrics` for all events but `end_document`. For
     * `end_document`, the function receives four arguments `int $pageNumber`,
     * `int $pageCount`, `Canvas $canvas`, and `FontMetrics $fontMetrics` instead.
     *
     * @param array $callbacks The set of callbacks to set.
     * @return $this
     */
    public function setCallbacks(array $callbacks): self
    {
        return $this->dompdf->setCallbacks($callbacks);
    }

    /**
     * Get the quirks mode
     *
     * @return boolean true if quirks mode is active
     */
    public function getQuirksmode()
    {
        return $this->dompdf->getQuirksmode();
    }

    /**
     * @param FontMetrics $fontMetrics
     * @return $this
     */
    public function setFontMetrics(FontMetrics $fontMetrics)
    {
        return $this->dompdf->setFontMetrics($fontMetrics);
    }

    /**
     * @return FontMetrics
     */
    public function getFontMetrics()
    {
        return $this->dompdf->getFontMetrics();
    }

}