0

hi, I have one image (sampleImage.png).. Already i connected my pc to printer....

Manually i open the image and select print option , then i got image from printer....

Now i want print image using javascript....

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

   <f:view>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Printer</title>          
            <script type="text/javascript">
                 function printImage()
                {                   
                   // Here i want to write a script for print image                              
                }
            </script>
        </head>

        <body>
            <h:form id="fileViewerForm">
                <rich:panel>
                    <f:facet name="header">
                        <h:outputText value="Printer"/>
                    </f:facet>
                                    
                    <h:commandButton value="PrintImage" onclick="printImage();"/>
<br>
                       <rich:panel id="imageViewerPanel">                               
                       <h:graphicImage id="imageViewer" url="sampleImage.png" value="sampleImage.png"   width="200" height="200"/>

                          </rich:panel>                                       
                </rich:panel>
            </h:form>
        </body>
    </html>
</f:view>

help me about this....

Edited by peter_budo: Keep It organized - For easy readability, always wrap programming code within posts in [code] (code blocks).

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jackrobert
0

Its worked in Firefox 3.0.18

Here, i received image id using both h:form and h:graphicImage tag id's

JSF code is :

<h:form id="fileViewerForm">


<h:panelGrid columns="2">
<h:commandButton value="Print" onclick="printImage();"/><br>
<rich:panel id="imageViewerPanel">
<h:graphicImage id="imageViewer" url="sampleImage.png" value="sampleImage.png" width="200" height="200" />
</rich:panel>
</h:panelGrid>


</h:form>


The Java script is :


function printImage()
{
var iamgeId = document.getElementById('fileViewerForm:imageViewer');
var imagObject = new Image();
imagObject = iamgeId;
var originalImage = '<img id="imageViewer" src="'+imagObject.src+'" height="'+imagObject.height+'" width="'+imagObject.width+'" />';


popup =  window.open('','popup','toolbar=no,menubar=no,width=200,height=150');
popup.document.open();
popup.document.write("<html><head></head><body onload='print()'>");
popup.document.write(originalImage);
popup.document.write("</body></html>");
popup.document.close();
}

Edited by happygeek: fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.