Renders the PDF and sends it to the browser as a download.

@param  string $sFilename The filename to give the PDF
@param  array  $aOptions  An array of options to pass to DomPDF's stream() method

@return void|bool
516232
public function download($sFilename = '', $aOptions = [])
    {
        $sFilename = $sFilename ? $sFilename : self::DEFAULT_FILE_NAME;

        //  Set the content attachment, by default send to the browser
        $aOptions['Attachment'] = 1;

        $this->oDomPdf->render();
        $this->oDomPdf->stream($sFilename, $aOptions);
        exit();
    }
547886
protected function renderOptions(array $options, $selection)
	{
		$html = '';

		foreach($options as $key => $val) {
			if(is_array($val) === false) {
				$selected = ($key == $selection) ? ' selected' : null;
				$html .= '<option value="' . $key . '"' . $selected . '>' . $val . '</option>';
			} else {
				$html .= '<optgroup label="' . $key . '">' . $this->renderOptions($val, $selection) . '</optgroup>';
			}
		}

		return $html;
	}
262333
public function save($strFilename) {
        if(file_exists($strFilename)) {
            unlink($strFilename);
        }
        
        $this->_objZip->addFromString('word/document.xml', $this->_documentXML);
        
        // Close zip file
        if($this->_objZip->close() === false) {
            throw new Exception('Could not close zip file.');
        }
        
        rename($this->_tempFileName, $strFilename);
    }
311900
public function saveAs($filename) {
    if (!$this->_isCreated && !$this->createPdf()) {
      return FALSE;
    }
    if (!$this->_tmpPdfFile->saveAs($filename)) {
      $this->_error = "Could not save PDF as '$filename'";
      return FALSE;
    }
    return TRUE;
  }
124236
protected function getSenderData(array $aOptions)
    {
        if (isset($aOptions['use_default_sender']) && $aOptions['use_default_sender']) {
            $sFromEmail = isset($this->aRendererConfig['mail_from_email'])
                ? $this->aRendererConfig['mail_from_email']
                : null;

            $sFromName = isset($this->aRendererConfig['mail_from_name'])
                ? $this->aRendererConfig['mail_from_name']
                : null;

            return [
                'email' => $sFromEmail,
                'name' => $sFromName,
            ];
        }

        $sFromEmail = isset($aOptions['sender_mail'])
            ? $aOptions['sender_mail']
            : null;

        $sFromName = isset($aOptions['sender_name'])
            ? $aOptions['sender_name']
            : null;

        return [
            'email' => $sFromEmail,
            'name' => $sFromName,
        ];
    }
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);
	}
585930
function stream( $options = '' )
    {
        // setting the options allows the adjustment of the headers
        // values at the moment are:
        // 'Content-Disposition'=>'filename'  - sets the filename, though not too sure how well this will
        //        work as in my trial the browser seems to use the filename of the php file with .pdf on the end
        // 'Accept-Ranges'=>1 or 0 - if this is not set to 1, then this header is not included, off by default
        //    this header seems to have caused some problems despite tha fact that it is supposed to solve
        //    them, so I am leaving it off by default.
        // 'compress'=> 1 or 0 - apply content stream compression, this is on (1) by default
        if ( !is_array( $options ) )
        {
            $options = array();
        }
        if ( isset( $options['compress'] ) && $options['compress'] == 0 )
        {
            $tmp = $this->output( 1 );
        }
        else
        {
            $tmp = $this->output();
        }
        $tmp = ltrim( $tmp );

        ob_clean();

        header( 'Pragma: ' );
        header( 'Cache-Control: ' );
        /* Set cache time out to 10 seconds, this should be good enough to work around an IE bug */
        header( "Expires: ". gmdate( 'D, d M Y H:i:s', time() + 10 ) . ' GMT' );
        header( 'X-Powered-By: eZ Publish' );

        header( 'Content-Length: '.strlen( $tmp ) );
        header( 'Content-Type: application/pdf' );
        header( 'Content-Transfer-Encoding: binary' );
        header( 'Accept-Ranges: bytes' );

        ob_end_clean();

        echo $tmp;

        eZExecution::cleanExit();
    }
