Where to insert HTML to control PDF page breaks?

Hi,

My question: where to I insert any HTML code to instruct a PDF-printer where to (avoid a) page break? Is it with a HTML-element, and if so - how do I target the div that I want to avoid from page-breaking?

Reason of question: I have an issue with avoiding page breaks after a header of large tables (1st screenshot below).

There are examples of how to instruct the PDF-printservice (in my case PDF.co) where to break and avoid to break (2nd screenshot below).

1 Like

Hey Thijs! :waving_hand:

Good question. Since WeWeb doesn’t render raw HTML directly, it’s not possible to inject classic print-specific HTML or CSS instructions like page-break-inside: avoid in the visual editor itself.

If you’re using a PDF service like PDF.co that reads those instructions, the limitation is that WeWeb doesn’t expose the raw markup where you could manually add tags or styles (like <div style="page-break-inside: avoid">...</div>).

That said, here are a couple of ideas you can try:

Group content in a Container: Sometimes wrapping the content you want to keep together (like a table header and its rows) in a single Container element can help maintain layout integrity when exported as PDF.

Use CSS classes if your PDF engine supports external stylesheets: If you’re exporting HTML from WeWeb before sending it to PDF.co, you might be able to apply custom styles like:

.avoid-break {
  page-break-inside: avoid;
  break-inside: avoid;
}

Then apply that class to the relevant wrapper div , but this would only be possible if you’re exporting HTML and have control before the PDF generation.

Post-processing workaround: If you’re generating the PDF outside WeWeb (e.g. via a backend), you could manipulate the HTML there before sending it to the PDF service and inject any needed styles or tags.

Let me know if any of them worked.

Hi @Agustin_Carozo ,

Thanks for you detailed suggestions!

On a positive note, I can confirm that a HTML-codeblock DOES make PDF.co understand where to break. That what got my hopes up to make PDF.co also understand when NOT to break. But the challenge is that I need some parts of dynamic lists within another dynamic list to not break, so I guess it’s not reasonable to expect from PDF.co to make a correct interpration on what containers not to break.

Question: would you say this might be something for Weweb to develop - to enable this use case of a PDF-template ?

Hi Thijs.

We haven’t had many users report they needed improvements in our PDF action.

But you can submit this idea / feedback and explain why you need it here:

Our CEO and developers sit down to discuss this sort of feedback weekly.

Hi @Agustin_Carozo ,

The PDF-action you’re referring to only allows for manual PDF-printing. But I’m looking for automated PDF-printing and storing.

I’ll submit a feature request. Thanks for you responses!

1 Like

This topic was automatically closed after 75 days. New replies are no longer allowed.