如何在打印机中打印图像文件 [英] How to print a image file in printer

查看:144
本文介绍了如何在打印机中打印图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的程序来在JSF中打印图像....

I write a simple program to print a image in JSF....

我有一个图像(sampleImage.png)..我已经将我的电脑连接到打印机....

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....

现在我想要使用javascript打印图片....

Now i want print image using javascript....

文件名:imagePrint.jsp

File name : imagePrint.jsp

<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 write a script for print image                              
            }
        </script>

    <body>
        <h:form id="fileViewerForm">
            <rich:panel>
                <f:facet name="header">
                    <h:outputText value="Printer"/>
                </f:facet>

                <h:commandButton value="PrintImage" onclick="printImage();"/>

                   <rich:panel id="imageViewerPanel">                               
                       <h:graphicImage id="imageViewer" value="sampleImage.png" url="sampleImage.png"/>             
                  </rich:panel>                                       
            </rich:panel>
        </h:form>
    </body>
</html>

帮我解决这个问题..

help me about this..

以下脚本将textarea打印到打印机中.....
所以我需要打印图像

The following script for print the textarea into the printer..... So i need to print the image

            function printText()
            {
                alert("Text Area print to printer start....");
                var textElem = document.getElementById("fileViewerForm:textAreaGrid1").innerHTML;
                alert("Text Area Content : " + textElem);

                if(textElem.toLowerCase().indexOf("<textarea", 0) != -1)
                {
                    textElem = document.getElementById("fileViewerForm:fileContent1").value;
                    var regExp = /\n/gi;
                    textElem = textElem.replace(regExp,'<br>');
                }
                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(textElem);
                popup.document.write("</body></html>");
                popup.document.close();
            }             


推荐答案

您将收到图片ID
h:form和h:graphicImage标签id

You will receive image id using both h:form and h:graphicImage tag id's

Java脚本是:

 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();           
}

JSF代码是:

  <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>

适用于FireFox 3.0。 18。

It works on FireFox 3.0.18.

By,

Eswara Moorthy,NEC。

By,
Eswara Moorthy, NEC.

这篇关于如何在打印机中打印图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