@param string $pdf_profile
@param string $document_content
@param string $output_path

@return bool
499346
public function generateWithDocraptor( $pdf_profile, $document_content, $output_path ) {
		// Configure service
		$configuration = \DocRaptor\Configuration::getDefaultConfiguration();
		$configuration->setUsername( DOCRAPTOR_API_KEY );

		// Save PDF as file in exports folder
		$docraptor = new \DocRaptor\DocApi();
		$prince_options = new \DocRaptor\PrinceOptions();
		$prince_options->setHttpTimeout( max( ini_get( 'max_execution_time' ), 30 ) );
		$prince_options->setProfile( $pdf_profile );
		$retval = false;

		try {
			$doc = new \DocRaptor\Doc();
			if ( defined( 'WP_TESTS_MULTISITE' ) ) {
				// Unit tests
				$doc->setTest( true );
			} elseif ( defined( 'WP_ENV' ) && ( WP_ENV === 'development' ) ) {
				// Localhost
				$doc->setTest( true );
			} else {
				$doc->setTest( false );
			}
			$doc->setDocumentContent( $document_content );
			$doc->setName( get_bloginfo( 'name' ) . ' Cover' );
			$doc->setPrinceOptions( $prince_options );

			$create_response = $docraptor->createAsyncDoc( $doc );
			$done = false;
			while ( ! $done ) {
				$status_response = $docraptor->getAsyncDocStatus( $create_response->getStatusId() );
				switch ( $status_response->getStatus() ) {
					case 'completed':
						if ( ! function_exists( 'download_url' ) ) {
							require_once( ABSPATH . 'wp-admin/includes/file.php' );
						}
						$result = \download_url( $status_response->getDownloadUrl() );
						if ( is_wp_error( $result ) ) {
							\Pressbooks\add_error( __( 'Your PDF could not be retrieved.', 'pressbooks' ) );
						} else {
							copy( $result, $output_path );
							unlink( $result );
							$retval = true;
						}
						$done = true;
						break;
					case 'failed':
						wp_die( $status_response );
						$done = true;
						break;
					default:
						sleep( 1 );
				}
			}
		} catch ( \DocRaptor\ApiException $exception ) {
			$message = "<h1>{$exception->getMessage()}</h1><p>{$exception->getCode()}</p><p>{$exception->getResponseBody()}</p>";
			wp_die( $message );
		}

		return $retval;
	}
1073580
protected function getOutput($test, $outputFolder, $extension)
    {
        if (empty($outputFolder)) {
            return;
        }

        $file = replace_suite_paths($test->suite, make_path([
            make_path([$test->suite->project->path, $outputFolder]),
            str_replace(['.php', '::', '\\', '/'], ['', '.', '', ''], $test->name).$extension,
        ]));

        return file_exists($file) ? $this->renderHtml(file_get_contents($file)) : null;
    }
263846
public function joinPDFs(array $PDFPaths, $outputDestination = null)
    {
        foreach ($PDFPaths as $key => $PDFPath) {
            if ($key > 0) {
                $this->joinTwoPDFs($PDFPaths[$key - 1], $PDFPath, $outputDestination);
            }
        }
    }
298834
public function filePutContents($path, $content, $flags = 0)
    {
        if (! $this->isFile($path) && !$this->createFile($path))
            return false;
        if (($flags & FILE_APPEND) == FILE_APPEND)
            $this->at($path)->content .= $content;
        else
            $this->at($path)->content = $content;
        return true;
    }
949842
public function generate() {
		$output_path = $this->timestampedFileName( 'pdf' );
		$this->generateWithDocraptor( $this->pdfProfile, $this->generateHtml(), $output_path );
		delete_transient( 'dirsize_cache' ); /** @see get_dirsize() */
		return $output_path;
	}
611006
def on_output_directory_chooser_clicked(self):
        """"""
        title = self.tr('Set the output directory for pdf report files')
        self.choose_directory(self.output_directory, title)
255587
public function output()
    {
        $orientation = $this->_Pdf->orientation() === 'landscape' ? 'L' : 'P';
        $format = $this->_Pdf->pageSize();
        if (is_string($format)
            && $orientation === 'L'
            && strpos($format, '-L') === false
        ) {
            $format .= '-' . $orientation;
        }

        $options = [
            'mode' => $this->_Pdf->encoding(),
            'format' => $format,
            'orientation' => $orientation,
            'tempDir' => TMP,
        ];
        $options = array_merge($options, (array)$this->getConfig('options'));

        $Mpdf = $this->_createInstance($options);
        $Mpdf->WriteHTML($this->_Pdf->html());

        return $Mpdf->Output('', Destination::STRING_RETURN);
    }
