如何将html页面转换为pdf并在每个pdf页面中打破带有标题的内容?

时间:2014-06-28 06:00:47

标签: php html css pdf printing

我正在使用css打破内容,因为需要在新的pdf页面中打印,我想在每个pdf页面上包含页眉/页脚,我尝试使用固定的css /以及页边距但是这适用于第一页而不是连续的页面。页脚与页面内容重叠..

mypage.php

<?php //call_db
//call_func
 ?>
    <!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=utf-8" />
    <title>My Print Page</title>
    <style>
    body {
        background-color: white;
        color: black;
        font-size: small;
        font-family: sans-serif, helvetica, tahoma, arial;
        margin: 20%;
    }

    .page-break  { 
        display:block; 
        page-break-before:always; 
    }

     @media screen {
            div.divFooter {
                display: none;
            }
            div.divHeader {
                display: none;
            }
        }
        @media print {
            div.divFooter {
                position: fixed;

                bottom: 0;
            }
            div.divHeader {
                position: fixed;

                top: 0;
            }
        }

    </style>

    <script type="text/javascript" src="jquery.js" > </script> 
    <script type="text/javascript">
        $(document).ready(function(){
            window.print(); 
            });
    </script>

    </head>

    <body>

//call sql query for content // A collection of 200 lists

    <div class="divHeader"> <h1 align="center" style="font-size:36px;"> THE GAME OF THORNES</h1> </div>


    <h1>Sean's CSS Print vs. Screen Example</h1>
    <h2>Lesson 1</h2>
    <p>This is my first Page in the document.</p>

    <div class="page-break"></div>
    <h2>Lesson 2</h2>
    <p>Examples and theory of lesson2</p>

    <div class="page-break"></div>
    <h2>Lesson 3</h2>
    <p>Examples and theory of lesson2</p>

    <div class="divFooter">UNCLASSIFIED </div>
    </body>
    </html>

**我正在添加PHP标记,就像你有其他更好的方法从db打印内容,请建议。

1 个答案:

答案 0 :(得分:1)

我认为这与此Convert HTML + CSS to PDF with PHP?重复, 您必须使用pdf转换库将页眉和页脚添加到pdf。

我在我的项目中使用了http://www.tcpdf.org/。你也可以使用它。