1357805
function (oEvent) {
				var oSelectedItem = oEvent.getParameters().selectedItem,
					oListItem = oSelectedItem ? oSelectedItem : oEvent.getSource().getParent();

				this._oDownloadButton.setBusy(true);
				sap.ui.require([
					"sap/ui/core/util/File",
					"sap/ui/thirdparty/jszip"
				], function (File, JSZip) {
					var oZipFile = new JSZip();

					// load the config file from the custom data attached to the list item
					jQuery.getJSON(oListItem.data("config"), function (oConfig) {
						var aFiles = oConfig.files,
							aPromises = [],
							aFails = [];

						// add extra download files
						aFiles.forEach(function(sFilePath) {
							var oPromise = sourceFileDownloader(oConfig.cwd + sFilePath);

							oPromise.then(function (oContent) {
								if (oContent.errorMessage) {
									// promise gets resolved in error case since Promise.all will not wait for all fails
									aFails.push(oContent.errorMessage);
								} else {
									// exclude relative paths outside of the app root (e.g. common helpers, images, ...)
									if (!sFilePath.startsWith("../")) {
										oZipFile.file(sFilePath, oContent, { base64: false, binary: true });
									}
								}
							});
							aPromises.push(oPromise);
						});

						// add generic license and notice file
						var oLicensePromise = sourceFileDownloader(sap.ui.require.toUrl("sap/ui/documentation/sdk/tmpl/LICENSE.txt"));
						oLicensePromise.then(function (oContent) {
							oZipFile.file("LICENSE.txt", oContent, { base64: false, binary: true });
						});
						aPromises.push(oLicensePromise);
						var oNoticePromise = sourceFileDownloader(sap.ui.require.toUrl("sap/ui/documentation/sdk/tmpl/NOTICE.txt"));
						oNoticePromise.then(function (oContent) {
							oZipFile.file("NOTICE.txt", oContent, { base64: false, binary: true });
						});
						aPromises.push(oNoticePromise);

						Promise.all(aPromises).then(function () {
							// collect errors and show them
							if (aFails.length) {
								var sCompleteErrorMessage = aFails.reduce(function (sErrorMessage, sError) {
									return sErrorMessage + sError + "\n";
								}, "Could not locate the following download files:\n");
								this._handleError(sCompleteErrorMessage);
							}

							// show success message
							this._oDownloadButton.setBusy(false);
							MessageToast.show("Downloading for app \"" + oListItem.getLabel() + "\" has been started");

							// still make the available files ready for download
							var oContent = oZipFile.generate({type:"blob"});
							this._createArchive(File, oContent, oListItem.getLabel());
						}.bind(this));
					}.bind(this));
				}.bind(this));
			}
721816
public function stream_open($aPath, $aMode, $aOptions, &$aOpenedPath)
    {
        $this->path = substr($aPath, 9);
        if (!isset(self::$string[$this->path])) {
            self::$string[$this->path] = '';
        }
        $this->options = $aOptions;
        $aOpenedPath = $this->path;
        $lenght = strlen(self::$string[$this->path]);
        $flags = [
            'r' => [true, false, 0],
            'rb' => [true, false, 0],
            'r+' => [true, true, 0],
            'c+' => [true, true, 0],
            'w' => [false, true, 0],
            'wb' => [false, true, 0],
            'w+' => [true, true, 0],
            'a' => [false, true, $lenght],
            'a+' => [true, true, $lenght],
            'c' => [false, true, 0]
        ];

        if (isset($flags[$aMode])) {
            $flag = $flags[$aMode];
            $this->setFlags($flag[0], $flag[1], $flag[2]);
        } else {
            throw new exceptions\StringStreamException("Unknown stream mode '{$aMode}'");
        }

        if ($aMode === 'w+') {
            $this->stream_truncate(0);
        }

        return true;
    }
