Impressao de imagens de um JSP

Pessoal.

Estou com uma dúvida. Tenho um JSP que carrega algumas imagens no browser. A minha intenção é possibilitar a impressão somente desta imagem, já que só permito a visualização de um imagem por vez, mas até este momento só consegui criar um botão que imprimi a tela toda, com todos os menus além da imagem que eu quero.

Minha pergunta é a seguinte: Eu consigo fazer a impressão de uma imagem que está carregada na tela? Ou pelo menos indicando em qual diretório de localiza a imagem e a partir dai efetuar a impressão do arquivo? Como setar a impressora como dispositivo de saída?

Obrigado!

Achei isto no MSDN, obviamente isto deve funcionar direito com o IE, mas não muito bem com o Netscape ou o Mozilla. Mas a idéia está aqui.
(Basicamente você deve pôr a imagem em um frame, e tentar imprimir só o frame).

Q I have a Web page that is produced dynamically from an ASP script. The page must have a Print button on it. When a user presses the Print button, the page should be printed, but I want the Print button to be hidden on the printed page.

A There are two issues here. One is to provide a button on a Web page that, when pressed, will cause the page to be printed; the other is to prevent that button from being printed along with the output. Each of these problems has two possible solutions. The one you adopt will depend on the browser your users have.
For printing, one approach is to use the ExecWB function. Using the code in Figure 1, you would call the Print subroutine when your button is clicked. This will work in Internet Explorer 4.0 or Internet Explorer 5.x, but not in Netscape Navigator.
The other option is to use the window.print method. This will work in Netscape 4.x or Internet Explorer 5.x, but not in Internet Explorer 4.0. Documentation for the print method can be found at http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/print.asp.
Note that while the code in Figure 1 provides a method to turn off prompting before printing, the print method does not. Also note that neither of these choices will allow you to assign the printer or modify the page count, orientation, or any other layout parameters. In order to get that level of functionality, you would need to write an application that embeds the browser in it.
To prevent the button from being printed along with the content, you can try one of a few solutions. Using Cascading Style Sheets (CSS), you can set up a style that will control the layout and display on the screen and printer separately:
<style>
@media screen {.PrintOnly {display:none}}
@media print {.ScreenOnly {display:none}}
</style>

  Here, I've defined two classes; one will only print, and the other will only display on the screen. So in your case, you would use something like this: 

<button class=“ScreenOnly” onclick=“window.print()”>Print</button>

Then the Print button would only appear on the screen. Note that this will only work in Internet Explorer 5.x, and not in Internet Explorer 4.0 or Netscape Navigator.
You could also use a frame-based set of pages, placing the Print button in another frame:
<button onclick=“parent.frames(“Doc”).window.print()”>Print</button>

The <button> item will only work for Internet Explorer 4.0 or Internet Explorer 5.x, and not in Netscape Navigator. You could, of course, provide the same level of functionality with an <input> button, or with any element that supports an onclick event.

thingol, valeu pela dica cara.

Fiz algo parecido com isso que você me indicou, vou postar aqui até para que alguém que tenha o mesmo problema veja.

Na verdade estou utilizando iframe, e ai criei um outro JSP que recebe o nome da imagem que eu quero carregar.

out.println("&lt;tr&gt;&lt;td&gt;&lt;iframe src='imageControl.jsp?imagename=" + strImagem + "' name='ifraImagem' id='ifraImagem' scrolling='no'&gt;&lt;/td&gt;&lt;/tr&gt;"); 

Dentro da minha página que tem o código acima, fiz um script que efetua a impressão:

    function ImprimirImagem(){
       window.ifraImagem.focus(); 
       window.print();
    }

Então a única coisa que fiz foi criar um botão e neste botão fazer a chamada da function ImprimirImagem.

Agora só preciso “arrumar” o tamanho da imagem para a impressão, mas ai já é outra história! :smiley:

Obrigado!