簡體   English   中英

如何將html頁面轉換為pdf並在每個pdf頁面中用標頭分隔內容?

[英]How to convert html page to pdf and breaking the content with header in each pdf page?

我正在使用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的副本嗎? ,您必須使用pdf轉換程序庫向pdf添加頁眉和頁腳。

我在項目中使用了http://www.tcpdf.org/ 您也可以使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM