프로그램/프로그램관련

[스크랩] div 영역 프린트 출력하기

체력덩이!! 2012. 12. 31. 11:53

<html>
<head>
    <title>http://www.blueb.co.kr</title>
   
<script type="text/javascript">
  var win=null;
  function printIt(printThis)  {
    win = window.open();
    self.focus();
    win.document.open();
    win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
    win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
    win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
    win.document.write(printThis);
    win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
    win.document.close();
    win.print();
    win.close();
  }
</script>
</head>
<body>

<a href="javascript:printIt(document.getElementById('printme').innerHTML)">Print</a><p>

<div id="printme">
여기서 부터~~~<p>
~~~~

여기까지만 출력됩니다.<br>
</div>


</body>
</html> 

 

 

 

 

 

function content_print(){
    
                var initBody = document.body.innerHTML;
                window.onbeforeprint = function(){
                    document.body.innerHTML = document.getElementById('선택될 div id').innerHTML;
                }
                window.onafterprint = function(){
                    document.body.innerHTML = initBody;
                }
                window.print();     
            }            
        </script>

===============================================================================================

<div id='content'>
    내용 content_1
</div>

<div id='content_2'>
   내용 content_2
</div>
<input type="button" value="print" onclick="javascript:content_print();">
================================================================================================

선택될 div id  이부분에 div id 를 삽입하면 된다.

print 버튼을 누르면 지정된 div 안의 내용이 프린트 된다

 

 

 

 

=================스크립트 / 폼 부분===============================
<!-- 프린터영역 <DIV id=A> 값을 받아서 넘기기 시작-->
<form name="pf">
 <input type=hidden name="printzone">
</form>
<script>
function print_div()
{
 document.pf.printzone.value = printDIV.innerHTML;
 window.open("print_page.php", "print_open","width=800,height=700,top=0,left=0,noresizable,toolbar=no,status=no,scrollbars=yes,directory=no");
}
</script>
<!-- 프린터영역 <DIV id=A> 값을 받아서 넘기기 끝-->

 

================== 프린트 할 DIV 영역=================================

 <div id=printDIV>
       <img src="../img/if_t02.gif" />
 </div>

 

-----------------------------------------------------------------------------------------------

<a href="#" ONCLICK=print_div();>print</a>   호출하기

 

=============== 팝업에 호출되는 print_page.php =====================

<HTML>
<HEAD>
<TITLE>PRINT_PAGE</TITLE>
<script for=window event=onload>
A.innerHTML = opener.pf.printzone.value

 window.print();
</script>
</HEAD>
<center>
<body>
<br>

<div id="A">
</div>

<br>
</BODY>
</HTML>
========== 실제 값이 넘어와 window.print 하는 파일==================

 

 

 
출처 : 북벌
글쓴이 : 무냐무냐 원글보기
메모 :

'프로그램 > 프로그램관련' 카테고리의 다른 글

올래맵 연동  (0) 2013.06.20
HTML5 개요와 기술적 특징  (0) 2013.04.25
[스크랩] [MS-SQL] 문법정리  (0) 2012.12.27
PIVOT 함수를 이용한 동적 PIVOT 구현  (0) 2012.12.16
Windows 7 SP1 ...  (0) 2011.03.01