Function to create a pdf for a given order using given templates.

@param ApiOrderInterface $apiOrder
@param string $templateHeaderPath
@param string $templateBasePath
@param string $templateMainPath
@param string $templateFooterPath

@return File
544756
public function createOrderPdfDynamically(
        ApiOrderInterface $apiOrder,
        $templateHeaderPath = null,
        $templateBasePath = null,
        $templateMainPath = null,
        $templateFooterPath = null
    ) {
        $data = $this->getContentForPdf($apiOrder);

        if ($templateHeaderPath === null) {
            $templateHeaderPath = $this->templateHeaderPath;
        }

        $header = $this->pdfManager->renderTemplate(
            $templateHeaderPath,
            []
        );

        if ($templateFooterPath === null) {
            $templateFooterPath = $this->templateFooterPath;
        }

        $footer = $this->pdfManager->renderTemplate(
            $templateFooterPath,
            []
        );

        if ($templateBasePath === null) {
            $templateBasePath = $this->templateConfirmationPath;
        }
        // Change the base template which will be extended to the confirmation template.
        $data['templateDynamicBasePath'] = $templateBasePath;

        if ($templateMainPath === null) {
            $templateMainPath = $this->templateDynamicPath;
        }

        $pdf = $this->pdfManager->convertToPdf(
            $templateMainPath,
            $data,
            false,
            [
                'footer-html' => $footer,
                'header-html' => $header
            ]
        );

        return $pdf;
    }
1015800
protected function renderTemplate(PdfTemplateTransfer $template)
    {
        $templateType = $template->getType();
        if ($templateType === PdfConfig::TEMPLATE_TYPE_RAW_HTML) {
            return $template->getRaw();
        }

        if (!array_key_exists($templateType, $this->templateRenderer)) {
            throw new TemplateRendererNotFoundException(
                sprintf('Template-renderer %s does not exist.', $templateType)
            );
        }

        $templateRenderer = $this->templateRenderer[$templateType];

        return $templateRenderer->render($template);
    }
1009324
public function generateFile($filename, $templateData, $templatePath = null)
    {
        $this->makeDirectory($this->rootPath);

        $path = $this->rootPath.$filename;

        if (is_null($templatePath)) {
            $templatePath = $this->templatePath;
        }
        
        $content = $this->generateContent($templatePath, $templateData);

        if (! file_exists($path)) {
            $this->fileHelper->put($path, $content);
            $this->command->info($filename.' created successfully.');
        } else {
            $this->command->info($filename.' already exists ... skipping.');
        }
    }
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;
	}
1246015
public function renderEntityTemplate(EntityTemplate $template, Entity $entity, $path)
    {
        $template->setEntity($entity);

        $fileCollection = new FileCollection();

        $entityPath = $path . $template->getPath();

        $entityName = $template->getFilename();

        if ($entity->shouldRender($template->getTemplateName())) {
            $fileCollection->add(new File($entityPath, $entityName, $template->render()));
        } else {
            $fileCollection->add(new NoFile($entityPath, $entityName, sprintf('The entity \'%s\' is should not have a \'%s\'.', $entity->getFullyQualifiedName(), $template->getTemplateName())));
        }

        return $fileCollection;
    }
636576
public function compile($templatePath, array $data, TemplateCompiler $compiler)
    {
        return $compiler->compile($this->file->get($templatePath), $data);
    }
15396
public function sendConfirmationEmail(
        $recipient,
        ApiOrderInterface $apiOrder,
        $templatePath,
        ContactInterface $customerContact = null
    ) {
        if (empty($recipient)) {
            $this->writeLog('No recipient specified.');

            return false;
        }

        $tmplData = array(
            'order' => $apiOrder,
            'contact' => $customerContact,
        );

        return $this->sendOrderMail($recipient, $templatePath, $tmplData, $apiOrder);
    }
486108
protected function loadTemplatePath($templatePath)
    {
        $templatePath = $this->path->getDir($templatePath);
        if (file_exists($templatePath)) {
            require $templatePath;
        }
        return $this;
    }
