Hello everyone..
How to print web page in PHP
without Header and footer when print button is clicked by user

Thanks in advance

Recommended Answers

All 8 Replies

Why would you want to print in PHP ?

For a special print style, you can use CSS.

You cant determine to what I set my header and footer, nor should you be able to access my hardware settings, think for a moment

I have generated a report...in a php page...
The report has to be printed in landscape mode
but
each time i have to set in into page setup
.and have to remove header and footers...
.
Please tell me the css code to do that

There are few steps to print only content on pages

Is your page have dynamic and static contents, well whats type of that contents follow these 2 simple steps

1. create a page without header and footer

That is because when we use print command in webpage whole page with header and footer will print, this is more simple to create a PHP page without any header and footer, only inner contents.
2. use this code to print that page

echo "<a href='javascript:window.print()'>[Click to Print This Page]</a>";

You cannot set the printer driver's page layout like that.

For the CSS see @media print.

Problem is to print a web page without any header and footer, 'print()' code will print web page as it is looks on the screen. That's why we have to create a new page without header and footer so that these two things didn't show in that page and can get print only contents of that page

Not true. Using CSS you can hide this when printing the page.

That is an other way to create div's for header and footer and on print command we can hide these through css, and even can some JavaScript, i just give the simple solution without creating new css or writing any JavaScriptto create new page. Well we can also create only one css for all header and footer,"named as media_css" and use on the pages where we want to print the page, when the print command executed "media_css" will automatically applied and hide header and footer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.