简体   繁体   中英

Page break using CSS in HTML to create PDF

I have a custom tag <PBR/> in HTML and I want to break page in PDF from this tag through CSS. But I have no idea about this. How can I break pages: I have tried this in CSS but it is not working --

pbr {
    page-break-before: always;
}

I think the trouble comes in targeting custom HTML tags with CSS.
I suggest using a class instead:

.page { page-break-before:always; }
<pbr class="page" />

Create a custom class with the following properties and apply to your HTML element.

<style>
    .breakhere {
                page-break-after: always;
                display: block;
                clear: both;
            }
</style>

<div class="breakhere">...content...</div>

Note: Make sure your HTML doesn't contain overflow tag, as it will create problem with page-break tags.

Rotativa library provides a good option to return View as PDF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM