views:

234

answers:

4

If i have 1000 pages of html can i provide option for page range while printing html? Is it possible in javascript? (Ex: print page 100 to 200)

A: 

Umm.. no. you can't.

UPDATE

I didn't go further for the simple reason that trying to control web printing is like grabbing a snake by it's tail and hoping it doesn't bite you. In other words, it's futile and you will get bit. If you want print control then a web app is NOT the way to do things.

If you're users need flexibility with format / layout / or just controlling what page numbers to print then you either have to build a desktop app OR try and control it via delivering regular document like Word or PDF.

Either way it's a lot of work.

Chris Lively
Helpful. I can see how this provides alternative solutions to that requested or advises the poster why this is a bad idea or not possible.
Stefan Kendall
A: 

Are you sure you can render all that in one pass? It may make more sense to feed out a selected range of files via a server-side language, or ajax in whatever the user selects.

For example, you could provide an input box for the begin and end page, ajax the needed material onto the page, and then printing would be exactly what you want it to be, minus the input fields. At that point, you could either hide the input fields or force that ajax to load into a new window, or something of that nature.

Stefan Kendall
This is the option what i currently have. Let me tell the background story. The basic requirement was to export particular page in PDF so that customers can take printout at anytime and between page range. I was creating PDF dynamically using iText. The problem is it is taking mure CPU utilization and memery usage. For single user it wont be an issue. If we go for multiple user, the server will die. That is why i want to export the pages in HTML (which is more than 1000 pages)
Niger
+3  A: 

Passing in a page range to the native print dialog... nope.

You could dynamically wrap the portions that you don't want to print with a CSS class that you've defined in a print stylesheet...

<link rel="stylesheet" type="text/css" media="print" href="print.css" />

/* contents of print.css */
.noprint { display: none; }

You'll have to figure out how to get that class onto the appropriate bits of HTML before calling window.print().

great_llama
Good idea. If the printable text is well-formed enough, I'm just some jQuery magic should be able to add the appropriate class to the appropriate elements.
Stefan Kendall
+3  A: 

You can try using the page-break-before CSS property to define page breaks in your HTML source.

Then allow your user to print a range of pages as he or she normally would.

Triptych
W00t - this put me over 10k. Moderation tools are neat.
Triptych
This only has partial support in most browsers. Nice idea if it would actually work though.
Chris Lively