问题 HTML的所有页面底部的HTML页脚在IE中打印出来


我被要求在html网页的每个页面底部打印一个页脚(不是浏览器上的实际页面)。你们知道怎么办? (它应该适用于IE,只是IE很好)

我尝试使用固定底部,但内容与页脚重叠。

我尝试使用javascript计算空间并给出一个空div高度:使用if底部页面高度%!= 0,添加必需的差距。但是页脚底部的值和所需的空格似乎随着元素类型的变化而变化。

var printPageHeight = 1900; 
var mFooter = $("#footer-nt");
var bottomPos = mFooter.position().top + mFooter.height();


var remainingGap = (bottomPos <printPageHeight ) ? (printPageHeight -bottomPos) :       printPageHeight - (bottomPos % printPageHeight );


$("#whiteSpaceToPositionFooter").css("height", remainingGap+"px");

我尝试使用表格,适用于所有页面,除了最后一页。

我尝试了其他一些保证金和这样的调整,但他们也没有工作。

我实际上希望页脚只显示在打印输出的最后一页的底部,如果可能的话。


2248
2017-07-05 07:05


起源



答案:


如果其他人需要解决方案,我正在回答我自己的问题。

经过长时间的研究和密集尝试(主要是试验和错误),我使用以下逻辑将页脚设置在最后一页的底部: -

  1. 在css中:@media print {position:fixed;顶部:0;左:0; z-index -1; Ad IE将其显示在每个页面的底部,并通过z-index发送到后台。

  2. 尽管如此,IE中的文本背景在打印时仍然是透明的,因此文本位于页脚顶部。因此,在绝对左上角位置使用1px×1px的白色图像作为图像的背景。

  3. 使用javaScript设置图像的高度和宽度,与具有内容的div的高度相同。

HTML:

<body>
    <div id="wrapper"> <!-- not necessary -->
        <img scr="./img/white.png" id="whiteBg" />
        <div id="content">
            <!-- content here -->
        </div>
    </div>
    <div id="footer">
    </div>
</body>

CSS:

@media screen {
    #whiteBg {
        display: none;
    }
}

@media print {
   #whiteBg {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      z-index: -1; //to send it to the background
   } 
   #wrapper {
      padding-bottom: (the size of the footer, to make footer visible on last page).
   }
   #footer {
     position: fixed;
     bottom: 0;
   }
}

jQuery的:

 @('#whiteBg').height(  $('#content')).height()  );

为了获得每页底部的内容,我使用了:(第二场景)

CSS:

@media print {
   #footer {
     position: fixed;
     bottom: 0;
   }
   body {
     margin: x x y x; (y should reflect the height of the footer);
}

12
2017-07-08 04:20



截至撰写本文时,此解决方案在Chrome中无效。 - Rap
那就对了。该问题仅针对IE和IE进行了专门询问。 - Anup Kattel
我相应地更新了标题和标签,OP可能会考虑下次这样做。 mod也可以标记并删除这些无用的评论。 - Shaun Wilson
截至2015年5月,Firefox 37.0.2 Chromium 41.0.2272.76适用于Firefox以及Chrome和Safari - Clain Dsilva
我正在尝试在每个页面底部的页脚解决方案,并且在打印时IE将忽略body元素上的边距,页面文本在页脚下流动。帮帮我? (顺便说一句,它应该是身体,而不是css中的#body)。 - Domchi


答案:


如果其他人需要解决方案,我正在回答我自己的问题。

经过长时间的研究和密集尝试(主要是试验和错误),我使用以下逻辑将页脚设置在最后一页的底部: -

  1. 在css中:@media print {position:fixed;顶部:0;左:0; z-index -1; Ad IE将其显示在每个页面的底部,并通过z-index发送到后台。

  2. 尽管如此,IE中的文本背景在打印时仍然是透明的,因此文本位于页脚顶部。因此,在绝对左上角位置使用1px×1px的白色图像作为图像的背景。

  3. 使用javaScript设置图像的高度和宽度,与具有内容的div的高度相同。

HTML:

<body>
    <div id="wrapper"> <!-- not necessary -->
        <img scr="./img/white.png" id="whiteBg" />
        <div id="content">
            <!-- content here -->
        </div>
    </div>
    <div id="footer">
    </div>
</body>

CSS:

@media screen {
    #whiteBg {
        display: none;
    }
}

@media print {
   #whiteBg {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      z-index: -1; //to send it to the background
   } 
   #wrapper {
      padding-bottom: (the size of the footer, to make footer visible on last page).
   }
   #footer {
     position: fixed;
     bottom: 0;
   }
}

jQuery的:

 @('#whiteBg').height(  $('#content')).height()  );

为了获得每页底部的内容,我使用了:(第二场景)

CSS:

@media print {
   #footer {
     position: fixed;
     bottom: 0;
   }
   body {
     margin: x x y x; (y should reflect the height of the footer);
}

12
2017-07-08 04:20



截至撰写本文时,此解决方案在Chrome中无效。 - Rap
那就对了。该问题仅针对IE和IE进行了专门询问。 - Anup Kattel
我相应地更新了标题和标签,OP可能会考虑下次这样做。 mod也可以标记并删除这些无用的评论。 - Shaun Wilson
截至2015年5月,Firefox 37.0.2 Chromium 41.0.2272.76适用于Firefox以及Chrome和Safari - Clain Dsilva
我正在尝试在每个页面底部的页脚解决方案,并且在打印时IE将忽略body元素上的边距,页面文本在页脚下流动。帮帮我? (顺便说一句,它应该是身体,而不是css中的#body)。 - Domchi


也许是这样的?

<link rel="stylesheet" href="print.css" type="text/css" media="print" /> /* this css file is only for printing purposes*/

body:after {
   content: "I am the footer";
}

使用文档末尾的最后一个元素而不是正文...


4
2017-07-05 07:31



很有意思。谢谢 - Frankie Loscavio
有趣的方法,但遗憾的是,如果您有多个页面,则不起作用。 - tftd