code: public function generatePdf()
  	{
  		$this->headline = $this->title;
  		$this->printable = false;
  
  		// Generate article
  		$strArticle = $this->replaceInsertTags($this->generate(), false);
  		$strArticle = html_entity_decode($strArticle, ENT_QUOTES, Config::get('characterSet'));
  		$strArticle = $this->convertRelativeUrls($strArticle, '', true);
  
  		// Remove form elements and JavaScript links
  		$arrSearch = array
  		(
  			'@<form.*</form>@Us',
  			'@<a [^>]*href="[^"]*javascript:[^>]+>.*</a>@Us'
  		);
  
  		$strArticle = preg_replace($arrSearch, '', $strArticle);
  
  		if (empty($GLOBALS['TL_HOOKS']['printArticleAsPdf']))
  		{
  			throw new \Exception('No PDF extension found. Did you forget to install contao/tcpdf-bundle?');
  		}
  
  		// HOOK: allow individual PDF routines
  		if (isset($GLOBALS['TL_HOOKS']['printArticleAsPdf']) && \is_array($GLOBALS['TL_HOOKS']['printArticleAsPdf']))
  		{
  			foreach ($GLOBALS['TL_HOOKS']['printArticleAsPdf'] as $callback)
  			{
  				$this->import($callback[0]);
  				$this->{$callback[0]}->{$callback[1]}($strArticle, $this);
  			}
  		}
  	}
docs: Print an article as PDF and stream it to the browser