You said you want to this in CodeIgniter. I don't think you need any server side code for this. Try below suggestion.
You can use @media
query.
In your default css without using external stylesheet you can do this:
@media print {
#with_print {
display: none;
}
}
Hide your header, footer and menu withing @media print
block
With external stylesheet add media="print"
attribute to <link>
tag.
<link href='printCSS.css' rel='stylesheet' media="print" type='text/css'>
With external stylesheet you don't need to add @media
query block in your printCSS.css
.
See the Demo
See the print preview from your browser and where the text says:
I will be hidden when you try to print me
, cannot not be seen on the print preview page.