bithost-gmbh / pdfviewhelpers

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

How to get content into pdf? #205

Closed createdwithlove closed 2 years ago

createdwithlove commented 2 years ago

Maybe this question is too basic, but couldn't find an answer.

Given we have a page with some content on it and now wan't the visitor to be able to download this page as a pdf what will we have to do?

Currently we installed your EXT and load this typoscript setup https://gist.github.com/createdwithlove/43b3c84242484cedf1ced1de24a36150.

When calling /index.php?id=123&type= 1617455214 we get a PDF showing the content from the given template file. Doing an <f:debug>{_all}</f:debug> lists nothing else but the page data.

So what point are we missing to access and use the same data that was shown on the same page with type=0

maechler commented 2 years ago

@createdwithlove If you want to pass rendered content elements to the Fluid template you could use something like lib.dynamicContent. For your page type=0 you are likely doing something similar.

https://docs.typo3.org/c/typo3/cms-fluid-styled-content/11.5/en-us/FirstSteps/DisplayContent.html

<pdf:document>
    <pdf:page>
        <pdf:html>
            <f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '0'}" />
        </pdf:html>
    </pdf:page>
</pdf:document>

You could then additionally provide a CSS stylesheet tailored to the PDF rendering.

If you want to just use the exact same HTML that is generated for type=0 you would probably have to implement some hook or middleware to get the rendered HTML and then use the standalone rendering: https://docs.typo3.org/p/bithost-gmbh/pdfviewhelpers/main/en-us/Examples/StandaloneRendering/Index.html

I would however advice you not to do this as the TCPDF HTML renderer is far from being perfect and you are probably much better off with optimising your page for the browser print view, which is probably the best HTML to PDF converter available.

createdwithlove commented 2 years ago

Thank you @maechler for your help. Using the news example, I got a better understanding of how the functions of your extension are meant to work. If you have only worked with one page type so far and all content is "automatically" available, you have to rethink a bit here ;) As soon as I am sure that I have understood everything, I would send a PR with a supplement to the documentation and an example of such "dynamic" content.