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;
    }