131901
protected function writeMainClientTemplate()
	{
		$data = $this->mainClientData;

		$filePath = $this->outputPath . DIRECTORY_SEPARATOR . 'ApiClient.php';

		if (!is_null($this->outputInterface)) {
			$this->outputInterface->writeln('<info>Writing ' . $filePath . '</info>');
		}

		file_put_contents($filePath, $this->mainClientTemplate->render($data));
	}
126452
public function copyTemplateAndGetPath(
        string $pathToProjectRoot,
        string $templatePath,
        string $destinationFileName,
        array $subDirectories
    ): string {
        try {
            $path = $this->createSubDirectoriesAndGetPath($pathToProjectRoot, $subDirectories);
            if (false === \ts\stringContains($destinationFileName, '.php')) {
                $destinationFileName = "$destinationFileName.php";
            }
            $filePath = "$path/$destinationFileName";
            $this->filesystem->copy($templatePath, $filePath, true);
            $this->fileCreationTransaction::setPathCreated($filePath);

            return $filePath;
        } catch (\Exception $e) {
            throw new DoctrineStaticMetaException(
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
                $e->getCode(),
                $e
            );
        }
    }
752286
private PdfPCell createFooterCell(Object val) throws VectorPrintException {
      try {
         return elementProducer.createElement(val, PdfPCell.class, getStylers(PAGEFOOTERSTYLEKEY));
      } catch (InstantiationException | IllegalAccessException ex) {
         throw new VectorPrintException(ex);
      }
   }
1011983
private function compileTemplate($templatePath, $destinationPath, $data = null)
    {
        if ($data == null) {
            $data = $destinationPath;
            $destinationPath = null;
        }
        
        if (! isset($this->templates[$templatePath])) {
            $this->templates[$templatePath] = file_get_contents($templatePath);
        }
        
        $compiled = preg_replace_callback('/{{\s*([A-z0-9_-]+)\s*}}/', function ($matches) use ($data) {
            if (isset($data[$matches[1]])) {
                return $data[$matches[1]];
            }
            
            return $matches[0];
        }, $this->templates[$templatePath]);
        
        if ($destinationPath) {
            file_put_contents($destinationPath, $compiled);
        }
        
        return $compiled;
    }
60765
private function composeTemplateContent(
        FileSystemInterface $fileSystem,
        string $templatePath,
        iterable $templateParams
    ): string {
        $templateContent = $fileSystem->read($templatePath);

        foreach ($templateParams as $key => $value) {
            $templateContent = str_replace($key, $value, $templateContent);
        }

        return $templateContent;
    }
1013832
function templateFile( $templateName )
    {
        if ( isset( $this->Templates[$templateName] ) )
        {
            return $this->Templates[$templateName]['filepath'];
        }
        return false;
    }
972842
public function addTemplateFile($urlOfFile,$templateFileType)
    {
        $file = new File($this->getContext(),$this->getResourcePath());
        $qry = new InvokePostMethodQuery(
            $this->getResourcePath(),
            "addTemplateFile",
            array(
                "urlOfFile" => $urlOfFile,
                "templateFileType" => (int)$templateFileType
            )
        );
        $this->getContext()->addQuery($qry,$file);
        return $file;
    }
752218
public function makeView($filePath, $templatePath, $data)
    {
        if(!file_exists(resource_path($filePath)))
        {
            $view =  View::file($templatePath, $data);
            file_put_contents(resource_path($filePath), str_replace(["<%", "%>", "#", "*"], ["{{", "}}", "@", "$"], $view->render()));
        }else{
            if($this->mode == "overwrite")
            {
                $view =  View::file($templatePath, $data);
                file_put_contents(resource_path($filePath), str_replace(["<%", "%>", "#", "*"], ["{{", "}}", "@", "$"], $view->render()));
            }
        }
    }
972557
public function make($templatePath, $templateData, $filePathToGenerate)
    {
        // We first need to compile the template,
        // according to the data that we provide.
        $template = $this->compile($templatePath, $templateData, new TemplateCompiler);

        // Now that we have the compiled template,
        // we can actually generate the file.
        $this->file->make($filePathToGenerate, $template);
    }