274
public function joinTwoPDFs($firstPDFPath, $secondPDFPath, $outputDestination = null)
    {
        $firstPDF = new \PDFDoc($firstPDFPath);
        $firstPDF->InitSecurityHandler();

        $secondPDF = new \PDFDoc($secondPDFPath);
        $firstPDF->InsertPages(1, $secondPDF, 1, $secondPDF->GetPageCount(), \PDFDoc::e_none);
        $secondPDF->Close();

        if (!empty($outputDestination)) {
            $firstPDF->Save($outputDestination, \SDFDoc::e_remove_unused);
        } else {
            $firstPDF->Save($firstPDFPath, \SDFDoc::e_remove_unused);
        }

    }
235883
public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf', $orientation = null, $meta = [])
    {
        if (!isset($this->_files) || !is_array($this->_files)) {
            throw new Exception("No PDFs to merge.");
        }

        $fpdi = new TCPDI;
        $fpdi->setPrintHeader(false);
        $fpdi->setPrintFooter(false);
        
        // setting the meta tags
        if (!empty($meta)) {
            $this->setMeta($meta);
        }

        // merger operations
        foreach ($this->_files as $file) {
            $filename  = $file[0];
            $filepages = $file[1];
            $fileorientation = (!is_null($file[2])) ? $file[2] : $orientation;

            $count = $fpdi->setSourceFile($filename);

            //add the pages
            if ($filepages == 'all') {
                for ($i=1; $i<=$count; $i++) {
                    $template   = $fpdi->importPage($i);
                    $size       = $fpdi->getTemplateSize($template);

                    if($orientation==null)$fileorientation=$size['w']< $size['h']?'P' : 'L';
                    
                    $fpdi->AddPage($fileorientation, array($size['w'], $size['h']));
                    $fpdi->useTemplate($template);
                }
            } else {
                foreach ($filepages as $page) {
                    if (!$template = $fpdi->importPage($page)) {
                        throw new Exception("Could not load page '$page' in PDF '$filename'. Check that the page exists.");
                    }
                    $size = $fpdi->getTemplateSize($template);

                    if($orientation==null)$fileorientation=$size['w']< $size['h']?'P' : 'L';
                    
                    $fpdi->AddPage($fileorientation, array($size['w'], $size['h']));
                    $fpdi->useTemplate($template);
                }
            }
        }

        //output operations
        $mode = $this->_switchmode($outputmode);

        if ($mode == 'S') {
            return $fpdi->Output($outputpath, 'S');
        } else {
            if ($fpdi->Output($outputpath, $mode) == '') {
                return true;
            } else {
                throw new Exception("Error outputting PDF to '$outputmode'.");
                return false;
            }
        }


    }
798045
function outputOutput(output, cb) {
    cb = u.maybe(cb);

    if (!output) return cb(new Error('no output specified'));

    debug('output %s', output.name);
    var files = output.files = [];

    var omit = output.omitRoutes;
    if (omit && !u.isArray(omit)) { omit = [omit]; }

    // TODO: re-use similar filter in server/serve-statics and server/serve-scripts
    var filterRe = new RegExp( '^(/admin/|/server/' +
                (opts.editor ? '' : '|/pub/') +
                       (omit ? '|' + u.map(omit, u.escapeRegExp).join('|') : '') +
                               ')');

    // pass1: collect files to generate (not /server or /admin or /pub)
    u.each(generator.pages, function(page) {
      if (filterRe.test(page._href)) return;
      if (output.match && !output.match(page)) return;
      var file = { page: page, path: page._href };
      if (page['http-header']) { file['http-header'] = page['http-header']; }
      files.push(file);
    });

    // pass2:
    fixOutputPaths(output, files);

    // pass3: generate using (possibly modified) file paths for relPaths
    // E.g. /adobe may live in the file /adobe/index.html so the relPath is '..'
    u.each(files, function(file) {
      var renderOpts =
        output.relPaths   ? { relPath:u.relPath(file.path) } :
        output.staticRoot ? { relPath:output.staticRoot } :
        opts.relPaths     ? { relPath:u.relPath(file.path) } :
        opts.staticRoot   ? { relPath:opts.staticRoot } :
        {};
      if (output.fqImages) { renderOpts.fqImages = output.fqImages; }
      file.text = generator.renderDoc(file.page, renderOpts);
      delete file.page;
    });

    output.src.put(files, cb);
  }
