3

I need to print some pictures in asp.net page and I need to print every picture in a separate page. How can I do this using ASP.net C#?

When I use window.print() it prints the whole page, but I need just the images and also every image in a separate page!

1 Answer 1

1

You need to define some things in your stylesheet (.css) file:

@media all
{
  .page-break { display:none; }
}
@media print
{
  .page-break { display:block; page-break-before:always; }
}

Then, in your HTML, whenever you'd like a page break:

<div class="page-break"></div>

You can hide/show elements in your print layout the same way (by using @media print and setting display:none on any element you don't want to print. For example, to only display images in a print layout, this might work (untested):

@media print
{
   * { display:none; }
   img { display:block; } 
   .page-break { display:block; page-break-before:always; }
}
2
  • sorry, I do not have much experience in CCS even so some how I understand but if there is any sample it will be very helpful, thanks in advance Mar 12, 2011 at 7:56
  • I added a sample for the bottom part. For the page breaking, simply put that line <div class="page-break"></div> after each image and it should work fine. Make a new stylesheet, include it in your HTML file, and then copy the first block of code into it.
    – drharris
    Mar 12, 2011 at 8:00

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.