【问题标题】:How to convert html page to pdf and breaking the content with header in each pdf page?如何将html页面转换为pdf并在每个pdf页面中使用标题打破内容?
【发布时间】:2014-06-28 16:35:04
【问题描述】:

我正在使用 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 打印内容一样,请提出建议。

【问题讨论】:

    标签: php html css pdf printing


    【解决方案1】:

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

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

    【讨论】:

    • 这对 PHP 来说很好,因为它可以制作一些小的相同类型的输出,比如只说表格或收据。但是如果我需要从 db 输出大量数据并输出为带有 css 和其他东西的 html .说一本具有多种功能的书是最终输出..直接将html输出为pdf会更好吗..?
    • 我不知道如何直接将html输出为pdf,如果你找到了我将不胜感激的方式与我分享。
    猜你喜欢
    • 2017-05-29
    • 1970-01-01
    • 2011-01-13
    • 2016-03-23
    • 1970-01-01
    • 2014-07-09
    • 2011-07-01
    • 1970-01-01
    相关资源
    最近更新 更多