bithost-gmbh / pdfviewhelpers

TYPO3 CMS extension that provides various Fluid ViewHelpers to generate PDF documents.
GNU General Public License v3.0
44 stars 20 forks source link

Use in controller #241

Closed ste101 closed 7 months ago

ste101 commented 7 months ago

TCPDF and fpdi can be used in a controller also:

        $pdf = new \Bithost\Pdfviewhelpers\Model\BasePDF();
        $fileAsString = $pdf->Output($fileName, 'S');
        return $this->responseFactory
            ->createResponse()
            ->withHeader('Content-Type', 'application/pdf; charset=utf-8')
            ->withHeader('Content-Disposition', 'filename="' . rawurlencode($fileName) . '"')
            ->withHeader('Content-Length', (string)strlen($fileAsString))
            ->withHeader('X-Robots-Tag', 'noindex,nofollow')
            ->withBody($this->streamFactory->createStream($fileAsString));

Maybe you could add this information to the documentation.

maechler commented 7 months ago

@ste101 I am not sure about your use case, but it looks like you could use a Fluid standalone view to render the PDF. You can also use output destination inline in order to set the Content-Type header and send the result to the client. I don't see a reason to create a BasePDF directly as you lose all the features provided by the numerous ViewHelpers. But maybe I am missing something, if so please elaborate on your use case.

Please see: https://docs.typo3.org/p/bithost-gmbh/pdfviewhelpers/main/en-us/Examples/StandaloneRendering/Index.html

ste101 commented 7 months ago

I tried to use it without any overhead and it is working. Thank you for this great extension.

maechler commented 7 months ago

@ste101 Great, thanks for letting me know! Glad to hear you like the extension, please consider giving it a star :)