简体   繁体   English

打印预览中的第一页后模态内容被切断

[英]Modal content gets cut off after first page in print preview

I am running into an issue when printing module content, and this happens to all browsers.我在打印模块内容时遇到问题,所有浏览器都会发生这种情况。 When I print the modal content, it only previews the first page and anything after the first page would get cut off.当我打印模态内容时,它只预览第一页,第一页之后的任何内容都会被切断。 I have tried debugging in Chrome print emulator but still cannot figure out a solution.我已经尝试在 Chrome 打印模拟器中进行调试,但仍然无法找到解决方案。

At some point, I added a scrollbar to the print emulator and I can scroll down to see all the content, but when I print preview, it shows the scrollbar and still cuts off any content after the first page.在某些时候,我向打印模拟器添加了一个滚动条,我可以向下滚动以查看所有内容,但是当我打印预览时,它显示滚动条并且仍然在第一页之后切断任何内容。 I don't know why print preview behaves so differently from the emulator.我不知道为什么打印预览与模拟器的表现如此不同。

The project is in react, plain modal that doesn't use any third-party library like bootstrap modal.该项目处于反应状态,不使用任何第三方库(如 bootstrap modal)的普通模态。

模态

打印预览

Media query for print:印刷媒体查询:

@media print {
  body, html {
    height: 100%;
    overflow: visible !important;
  }

  .account-header {
    display: none;
  }

  .list-wrap {
    height: 100%;
    // overflow: scroll !important;
  }
  .account-content {
    margin: 0;
    padding: 0;
    border: 2px solid red;
    position: absolute !important;
    overflow: visible !important;
    visibility: visible !important;
    display:block;
  }

  .account {
    background-color: none !important;
    display: inline-block;
    font-size: 12px;
    border: 1px solid blue;
  }
}

Note: .list-wrap is a class applying to the parent container for .account-content.注意:.list-wrap 是一个应用于 .account-content 的父容器的类。 Using the overflow: scroll style would add a scrollbar to the print emulator and I would be able to see all the modal content there.使用 overflow: scroll 样式会向打印模拟器添加一个滚动条,我将能够在那里看到所有的模式内容。 But in the actual print preview, it still shows the first page only.但在实际打印预览中,它仍然只显示第一页。

The problem, when printing, is that you have to set the page size property.打印时的问题是您必须设置页面大小属性。 The rules that give you the issues you are describing are the ones related to height .为您提供所描述问题的规则是与height相关的规则。

Depending on how you would like to print pages and how you want to handle page breaks, you have to act as described in the following documentation:根据您希望如何打印页面以及您希望如何处理分页符,您必须按照以下文档中的说明进行操作:

https://www.w3.org/TR/WD-css2/page.html https://www.w3.org/TR/WD-css2/page.html

The sections you should check are, at least:您应该检查的部分至少是:

Another article that can help you is this one:可以帮助您的另一篇文章是这篇文章:

https://www.jegsworks.com/lessons/web-2/html/step-mediaprint.htm https://www.jegsworks.com/lessons/web-2/html/step-mediaprint.htm

If you want be make sure to have a more wide as possible compatibility with browsers, this GitHub repository may help you:如果你想确保与浏览器有更广泛的兼容性,这个 GitHub 存储库可以帮助你:

https://github.com/cognitom/paper-css https://github.com/cognitom/paper-css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM