Generate the PDF from a given HTML string. Replace all the CSS and JS
tags with inline blocks/code.

@param  string $html
@param  array  $options
@return string
962565
public function getOutputFromHtml($html, array $options = array())
    {
        $this->log('Get output from html.');

        $html = $this->getCssConverter()->convertToString($html);
        $html = $this->getJSConverter()->convertToString($html);

        return $this->getGenerator()->getOutputFromHtml($html, $options);
    }
695362
public function HTMLToPDF($html, GrabzItPDFOptions $options = null)
	{
		if ($options == null)
		{
			$options = new GrabzItPDFOptions();			
		}

		$this->request = new GrabzItRequest($this->getRootUrl(true) . GrabzItClient::TakePDF, true, $options, $html);
	}
234758
public function deserialize($data, $content = null, array $options = [])
    {
        if ('text/html' === $data['type'] || 'text/plain' === $data['type']) {
            // HTML is directly stored in the choice entity
            $content->setData($data['data']);
            $content->setResourceNode(null);
        } else {
            // Other types require a ResourceNode
            $node = $this->resourceContentSerializer->deserialize($content);

            $content->setData('');
            $content->setResourceNode($node);
        }

        return $content;
    }
1124122
public function output($options = array())
    {
        if (!isset($options["compress"])) $options["compress"] = true;

        $this->_add_page_text();

        if ($options["compress"]) {
            $this->_pdf->set_value("compress", 6);
        } else {
            $this->_pdf->set_value("compress", 0);
        }

        $this->_close();

        if (self::$IN_MEMORY) {
            $data = $this->_pdf->get_buffer();
        } else {
            $data = file_get_contents($this->_file);

            //debugpng
            if ($this->_dompdf->getOptions()->getDebugPng()) {
                print '[pdflib output unlink ' . $this->_file . ']';
            }
            if (!$this->_dompdf->getOptions()->getDebugKeepTemp()) {
                unlink($this->_file);
            }
            $this->_file = null;
            unset($this->_file);
        }

        return $data;
    }
499022
public function generateSelectOptions($options, $attr)
    {
        $return = '';

        foreach ($options as $key => $value) {
            if (is_array($value)) {
                $subArray = $this->generateSelectOptions($value, $attr);

                $return .= $this->Html->tag(
                    'optgroup',
                    array(
                        'label' => $key
                    ),
                    $subArray,
                    true
                );
            } else {
                $optionsAttr = array('value' => $key);

                if (isset($attr['selected']) && $attr['selected'] == $key) {
                    $optionsAttr[] = 'selected';
                }

                $return .= $this->Html->tag(
                    'option',
                    $optionsAttr,
                    $value,
                    true
                );
            }
        }

        return $return;
    }
241558
public function getStreamResponse(string $html, string $filename, array $options = []): StreamedResponse
    {
        $response = new StreamedResponse();
        $response->setCallback(function () use ($html, $filename, $options): void {
            $this->streamHtml($html, $filename, $options);
        });

        return $response;
    }
1252196
protected function buildText(string $html): string
    {
        $text = Strings::replace($html, [
            '#<(style|script|head).*</\\1>#Uis' => '',
            '#<t[dh][ >]#i' => ' $0',
            '#<a\s[^>]*href=(?|"([^"]+)"|\'([^\']+)\')[^>]*>(.*?)</a>#is' => '$2 &lt;$1&gt;',
            '#[\r\n]+#' => ' ',
            '#<(/?p|/?h\d|li|br|/tr)[ >/]#i' => "\n$0",
        ]);
        $text = \html_entity_decode(\strip_tags($text), ENT_QUOTES, 'UTF-8');
        $text = Strings::replace($text, '#[ \t]+#', ' ');

        return \trim($text);
    }
343557
public static function options($options, $selected = []): string
    {
        $html     = '';
        $selected = array_flip($selected);

        foreach ($options as $value => $name) {
            $html .= is_array($name)
                ? self::tag('optgroup', ['label' => $value], self::options($name, $selected))
                : self::tag('option', ['value' => $value] + (isset($selected[$value]) ? ['selected' => 'selected'] : []), $name);
        }

        return $html;
    }
728608
private static function buildHtml(&$html, $tag_object, $options, $tab = 0)
    {
        self::checkBuildOptions($options);

        $tag_is_special = in_array($tag_object->getTag(), self::$special_tags);
        $tag_is_ignored = in_array($tag_object->getTag(), array_get($options, 'ignore_tags', []));

        $ignore_tag = true;
        if (!isset($options['ignore_tags']) || !$tag_is_ignored) {
            $ignore_tag = false;
        } elseif (isset($options['ignore_tags']) && $tag_is_ignored) {
            $tab--;
        }

        $pad = '';
        if ($tab > 0) {
            $pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
        }

        if (!$ignore_tag) {
            if ($tag_is_special) {
                $html .= $pad.trim((string) $tag_object)."\n";
            } elseif (!$tag_is_special) {
                $html .= $pad;
                $html .= '<'.$tag_object->tag.''.self::buildHtmlAttribute($tag_object->getAttributes()).'>';
                $html .= ($tag_object->use_whitespace) ? "\n" : '';
                if (strlen($tag_object->getText())) {
                    $html .= ($tag_object->use_whitespace) ? $pad.'  ' : '';
                    $html .= $tag_object->getText();
                }
                $html .= ($tag_object->use_whitespace && strlen($tag_object->getText())) ? "\n" : '';
            }
        }

        if (!$tag_is_special && $tag_object->hasChildNodes()) {
            foreach ($tag_object->getChildNodes() as $child_tag_object) {
                self::buildHtml($html, $child_tag_object, $options, $tab + 1);
            }
        }

        $pad = '';
        if ($tab > 0) {
            $pad = str_pad($pad, $tab * 2, ' ', STR_PAD_LEFT);
        }

        if (!$ignore_tag && !$tag_is_special) {
            $html .= ($tag_object->use_whitespace) ? $pad : '';
            $html .= '</'.$tag_object->tag.'>'."\n";
        }
    }