57059
protected function _profilerRenderEcho()
    {
        $output = PHP_EOL;
        foreach ($this->_bufferInfo as $key => $mark) {
            $output .= "\t" . self::_profilerFormatMark($mark) . PHP_EOL;
        }
        $this->_dumpRenderLite($output, '! profiler !');
    }
1280440
public static function write($file_path = null, $content, $type = 'a', $force = false, array &$logs = array())
    {
        if (is_null($file_path)) {
            return null;
        }
        if (!file_exists($file_path)) {
            if (true===$force) {
                self::touch($file_path, $logs);
            } else {
                $logs[] = sprintf('File path "%s" to copy was not found.', $file_path);
                return false;
            }
        }
        if (is_writable($file_path)) {
            $h = fopen($file_path, $type);
            if (false !== fwrite($h, $content)) {
                fclose($h);
                return true;
            }
        }
        $logs[] = sprintf('Can not write in file "%s".', $file_path);
        return false;
    }
422287
protected function publish(InputInterface $input, OutputInterface $output, $profile_name) {
        $output->writeln('<info>Publishing to '.$profile_name.'...</info>');
        $parser = new Parser();
        $profile_config = $parser->parse(file_get_contents('deployement/publish_'.$profile_name.'.yml'));

        if(!CommandUtils::checkCommand('rsync')) {
            $output->writeln('<error>rsync not installed, please install it. Exiting now...</error>');
            return 1;
        }
        if($profile_config['use_pem']) {
            $command = 'rsync -rltDvze "ssh -i '.$profile_config['pem_path'].'" ';
        }
        else {
            $command = 'rsync -rltDvz ';
        }

        $is_full = $input->getOption('full');
        if(!$is_full) {
            foreach ($profile_config['exclude'] as $exclude) {
                $command .= '--exclude \'' . $exclude . '\' ';
            }
        }

        if(substr($profile_config['remote_dir'],-1,1) != '/') {
            $profile_config['remote_dir'] .= '/';
        }

        $command .= '. '.$profile_config['username'].'@'.$profile_config['host'].':'.$profile_config['remote_dir'];


        $chmod = array(
            'chown -R '.$profile_config['username'].':'.$profile_config['remote_group'].' '.$profile_config['remote_dir'],
            'chmod -R 750 '.$profile_config['remote_dir'],
            'chmod -R 770 '.$profile_config['remote_dir'].'app/logs',
            'chmod -R 770 '.$profile_config['remote_dir'].'app/proxies',
            'chmod -R 770 '.$profile_config['remote_dir'].'app/public',
            'chmod -R 770 '.$profile_config['remote_dir'].'app/tmp'
        );

        $permissions_commands = 'ssh '
            .($profile_config['use_pem']?'-i '.$profile_config['pem_path']:'')
            .' '
            .$profile_config['username']
            .'@'
            .$profile_config['host']
            .' '
            .($profile_config['use_sudo']?'sudo':'')
            .' \'';
        foreach($chmod as $c) {
                $permissions_commands .= $c. ' && ';
        }
        $permissions_commands = substr($permissions_commands, 0, -3);
        $permissions_commands .= '\'';

        // PUBLISH
        $dump_commands = $input->getOption('dump-commands');
        if($dump_commands) {
            $output->writeln($command);
        }
        else {
            $output->writeln('Publishing with rsync, please wait (it may take a while)...');
            passthru($command);
            $output->writeln('<info>PUBLISH DONE</info>');
        }

        // OPTIMIZE
        $run_optimize = $profile_config['always_run_optimize'];
        if($run_optimize) {
            $output->writeln('Run optimizations...');
            $command = 'ssh '
                .($profile_config['use_pem']?'-i '.$profile_config['pem_path']:'')
                .' '
                .$profile_config['username']
                .'@'
                .$profile_config['host']
                .' '
                .'\'cd '.$profile_config['remote_dir'].' && vendor/bin/pff deploy:optimize\'';

            if($dump_commands) {
                $output->writeln($command);
            }
            else {
                passthru($command);
            }
            $output->writeln('<info>OPTIMIZE DONE</info>');
        }

        // PERMISSIONS
        $output->writeln('Setting permissions...');
        if($dump_commands) {
            $output->writeln($permissions_commands);
        }
        else {
            passthru($permissions_commands);
        }
        $output->writeln('<info>PERMISSIONS DONE</info>');

    }
