在wkhtmltopdf中添加分页符相关的CSS? [英] where to add page-break related css in wkhtmltopdf?

查看:1611
本文介绍了在wkhtmltopdf中添加分页符相关的CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上使用wkhtmltopdf 0.12.3.2。



我知道这个话题有很多问题和答案,但我仍然无法找到我的问题的答案;我不知道在哪里放置相应的CSS - 或者因为某些(其他)原因CSS不起作用:例如,我尝试将页面设置为将相关的CSS直接分解成我想呈现的html文件。我在< body> 中试图用< span class =break_here>< / span> code>:

 <! -  ...  - > 
< head>
< style>
span.break_here {
page-break-after:always!important;
}
< / style>
< / head>
<! - ... - >

这并没有做任何事。

然后我也尝试将它放入 @media print {} @media screen {} 任何东西:

 < style> 
@media screen {
span.break_here {
page-break-after:always!important;
}
}
< / style>

感谢您的任何帮助!

edit:通过为使用外部样式表添加 - 用户样式表选项还有另一种可能性。

解决方案

通过wkhtmltopdf中的独立元素添加分页符也导致了我的问题。



我发现将分页符应用于包装内容的元素更可靠。




$ b

 < div>一些内容< / div> 
< div class =pagebreak>< / div>

鉴于此,诀窍在于:

 < div class =pagebreak>一些内容< / div> 

为了做到这一点,我没有使用 .pagebreak {分页符-after:always!important;}



但是,使用: .pagebreak {page-break-inside:避免!important;}



同样值得注意的是,print打印应该尽可能在dom-tree中高。将分页规则应用于深度嵌套的元素可能会导致头痛(至少对我来说是过去)



希望这有助于您!


I am using wkhtmltopdf 0.12.3.2 on Windows.

I know there are a lot of questions and answers around this topic, but I still can't find an answer to my problem; I don't know where to put the according CSS - or the CSS doesn't work for some (other) reason:

for example i tried to put the page-break related CSS directly into my html file which i want to render. i tried to force page-breaks with <span class="break_here"></span> in my <body>:

<!-- ... -->
<head>
    <style>
        span.break_here {
            page-break-after: always !important;
        }
    </style>
</head>
<!-- ... -->

this didn't do anything.

then i also tried to put it into @media print{} or @media screen{} which did not change anything either:

<style>
    @media screen{
        span.break_here {
            page-break-after: always !important;
        }
    }
</style>

thanks for any help!

edit: there is even another possibility by adding the --user-style-sheet option for using an external stylesheet.

解决方案

Adding pagebreaks via a standalone element in wkhtmltopdf has caused me problems as well.

I've found that applying the pagebreaks to an element which wraps the contents to be much more reliable.

This doesn't work so well:

<div>some content</div>
<div class="pagebreak"></div>

Whereas this does the trick:

<div class="pagebreak">some content</div>

To make this work, I did not use .pagebreak{page-break-after: always!important;}

But, instead used: .pagebreak{page-break-inside: avoid!important;}

It's also good to note that pagebreaks on print should be as high-up in the dom-tree as possible. Applying pagebreak rules to elements that are deeply nested can cause headaches (or at least has for me in the past)

Hope this helps!

这篇关于在wkhtmltopdf中添加分页符相关的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