window.print只打印第一页

时间:2016-06-14 16:31:14

标签: javascript html angularjs printing

我想要打印超过1页长的报告,但是当我使用时 window.print()它只显示第一页!我怎么能有其他页面?

注意:页面变量超过1页

var page = document.createElement("div");
angular.forEach($scope.customersTasks, function(item) {

  var toPrint = document.getElementById("toPrint");
  page.innerHTML += toPrint.innerHTML;
});

printElement(page);

function printElement(elem) {
  var domClone = elem.cloneNode(true);
  var $printSection = document.getElementById("printSection");
  if (!$printSection) {
    var $printSection = document.createElement("div");
    $printSection.id = "printSection";
    document.body.appendChild($printSection);
  }
  $printSection.innerHTML = "";
  $printSection.appendChild(domClone);
}
@media screen {
  #printSection {
    display: none;
  }
}
@media print {
  body * {
    margin: 0;
    padding: 0;
    visibility: hidden;
  }
  #printSection,
  #printSection * {
    visibility: visible;
  }
  #printSection {
    overflow: visible;
    position: absolute;
    left: 0;
    top: 0;
  }
}

0 个答案:

没有答案