打印:如何将每页的页脚粘贴到底部?

Print: How to stick footer on every page to the bottom?(打印:如何将每页的页脚粘贴到底部?)
本文介绍了打印:如何将每页的页脚粘贴到底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试将生成的 HTML 文档打印为 PDF.文档本身可以包含多个页面.每个页面都是这样构建的:

I'm trying to print a generated HTML document to PDF. The document itself can hold multiple pages. Every page is built up like this:

<!-- Header -->

<!-- Content -->

<!-- Footer -->

这三个在每一页上看起来都很好.唯一的问题是页脚不会粘在底部......页脚将始终赶上页面的最后一个元素.只要页面填充了足够的内容,页脚就会像您期望的那样位于底部.

All three look fine on every page. The only problem is that the footer won't stick at the bottom... The footer will always catch up with the last element of the page. As long as the page is filled with enough content the footer will be at the bottom as you would expect it to be.

这是我的 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:

I've also tried to generate a separate CSS like this:

@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:

And of course I'm using the CSS like this:

<link rel="stylesheet" href="./main.min.css" media="all">

旁注:

  • 我只需要 Chrome 支持,因为我正在使用 electron 框架
  • 进行开发
  • 我正在使用这个:https://github.com/delight-im/HTML-Sheets-of-Paper CSS 文件使页面可见,就像它们将要打印给用户一样.
  • Logic 使用 Node.js 7.5 构建
  • I just need Chrome support, since I'm developing with the electron framework
  • I'm using this: https://github.com/delight-im/HTML-Sheets-of-Paper CSS files to make pages visible like they are going to be printed to the user.
  • Logic is built with Node.js 7.5

我做了一些研究并尝试了这些问题的答案,但没有成功:

I did some research and tried out the answers from these questions with no success:

  • 将自定义页脚粘贴到每页底部同时打印
  • 在打印时特定页面的底部
  • 如何使用 HTML 在文档的每个打印页面上打印页眉和页脚?

那么有没有可能用纯 CSS 来实现呢?如果没有,我还会构建一些逻辑来填充页脚上方的所有空白空间,直到页面达到其最大尺寸.

推荐答案

好的,由于某些奇怪的原因,解决方案非常简单.但是我已经改变了我的 CSS:

Ok, the solution was super easy for some strange reason. However I've changed my CSS from this:

.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;
}

到这里:

display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
    width: 100%;
    position: absolute;
    top: 27.7cm !important;
    padding-right: 2cm !important;

因为我知道 A4 页面不会超过 29.7cm,所以很容易将元素设置到底部,同时使用 top: 27.7cm

Since I know that a A4 page won't exceed 29.7cm it was easy to set the element to the bottom while making it absolute positioned coming from top with top: 27.7cm

这篇关于打印:如何将每页的页脚粘贴到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)