355288
public function generatePdf($html, array $argOptions = array())
    {
        //Calculate arguments
        $defaultOptions = array(
            'constructorArgs'      => array(),
            'writeHtmlMode'        => null,
            'writeHtmlInitialise'  => null,
            'writeHtmlClose'       => null,
            'outputFilename'       => '',
            'outputDest'           => 'S',
            'mpdf'                 => null
        );                
	
        $options = array_merge($defaultOptions, $argOptions);
        extract($options);

        if (null == $mpdf) {
            $mpdf = $this->getMpdf($constructorArgs);
        }

        //Add arguments to AddHtml function
        $writeHtmlArgs = array($writeHtmlMode, $writeHtmlInitialise, $writeHtmlClose);
        $writeHtmlArgs = array_filter($writeHtmlArgs, function($x) { 
            return !is_null($x); 
        });

        $writeHtmlArgs['html'] = $html;

        @call_user_func_array(array($mpdf, 'WriteHTML'), $writeHtmlArgs);

        //Add arguments to Output function
        $content = $mpdf->Output($outputFilename, $outputDest);
	
        return $content;
    }
737570
public function generate($markup, $options = array()) {
        // 1 - write the content to the temp file
        $tempPath = $this->tempDirectory . '/' . uniqid();
        $tempPathOut = $tempPath . '-output';

        if( $markup instanceof MarkupInterface ) {
            $content = $markup->getContent();
        } else {
            $content = $markup;
        }

        // Store the content to the proper file
        file_put_contents($tempPath, $content);

        // Start building the command line
        $arguments = array('rst2html');

        if( $this->templatePath !== null ) {
            $arguments []= '--template=' . $this->templatePath;
        }

        if( $this->syntaxHighlight !== null ) {
            $arguments []= '--syntax-highlight=' . $this->syntaxHighlight;
        }

        if( $this->noSourceLinks != false ) {
            $arguments []= '--no-source-link';
        }

        if( $this->quiet != false ) {
            $arguments []= '--quiet';
        }

        if( $this->noDebug != false ) {
            $arguments []= '--no-debug';
        }

        $arguments []= $tempPath;
        $arguments []= $tempPathOut;

        // Get the builder
        $builder = new ProcessBuilder($arguments);

        // Build the process
        $process = $builder->getProcess();
        $process->setTimeout(3600);

        // Execute
        $process->run();

        if (!$process->isSuccessful()) {
            throw new \RuntimeException($process->getErrorOutput());
        }

        return file_get_contents($tempPathOut);
    }
1204104
public function get($html) {
      $kernel_dir = $this->kerneldir;
      require __DIR__ . "/../Resources/config/dompdf.php";

      $this->pdf = new DOMPDF;

      foreach ($this->options as $optionKey => $optionValue) {
         $this->pdf->set_option($optionKey, $optionValue);
      }

      $this->pdf->load_html($html);
      $this->pdf->set_paper("a4", 'portrait');
      $this->pdf->render();

      $response = new Response();

      $response->setContent($this->pdf->output());
      $response->setStatusCode(200);
      $response->headers->set('Content-Type', 'application/pdf');

      return $response;
   }
384239
function output($options = null) {
		//Helpers::dompdf_debug("trace", "($options[compress])");

		// Add page text
		$this->_add_page_text();
		$this->_add_internal_links();

		$this->_place_objects();

		if ( isset($options["compress"]) && $options["compress"] == 0 ) {
			$compress = false;
		}
		else {
			$compress = true;
		}

		$this->_pdf->SetCompression($compress);

		return $this->_pdf->Output('', 'S');
	}
554777
public function loadHTML( $html, $options = [] ) {
		$html = '<div><!-- pb_fixme -->' . $html . '<!-- pb_fixme --></div>';
		if ( $this->parser instanceof \DOMDocument ) {
			libxml_use_internal_errors( true );
			$this->parser->loadHTML( mb_convert_encoding( $html, 'HTML-ENTITIES', 'UTF-8' ), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
			$this->errors = libxml_get_errors();
			libxml_clear_errors();
			return $this->parser;
		} else {
			return $this->parser->loadHTML( $html, $options );
		}
	}
208399
public function replaceExternalCss($html, array $stylesheets)
    {
        foreach ($stylesheets['links'] as $key => $stylesheet) {
            if (!$this->isExternalStylesheet($stylesheet)) {
                $html = str_replace(
                    $stylesheets['tags'][$key],
                    $this->getStylesheetContent($stylesheet),
                    $html
                );
            }
        }

        return $html;
    }
815310
public function panelHeading($html, $options = array()) {
		$defaults = array('class' => '');
		$options = array_merge($defaults, $options);
		$options = $this->addClass($options, 'panel-heading');
		return $this->tag('div', $html, $options);
	}
309557
private function renderHtml($message, $options = [])
    {
        $html = Html::beginTag('div', $options);
        $html .= '<div class="card-panel">';
        $html .= $message;
        $html .= '</div>';
        $html .= Html::endTag('div');

        return $html;
    }