RenderedDocument example

$config->merge([
                    'documentDate' => $operation->getConfig()['documentDate'] ?? $now,
                    'documentNumber' => $number,
                    'custom' => [
                        'stornoNumber' => $number,
                        'invoiceNumber' => $referenceDocumentNumber,
                    ],
                ]);

                if ($operation->isStatic()) {
                    $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                    $result->addSuccess($orderId$doc);

                    continue;
                }

                /** @var LocaleEntity $locale */
                $locale = $order->getLanguage()->getLocale();
                $html = $this->documentTemplateRenderer->render(
                    $template,
                    [
                        'order' => $order,
                        
/** @var DocumentEntity $document */
            $document = $documents->first();

            $documentMediaId = $this->ensureDocumentMediaFileGenerated($document$context);

            if ($documentMediaId === null) {
                return null;
            }

            $fileBlob = $context->scope(Context::SYSTEM_SCOPE, fn (Context $context): string => $this->mediaService->loadFile($documentMediaId$context));

            $renderedDocument = new RenderedDocument('', '', $fileName);
            $renderedDocument->setContent($fileBlob);

            return $renderedDocument;
        }

        $totalPage = 0;
        foreach ($documents as $document) {
            $documentMediaId = $this->ensureDocumentMediaFileGenerated($document$context);

            if ($documentMediaId === null) {
                continue;
            }
'orderId' => Uuid::fromHexToBytes($orderId), 'documentTypeIds' => Uuid::fromHexToBytesList($eventConfig['documentTypeIds'])],
                ['documentTypeIds' => ArrayParameterType::STRING]
            )
            ->willReturn([
                ['doc_type' => 'foo', 'doc_id' => '1'],
                ['doc_type' => 'bar', 'doc_id' => '2'],
                ['doc_type' => 'foo', 'doc_id' => '3'],
                ['doc_type' => 'foo', 'doc_id' => $idC],
                ['doc_type' => 'bar', 'doc_id' => $idD],
            ]);

        $document = new RenderedDocument();
        $document->setContent('');
        $this->documentGenerator
            ->expects(static::exactly(4))
            ->method('readDocument')
            ->willReturn($document);

        $criteria = new Criteria($extension->getMediaIds());
        $criteria->setTitle('send-mail::load-media');
        $entities = array_map(static function Dstring $id): MediaEntity {
            $media = new MediaEntity();
            $media->setId($id);

            
public function getDecorated(): AbstractDocumentRenderer
    {
        throw new DecorationPatternException(self::class);
    }

    public function render(array $operations, Context $context, DocumentRendererConfig $rendererConfig): RendererResult
    {
        $result = new RendererResult();

        foreach ($operations as $operation) {
            $rendered = new RenderedDocument('<html>test</html>');
            $rendered->setName('custom.pdf');

            $result->addSuccess($operation->getOrderId()$rendered);
        }

        return $result;
    }
}


        $rendered = new RenderedDocument(
            $html,
            '1001',
            InvoiceRenderer::TYPE,
            FileTypes::PDF,
            ['displayFooter' => true]
        );

        static::assertStringContainsString('<html>', $rendered->getHtml());
        static::assertStringContainsString('</html>', $rendered->getHtml());
        static::assertStringContainsString('DOMPDF_PAGE_COUNT_PLACEHOLDER', $rendered->getHtml());

        
return null;
        }

        /** @var MediaEntity $documentMedia */
        $documentMedia = $document->getDocumentMediaFile();

        $fileBlob = $context->scope(Context::SYSTEM_SCOPE, fn (Context $context): string => $this->mediaService->loadFile($documentMediaId$context));

        $fileName = $documentMedia->getFileName() . '.' . $documentMedia->getFileExtension();
        $contentType = $documentMedia->getMimeType();

        $renderedDocument = new RenderedDocument();
        $renderedDocument->setContent($fileBlob);
        $renderedDocument->setName($fileName);
        $renderedDocument->setContentType($contentType);

        return $renderedDocument;
    }

    public function preview(string $documentType, DocumentGenerateOperation $operation, string $deepLinkCode, Context $context): RenderedDocument
    {
        $config = new DocumentRendererConfig();
        $config->deepLinkCode = $deepLinkCode;

        
$config->merge([
                    'documentDate' => $operation->getConfig()['documentDate'] ?? (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                    'documentNumber' => $number,
                    'custom' => [
                        'creditNoteNumber' => $number,
                        'invoiceNumber' => $referenceDocumentNumber,
                    ],
                ]);

                if ($operation->isStatic()) {
                    $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                    $result->addSuccess($orderId$doc);

                    continue;
                }

                $price = $this->calculatePrice($creditItems$order);

                /** @var LocaleEntity $locale */
                $locale = $order->getLanguage()->getLocale();

                $html = $this->documentTemplateRenderer->render(
                    
'documentDate' => $operation->getConfig()['documentDate'] ?? $now,
                        'documentNumber' => $number,
                        'custom' => [
                            'invoiceNumber' => $number,
                        ],
                    ]);

                    // create version of order to ensure the document stays the same even if the order changes                     $operation->setOrderVersionId($this->orderRepository->createVersion($orderId$context, 'document'));

                    if ($operation->isStatic()) {
                        $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                        $result->addSuccess($orderId$doc);

                        continue;
                    }

                    /** @var LocaleEntity $locale */
                    $locale = $order->getLanguage()->getLocale();

                    $html = $this->documentTemplateRenderer->render(
                        $template,
                        [
                            
$config->merge([
                        'documentNumber' => $number,
                        'documentDate' => $operation->getConfig()['documentDate'] ?? $now,
                        'custom' => [
                            'deliveryNoteNumber' => $number,
                            'deliveryDate' => $customConfig['deliveryDate'] ?? $now,
                            'deliveryNoteDate' => $customConfig['deliveryNoteDate'] ?? $now,
                        ],
                    ]);

                    if ($operation->isStatic()) {
                        $doc = new RenderedDocument('', $number$config->buildName()$operation->getFileType()$config->jsonSerialize());
                        $result->addSuccess($orderId$doc);

                        continue;
                    }

                    $deliveries = null;
                    if ($order->getDeliveries()) {
                        $deliveries = $order->getDeliveries()->first();
                    }

                    /** @var LocaleEntity $locale */
                    
Home | Imprint | This part of the site doesn't use cookies.