1070928
public function createDb(array $aOptions = array())
    {
        /**
         * option -a [indicated the sql json file]
         */

        if (isset($aOptions['a'])) { $sSqlJsonFile = $aOptions['a']; }
        else { $sSqlJsonFile = false; }

        /**
         * option -b [indicated the sql json]
         */

        if (isset($aOptions['b'])) { $sSqlJson = $aOptions['b']; }
        else { $sSqlJson = false; $sSqlJsonFile = str_replace('Batch', '', __DIR__).'Db.conf'; }

        /**
         * option -i [indicated the const json file to manage annotation in files]
         */

        if (isset($aOptions['i'])) { $oConstJson = json_decode(file_get_contents($aOptions['i']));}
        else { $oConstJson = '../Const.conf'; }

        if (is_object($oConstJson)) {

            foreach ($oConstJson as $sKey => $mValue) {

                if (is_string($mValue) || is_int($mValue) || is_float($mValue)) {

                    if (!defined(strtoupper($sKey))) { define(strtoupper($sKey), $mValue); }
                }
            }
        }

        if ($sSqlJsonFile !== false) { $oJson = json_decode(file_get_contents($sSqlJsonFile)); }
        else { $oJson = json_decode($sSqlJson); }

        $oConnection = $oJson->configuration;

        $oContainer = new DbContainer;

        $oContainer->setHost($oConnection->host)
            ->setName($oConnection->db)
            ->setPassword($oConnection->password)
            ->setType($oConnection->type)
            ->setUser($oConnection->user);

        $oPdo = Db::connect($oContainer);

        $oPdo->query("CREATE DATABASE ".$oConnection->db);

        echo "\n\n";
        echo Bash::setBackground("                                                                            ", 'green');
        echo Bash::setBackground("          [OK] Success                                                      ", 'green');
        echo Bash::setBackground("                                                                            ", 'green');
        echo "\n\n";
    }
977189
public function outputWithHeaders($filename = 'output.xls')
    {
        \header("Expires: " . date("r", 0));
        \header("Last-Modified: " . gmdate("r") . " GMT");
        \header("Content-Type: application/x-msexcel");
        \header("Content-Disposition: attachment; filename=" . $filename);
        echo $this->__toString();
    }
443229
public static function createXmlDocumentFromFile($filename, $docOptions = XMLUTIL_OPT_DONT_FIX_AMPERSAND)
    {
        if (!file_exists($filename)) {
            throw new XmlUtilException("Xml document $filename not found.", 250);
        }
        $xml = file_get_contents($filename);
        $xmldoc = self::createXmlDocumentFromStr($xml, $docOptions);
        return $xmldoc;
    }
904296
private function setJavascriptFileCDNjQueryLibs($jsFileName)
    {
        $sFN    = $this->sanitizeString($jsFileName);
        $eArray = $this->knownCloudFlareJavascript($sFN);
        if (!is_null($eArray['version'])) {
            return [
                true,
                $this->sCloundFlareUrl . $eArray['version'] . $eArray['justFile'],
                '<script>' . $eArray['eVerify'] . ' || document.write(\'<script src="' . $sFN
                . '">\x3C/script>\')</script>',
            ];
        }
        return null;
    }
1358320
public function render($filename, $data)
    {
        $html = Twig::render($filename, $data);

        $dir = sys_get_temp_dir()."/dompdf";

        $options = new Options();
        $options->setIsRemoteEnabled(true);
        $options->setFontDir($this->resolveDirectory($dir."/lib/fonts"));
        $options->setFontCache($this->resolveDirectory($dir."/lib/fonts"));
        //$options->setRootDir($this->resolveDirectory($dir));
        //$options->setChroot($this->resolveDirectory($dir));
        $dompdf = new Dompdf($options);

        $dompdf->loadHtml($html);
        $dompdf->render();

        return $dompdf->output();
    }
672517
public function download($fileName)
    {
        header("Content-Type: text/tab-separated-values; charset={$this->getHeaderCharset()}");
        header("Content-Disposition: attachment; filename={$fileName}");

        echo $this->createOutputContents(
                        $this->header,
                        $this->delimiter4Tsv,
                        $this->enclosure,
                        $this->toConvert
                    );
    }
165260
public function afterRender($filename) {
		$msgs = CakeSession::read('Alerts');
		
		if(empty($msgs)){
			return;
		}
		$out = array();
		$out[]= '<script type="text/javascript">';
		foreach($msgs as $msg){

			$out[] = sprintf('Rita.Alert.%s("%s");',$msg['type'],$msg['msg']);
		}
		$out[]= '</script>';
		$out = implode(' ',$out);
		
		$this->getView()->append('content',$out);
		CakeSession::write('Alerts',array());
	}
1085389
public function save( $fileName )
	{
		$svg	= $this->encapsulate( $this->content );
		$doc	= new DOMDocument();
		$doc->preserveWhiteSpace = false; 
		$doc->formatOutput = true;
		$doc->loadXml( $svg );
		$svg	= $doc->saveXml();
		return FS_File_Writer::save( $fileName, $svg );
	}