Discussion Locked

Force image smaller with onbeforeprint

0 helpful
17 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have been at this awhile, and I haven't been able to get onbeforeprint to make a jpg go to 384x288 from 640x480. When printing, the image takes up a third of the page which forces the text down to a 2nd and sometimes 3rd page. This is fine on screen, but that size isn't needed when printed (just a little overkill). I just don't have enough experience with JS to find the key(s) to get the image size down the way I want it. I have over 200 jpg's that are used for the screen and print so I don'twant to have multiple sizes of the same pictures, it is bad enough I had to do that for the thumbnails. I don't really need anymore. If I could even get a suggestion as to the right direction to head toward it would be a big help.

Thanks

17 replies

by ann777

You might want to lookup Microsoft Knowledgebase article # Q294901...

It has two samples of java coding that might work for you... depending on what you want to do.

I don't think that java will resize the image, but you can set it to printa single area or a single page.

by ann777

To re-size jpeg's, i think you'll need another program... such as Paint Shop Pro.

by bigbillh

I can remove images and items from a page with onbeforeprint and I can force an image 640x480 picture smaller with:
but that makes it that size all the time. What I'm trying to do is remove the items that I don't want printed, and reduce the size of the picture using the "onbeforeprint" event of IE5.0 and above. Sorry if I wasn't clear in my first posting. Thanks for the response.

by bigbillh

Oh Yeah,
Yes, you are right I could change the size with Paint Shop or other picture program. But I don't want to change the size all the time, just when it is bing printed. The only place I have seen ANY type of article on the window.onbeforeprintevent is wsabstract.com but it only covered removing elements and backgrounds and then reloading the page.

Oh well, back to the drawing board.

by bigbillh

Still? All I'm asking for it an idea of how to do this. All the things I have tried didn't work. I thought someone that is more experienced with js would be able to just whip this out without a lot of trouble. Thanks anyway.

by sbkwi

There is a very simple solution if you if you don't mind using dynamic html and php and your web server executes php pages. Example:

Print Layout

Normal Layout

To see how it works create a file named printdemo.php3 containing everything from "" to "" above. Transfer this file to your web server. Using the URL "http://www.my_server.com/printdemo.php3" you get the 640x480 picture, and the smaller picture using "http://www.my_server.com/printdemo.php3?layout=print".

So when you create your own page(s), use the following pattern:

....
content when printed
....

....
normal content
....

Put a link like "Printer frienly format" somewhere in the page.

Note that the file extension for php pages may vary. Ask your service provider for the correct value (".php3" works with mine).

The big advantage of using php is that it works with any browser and is very easy to learn and use.

by bigbillh

Sorry.
Again, I want/need to use the window.onbeforeprint event. This way it will only force the graphic smaller, during the print of the page only, and then return to full size on the screen.

Thanks!

by sbkwi

Maybe it is not clear from the first post:

You can use the pattern multiple times in one page and whereever you like, it even within normal html tags, e.g. to display tables with different attributes or links pointing to different addresses.

by sbkwi

So you don't like php? OK, after a little digging into javascript I found a solution. But be warned: it works >>only<< for MSIE 5 and above. If the functions "window.onbeforeprint" and "window.onafterprint" are included when the page is loaded by any other browser, this will result in a javascript error.
Here is an example code:

Test onbeforeprint

This is the text for display only.

This is text to be printed.


Hope this helps.

This discussion is closed to new replies.