How to print a image file in printer

前端 未结 3 741
傲寒
傲寒 2021-01-27 12:53

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

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

Manually i open the image and

相关标签:
3条回答
  • 2021-01-27 13:06

    You could send this to the browser

       window.print();
    

    It is up to the browser to decide what to do.

    To print specific portions of the page, consider a print stylesheet. Using the media attribute allows you to make a certain file print only styles.

    <link rel="stylesheet" href="/assets/css/print.css" media="print" />
    
    0 讨论(0)
  • 2021-01-27 13:18

    You won't be able to print using javascript, since you can't manage hardware devices from the browser and it executes there.

    0 讨论(0)
  • 2021-01-27 13:22

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

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

    JSF code is :

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

    It works on FireFox 3.0.18.

    By,
    Eswara Moorthy, NEC.

    0 讨论(0)
提交回复
热议问题