php - 如何将 html 页面转换为 pdf 并在每个 pdf 页面中用标题打破内容?

标签 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 的内容,请建议。

最佳答案

我认为这是这个 Convert HTML + CSS to PDF with PHP? 的副本, 您必须使用 pdf 转换器库将页眉和页脚添加到 pdf。

我习惯了http://www.tcpdf.org/在我的元素中。你也可以使用它。

关于php - 如何将 html 页面转换为 pdf 并在每个 pdf 页面中用标题打破内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24464115/

相关文章:

php - Hotmail 使用 Mailgun 或 SparkPost 拒绝所有电子邮件

php - 使用条件逻辑: check if record exists; if it does,更新它,如果没有,则创建它

php - WooCommerce get_availability() 返回一个数组

javascript - 调用新页面Javascript后滚动检测不起作用

css - 元素包围或包裹另一个元素

css - Ionic-Toggle 每侧都有标签

PHP 查询表格不起作用?

javascript - JQuery - 使用 fa fa-star 计算 i 的数量

javascript - 如何使用 python 捕获 URL 中的 javascript 代码注入(inject)?

html - 如何让 Bootstrap3 缩略图中的内容一直流到边缘?