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

AvoidPageBreakInsideViewhelper not working in HtmlViewHelper #176

Closed butu closed 3 years ago

butu commented 4 years ago

Describe the bug I need the AvoidPageBreakInsideViewhelper inside a HtmlViewHelper. But the content in the AvoidPageBreakInsideViewhelper gets deleted and is not rendered at all.

Environment TYPO3 version(s): 8.7.32 pdfviewhelpers version: 2.3.4

Steps to reproduce `

Content that is rendered

Content that is not rendered

` **Expected behavior** The content should be rendered and Pagebreak should be avoided. **Possible solution** I think the problem is in the height calculation when rendering with and without the content of avoidPageBreakInside. But I am not sure.
maechler commented 4 years ago

@butu Thanks for this well written error report!

Unfortunately I think there is no easy fix for this, as this ViewHelper is not meant to be used in that way. It is meant to wrap a composition of EXT:pdfviewhelper ViewHelpers but can not be used inside an HtmlViewHelper.

A possible workaround for you could be to split your content into multiple calls to pdf:html like this:

<pdf:document>
    <pdf:page importPage="1" autoPageBreak="1" margin="{top:50, right:20, bottom:20, left:20}">
        <pdf:html padding="{left:2}"> <p>Content that is rendered</p> </pdf:html> 
        <pdf:avoidPageBreakInside>
            <pdf:html padding="{left:2}"> <p>Content that is now also rendered</p> </pdf:html> 
       </pdf:avoidPageBreakInside> 
    </pdf:page> 
</pdf:document>

Does that work for you?

maechler commented 4 years ago

@butu Could you test the proposed workaround? Or did you find another way for you to make it work?

maechler commented 3 years ago

Closing because of no response. If you think this is a mistake, please let me know.

butu commented 3 years ago

I am sorry for not responding, but unfortunately the workaround is not an option in my case, because the PDF is splitted in many partials. I would have to open the avoidPageBreakInside Viewhelper in one partial and close it in another, which is not valid. Hard to explain. Is there no chance to add this feature? Depending on the costs, our client may be willing to fund this new feature :)

maechler commented 3 years ago

Adding such a feature would probably have a big impact on performance, complexity and rendering behaviour of the HTMLViewHelper. At the moment the rendering of the HTMLViewHelper happens in two phases:

1) Render all children to an HTML string. At this stage AvoidPageBreakInsideViewHelper is already called if nested.

2) Pass this string to TCPDF::writeHTML method. Within this method TCPDF parses the HTML and splits it into many rendering calls. This rendering is out of control of the HTMLViewHelper.

The only solution I see to support this feature, would be for the HTMLViewHelper and AvoidPageBreakInsideViewHelper to disable the compilation of the template, giving it access to its child nodes. We would then have to call TCPDF::writeHTML for each child node separately. In addition the AvoidPageBreakInsideViewHelper would have to be aware of being surrounded by an HTMLViewHelper to be able to render its children as HTML as well. All this would have a significant impact on performance, complexity and rendering behaviour.

Long story short

I do not think adding this would be a good idea, I might however have come across a solution for you nevertheless. TCPDF has a hidden feature for its HTML rendering, you could try to wrap your content with a div with a nobr="true" attribute.

<div nobr="true"> .. your stuff here ... </div>

See: https://sourceforge.net/p/tcpdf/discussion/435311/thread/b8727cd3/

I have never tested it, but it might be doing exactly what you need.

butu commented 3 years ago

Thank you for the input and your help! I will try this!

maechler commented 3 years ago

@butu No worries, would be nice if you could tell us whether this solved your issue or not as soon as you tested it. And if you like the extension, please consider giving it a star on GitHub (:

butu commented 3 years ago

@maechler It worked, does exactly what I needed! Thank you, very much! :)