代码之家  ›  专栏  ›  技术社区  ›  Kamil Jarosz

打印时强制多页中断<div/>

  •  1
  • Kamil Jarosz  · 技术社区  · 7 年前

    我正在编写一个JSP应用程序,专门用于生成EDI标准文档。现在,我无法格式化输出。

    以下JSP代码段将生成有问题的PDF:

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title></title>
        <style>
        @page {
            size: 7in 9.25in;
            margin: 0.25in 0.25in 0.25in 0.25in;
        }
    
        p:first-child {
            margin-top: 0;
        }
    
        .main-container {
            display: block;
            margin: 0 auto;
        }
    
        .main-container .row .left {
            display: inline-block;
            width: 29%;
            text-align: right;
            vertical-align: top;
            padding: 0.1em 0.2em;
            font-weight: bold;
        }
    
        .main-container .row .right {
            display: inline-block;
            width: 69%;
            text-align: left;
            vertical-align: top;
            padding: 0.1em 0.2em;
        }
        </style>
    </head>
    <body>
        <div class="main-container">
            <div class="row">
                <div class="left">
                    Label1:
                </div><div class="right">
                    <% for(int i = 0; i < 10; i++) { %>
                        <p>First 10 lines will fit on the first page.</p>
                    <% } %>
                </div>
            </div>
            <div class="row">
                <div class="left">
                    Label2:
                </div><div class="right">
                    <% for(int i = 0; i < 24; i++) { %>
                        <p><%= i %>Test line goes here. Let's make a 1000.</p>
                    <% } %>
                </div>
            </div>
        </div>
    </body>
    </html>
    

    <div class="row"> <div class=“row”>

    我希望文本继续前面的内容 <div> 离开了。我不想要下一个 <部门> 别回避了

    auto/avoid/always/etc . 不幸的是,这些解决办法没有奏效。我尝试用flyingsaucer渲染,但也找不到任何解决方案。我真的不想求助于手动计算距离,因为这是远远超出了什么应该是一个快速和肮脏的工具范围。

    我一直在试图找到一个解决办法,但由于最常见的情况是做我想避免的事情,很难找到答案(如果有)。也许你们中有人知道实现这一目标的可靠方法?

    0 回复  |  直到 7 年前