1349400
public function echoPdfContent($content, $filename, $download = false)
    {
        // \MUtil_Echo::track($filename);
        if ($download) {
            // Download & save
			header('Content-Type: application/x-download');
        } else {
            //We send to a browser
            header('Content-Type: application/pdf');
        }
        header('Content-Length: '.strlen($content));
        header('Content-Disposition: inline; filename="'.$filename.'"');
        header('Cache-Control: private, max-age=0, must-revalidate');
        header('Pragma: public');

        echo $content;
    }
791149
public static function concat_pdf($path_array, $target_file_name, $multiple = false)
    {

        $cmd       = 'pdftk ';
        $cmd_files = '';
        $unique    = array();
        try {
            if (empty($path_array)) {
                throw new FileException((string)"\$path_array was empty", (int)Config::get('file_error'), (int)Config::get('error_lvl_low'), (string)__FILE__, (string)__LINE__);
            }

            foreach ($path_array as $pdf_file) {
                if (!file_exists($pdf_file) || in_array($pdf_file, $unique)) continue;
                if ($multiple === false) {
                    $unique[] = $pdf_file;
                }

                $cmd_files .= (string)" " . escapeshellarg(addslashes(stripslashes($pdf_file))) . " ";
            }

            unset($pdf_file);

            if (empty($cmd_files)) {
                throw new FileException((string)"No valid File within the whole array", (int)Config::get('file_error'), (int)Config::get('error_lvl_low'), (string)__FILE__, (string)__LINE__);
            }

            $cmd .= (string)$cmd_files;

            // so that the output wont be lost
            if (empty($target_file_name)) {
                $target_file_name = Config::get('storage_root') . "/" . Config::get('pdf_default_path') . "/concat_" . Tool::random_string(10) . ".pdf";
            }

            system($cmd . " cat output $target_file_name", $output);

            if (strpos(strtolower($output), 'err') !== false) {
                throw new FileException((string)"Error generating the pdf file $cmd\n$output", (int)Config::get('file_error'), (int)Config::get('error_lvl_low'), (string)__FILE__, (string)__LINE__);
            }
            unset($cmd, $output);
        } catch (FileException $e) {
            throw $e;
        }

        return true;
    }
690162
private function doPermChange(string $path, vfsStreamAbstractContent $content, callable $change): bool
    {
        if (!$content->isOwnedByUser(vfsStream::getCurrentUser())) {
            return false;
        }

        if (self::$root->getName() !== $path) {
            $names   = $this->splitPath($path);
            $parent = $this->getContent($names['dirname']);
            if (!$parent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {
                return false;
            }
        }

        $change();
        return true;
    }
950643
function applyOutputOptionsFromConfig() {

        $keyct = 1;
        $output_config = array();

        if ($this->pdf_engine == "tcpdf" && $this->target_format == "PDF" )
            $output_config = ReporticoApp::getConfig("output_sections_tcpdf");
        else
            $output_config = ReporticoApp::getConfig("output_sections");

        if ( $output_config )  {
            
            foreach ( $output_config as $k => $v ) {

                if ( $k == "page-header-block" ) {
                    
                    foreach ( $v as $header ) {
                    
                        $key = "AUTO$keyct";
                        $content = $header["content"];
                        if ( isset($header["content"]) )
                            $content .= "{STYLE {$header["styles"]}}";
                        $this->createPageHeader($key, 1, $content); 
                        $this->setPageHeaderAttribute($key, "ShowInHTML", "yes" );
                        $this->setPageHeaderAttribute($key, "ShowInPDF", "yes" );
                        $keyct++;
                        
                    }

                }
                
                if ( $k == "page-footer-block" ) {
                    
                    foreach ( $v as $footer ) {
                    
                        $key = "AUTO$keyct";
                        $content = $footer["content"];
                        if ( isset($footer["content"]) )
                            $content .= "{STYLE {$footer["styles"]}}";
                        $this->createPageFooter($key, 1, $content); 
                        $this->setPageFooterAttribute($key, "ShowInHTML", "yes" );
                        $this->setPageFooterAttribute($key, "ShowInPDF", "yes" );
                        $keyct++;
                        
                    }

                }

                if ( $k == "styles" ) {
                    
                    foreach ( $v as $type => $styleset ) {
                       $this->applyStyleset(strtoupper($type), $styleset["style"]); 
                    }

                }
            }
        }
    }