我試圖將生成的HTML文檔打印爲PDF。文件本身可以容納多個頁面。每個頁面都是這樣構建的:打印:如何將頁面上的頁腳粘貼到底部?
<!-- Header -->
<!-- Content -->
<!-- Footer -->
這三個頁面在每個頁面上看起來都不錯。唯一的問題是頁腳不會粘在底部......頁腳會始終趕上頁面的最後一個元素。只要頁面中充滿了足夠的內容,頁腳就會像您期望的那樣位於底部。
這裏是我的CSS:
.docFooter{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
width: 100%;
position: absolute;
bottom: 0;
padding-right: 2cm;
padding-bottom: 1cm;
}
我也試着產生一個單獨的CSS是這樣的:
@media print{
.docFooter{
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
width: 100%;
position: absolute;
bottom: 0;
padding-right: 2cm;
padding-bottom: 1cm;
}
}
當然,我使用的CSS是這樣的:
<link rel="stylesheet" href="./main.min.css" media="all">
Sidenotes:
- 我只需要瀏覽器的支持,因爲我與
electron framework
- 開發我使用這個:https://github.com/delight-im/HTML-Sheets-of-Paper CSS文件,使頁面上看到像他們將要打印的用戶。
- 邏輯與Node.js的內置7.5
我做了一些研究,並嘗試了這些問題,但沒有成功的答案:
- Sticking custom footer on each page to bottom while printing
- make a div at the bottom of a specific page on printing
- How to use HTML to print header and footer on every printed page of a document?
那麼有可能以任何方式用普通的CSS來實現這一點?如果沒有,我還會構建一些邏輯來填充頁腳上方的所有空白空間,直到頁面達到其最大大小。