1

I am using css to break the content as required to be printed in fresh pdf page, I want to include the header/footer on each pdf page, I tried with fixed css/ along with margin but that works for first page not the successive page. The footer is getting overlapped with page content..

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>

** I am adding PHP tag as if you have any other better way to print the content from db, please suggest.

1 Answers1

1

I think this is duplicate of this Convert HTML + CSS to PDF with PHP? , you must use your pdf convertor library to add header and footer to pdf.

I'm used http://www.tcpdf.org/ in my project. you can use it too.

Community
  • 1
  • 1
Amir Habibzadeh
  • 437
  • 2
  • 11
  • That goes good for PHP for making some small same kind of output, say tables only, or receipt.. But if I need to output a lot data from db and output as html with css and other stuff. Say a book with multiple features is final output.. would it be better to directly output the html to pdf.. ? –  Jul 01 '14 at 08:28
  • i don't know how to directly output the html to pdf , if you find the way i will appreciate to share with me . – Amir Habibzadeh Jul 02 '14 at 07:37