【问题标题】:DOMPDF: Why is CSS not rendering properly to PDF while splitting page in half?DOMPDF:为什么将页面分成两半时 CSS 无法正确呈现为 PDF?
【发布时间】:2016-05-04 15:43:25
【问题描述】:

对我的 CSS 有不同的处理方式吗?

我有一些 html 代码和一些 CSS 样式,试图生成一个 PDF,其中我的示例文本容器/div 向右浮动。如果我自己加载 html 站点,则 CSS 都是正确的并且看起来很好。但是当我从代码转换为 PDF 文件时,它输出错误。任何人都可以提出一种可行的方法吗?

我的代码:

<html>
<head>
    <style>
        @page {
            margin: 0px 0px 0px 0px;
        }
        body {
            height: 100%;
            margin: 0px 0px 0px 0px;
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }
        #top,
        #bottom {
            position: fixed;
            left: 0;
            right: 0;
            height: 50%;
        }
        #top {
            top: 0;
            background-color: orange;
        }
        #bottom {
            bottom: 0;
            background-color: green;
        }
        div.mainLayout{position: relative;float:right;width:50%;height:100%;}
        .textstuff {
            background-color:aqua;
            left:0;
            height: 100%;
            width:100%;
        }
    </style>
</head>
<body>
    <div id="top">
        <div class="mainLayout">
            <div class="textstuff">
                <center>
                    <font size="5" style="padding-bottom:5px">Sample Text 1</font><br />
                    <font size="4" style="padding-bottom:5px">Sample Text 2</font><br />
                    <font size="5" style="padding-bottom:25px">Sample Text 3</font><br />
                    <font size="4">Sample Text 4</font>
                </center>
            </div>
        </div>
    </div>
    <div id="bottom">
        <div class="mainLayout">
            <div class="textstuff">
                <center>
                    <font size="5" style="padding-bottom:5px">Sample Text 1</font><br />
                    <font size="4" style="padding-bottom:5px">Sample Text 2</font><br />
                    <font size="5" style="padding-bottom:25px">Sample Text 3</font><br />
                    <font size="4">Sample Text 4</font>
                </center>
            </div>
        </div>
    </div>
</body>
</html>

呈现为 HTML 文件的内容(正确):

呈现为 PDF 文件的内容(输出不正确,应如上所示):

【问题讨论】:

    标签: html css pdf dompdf


    【解决方案1】:

    我修改了 CSS 以处理 PDF:

    <style>
        @page {
            margin: 0px 0px 0px 0px;
        }
        body {
            height: 100%;
            margin: 0px 0px 0px 0px;
            background-size: 100% 100%;
            background-repeat: no-repeat;
        }
        #top, #bottom {
            position: fixed;
            left: 0;
            right: 0;
            height: 50%;
        }
        #top {
            top: 0;
        }
        #bottom {
            bottom: 0;
        }
        div.mainLayout{height:100%;}
        .communitylogotop {
            bottom: 41px;
        }
        .text {
            margin-right:50px;
            margin-top:65px;
            width:44%;
            float:right;
        }
    </style>
    

    我的身体现在是这样的:

    <div id="top">
        <div class="mainLayout">
            <div class="text">
                HERE's..
            </div>
        </div>
    </div>
    <div id="bottom">
        <div class="mainLayout">
            <div class="text">
                ...STUFF
            </div>
        </div>
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 2023-01-24
      • 1970-01-01
      • 2018-07-28
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      相关资源
      最近更新 更多