Click here to Skip to main content
12,954,631 members (55,759 online)
Rate this:
 
Please Sign up or sign in to vote.
hi,

I am creating a form. and i want to take printout of the the form only.
When i use
window.print()

it take whole page for print.

i want is there any code so that i can take only the selected portion of the form.

thanks
Posted 12-Sep-12 20:12pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this

 
<html>
<head>
 
<script type="text/javascript">
 
function CallPrint()
   {
    
    // getting content from previous window
    //var prtContent = document.getElementById( strid );
    // here your are opening a new window with custom size
    var WinPrint = window.open('', '', 
 
'left=30,top=0,width=600,height=600,toolbar=1,scrollbars=1,status=0');
    var ss='<table style="text-align:justify;"><tr><td><style type="text/css">your styles</style><h1>ITS A TEST......</h1><br /><h1>ITS A TEST</h1><br /><br /><h1>CONTENT FOR PRINTING.........</h1><br /></td><table><tbody><tr></tr></tbody></table></tr></table>';
    // preparing page content 
    WinPrint.document.write(ss);
    // writing that content to new window
    WinPrint.document.close();
    WinPrint.focus();
    WinPrint.print();
   }
 
</script>
 
</head>
 
<body>
 
<br />
<br />
<br />
 
<a  önclick="CallPrint()">PRINT</a>
 
</body>
 
</html>
 
  Permalink  
v2
Comments
Rajeshkrathor 13-Sep-12 4:27am
   
Thanks vino2012

Its working but my Question was, i want to print a form.
you creating a form in <script> then printing it but i want to print form which is in <body>.

Thanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,
Add a html page
<head>
<script language="javascript" type="text/javascript" src="print_part_page.js"></script>
</script></head>
<body>
<p id="printout" style="font-size:150%">This part of page will be printed!</p>
<p style="font-size:150%"><a href="#" onclick="var obj = new printPartOfPage(); obj.printPart('printout');">Click to print a part of page</a></p>
 
</body>


here is the print_part_page.js
var wi = null;
printPartOfPage = function(){
				
					if( wi && (!wi.closed ) )
					  {
						  wi.close();
					  }
					  
					this.printPart = function(divId)
									{
						  
										html = document.getElementById(''+divId+'').innerHTML;
										
										wi=window.open('','printingpage');
										
										wi.document.write('
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100