2

So basically, I have my CSS document that is stopping things from being printed.

Heres my CSS:

/* Making the page A4 compatible */
body 
{
 margin: 0;
 padding: 0;
 font: 12pt "Tahoma";
}
* 
{
 box-sizing: border-box;
 -moz-box-sizing: border-box;
}
.page 
{
 width: 21cm;
 min-height: 29.7cm;
 padding: 2cm;
 margin: 1cm auto;
 border-radius: 5px;
 background: white;
 box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.subpage 
{
 height: 237mm;
}
@page 
{
 size: A4;
 margin: 0;
}
@media print 
{
 .page 
 {
 margin: 0;
 border: initial;
 border-radius: initial;
 width: initial;
 min-height: initial;
 box-shadow: initial;
 background: initial;
 page-break-after: always;
 }
}

I made the page perfectly A4 compatible, while stopping basically everything from being printed besides a div that has the class of page.

I then call my print via window.print(); from a button far outside of this div, which is just inside of the closing body tag.

Although, I am getting 4 pages being printed. One that is perfect, two that are blank, and one with just the button on it?

All these pages have the annoying footer on them with the URL, date, time and page number. I searched everywhere and this bit of code was meant to remove this, although it didn't do anything at all:

@page 
{
 margin: 0;
}

Does anyone have any suggestions to why this is happening?

asked Oct 8, 2013 at 11:12
3
  • You have positioned your button a "far outside" the .page div so in your media print styles try hiding the button and it's container (and any extra content not within the .page div) with display:none Commented Oct 8, 2013 at 11:19
  • @Pete - Thanks for that, I'll give it a try. Although, that still doesn't solve why the footer stuff is being printed on each page? Commented Oct 8, 2013 at 11:22
  • THis link may help you. Commented Oct 8, 2013 at 11:23

2 Answers 2

1
<input id="Button1" name="b_print" type="button" runat="server" class="ipt" onclick="printdiv(divIDtoprint);" value=" Print "/>
<script lang="javascript">
function printdiv(printpage) {
 var headstr = "<html><head><title></title></head><body>";
 var footstr = "</body>";
 var newstr = document.all.item(printpage).innerHTML;
 var oldstr = document.body.innerHTML;
 document.body.innerHTML = headstr + newstr + footstr;
 window.print();
 document.body.innerHTML = oldstr;
 return false;
}

Basically just temporarily removes the other stuff on the page, prints whatever you want to print, then puts the old page back in it's place.

answered Oct 8, 2013 at 11:28
Sign up to request clarification or add additional context in comments.

4 Comments

That's actually quite a smart approach. I'll let you know how it goes.
I am receiving this error: Uncaught TypeError: Cannot read property 'innerHTML' of undefined
Whoops, fixed it. That is a great solution, and it removed the problem I was having with many pages being printed. Although, it did not solve the footer issue.
Simply put the footer outside of the div you're printing in a new div with ID let's say "footerdiv" and give it ít's own position in the css.
0

Depending upon the position of your Page No.

@page {
 @bottom-right {
 // you may have to change this right to left or center as per how it is printed
 content: "";
 }
}
BBdev
4,9562 gold badges33 silver badges45 bronze badges
answered Oct 8, 2013 at 11:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.