Printing DIV Contents using Print Preview

How to Display only DIV Contents using Internet Explorer Print Preview Window.

Am using this code from a POST

function showPrintPreview() {

var objPrintPreview = '<object id="printPrev" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';

document.body.insertAdjacentHTML('beforeEnd', objPrintPreview);

printPrev.ExecWB(7, 2);

printPrev.outerHTML ="";

 

Using this Displays whole Page contents in Print Preview Window.

0
barrysuku
10/25/2007 2:39:06 AM
asp.net.client-side 24353 articles. 1 followers. Follow

12 Replies
1433 Views

Similar Articles

[PageSpeed] 42

You may like to check out this discussion thread http://www.dynamicdrive.com/forums/showthread.php?t=20162. It tries to make use of a simple CSS trick to achieve the DIV printing.


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

Deepak Vasudevan

http://lavanyadeepak.blogspot.com/

1 972 756 0458 (Ext 1046)

91 98400 26014

-------
0
deepak
10/25/2007 7:29:02 AM

No print preview, but this will print only the specified <div> tag:

<form id="Form1" method="post" runat="server">
 <div id="Div1">
  Printable content
 </div>
 <input type="button" value="Print" onclick="JavaScript:printPartOfPage('Div1');">

<script type="text/javascript">
<!--
function printPartOfPage(elementId)
{
 var printContent = document.getElementById(elementId);
 var windowUrl = 'about:blank';
 var uniqueName = new Date();
 var windowName = 'Print' + uniqueName.getTime();
 var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');

 printWindow.document.write(printContent.innerHTML);
 printWindow.document.close();
 printWindow.focus();
 printWindow.print();
 printWindow.close();
}
// -->
</script>

</form>

NC...

0
NC01
10/25/2007 11:37:40 AM

You will have to loop through all controls in the page and hide the ones you dont want to display before calling the showPrintPreview function.  Then you will have to make the controls visible again after the print preview is done.

Best regards...


Josh Stodola ← Come check out my blog!
0
JoshStodola
10/25/2007 4:28:02 PM

This should also work:
<form id="Form1" method="post" runat="server">
 <div id="Div1">
  Printable content
 </div>
 <input type="button" value="Print" onclick="JavaScript:printPreviewDiv('Div1');">

 <script type="text/javascript">
 <!--
 function printPreviewDiv(elementId)
 {
  var printContent = document.getElementById(elementId);
  var windowUrl = 'about:blank';
  var uniqueName = new Date();
  var windowName = 'Print' + uniqueName.getTime();
  var printWindow = window.open(windowUrl, windowName, 'left=50000,top=50000,width=0,height=0');
  var printPreviewObject = '<object id="printPreviewElement" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';

  printWindow.document.write(printContent.innerHTML);
  printWindow.document.write(printPreviewObject);
  printWindow.document.write('<script language=JavaScript>');
  printWindow.document.write('printPreviewElement.ExecWB(7, 2);');
  printWindow.document.write('printPreviewElement.outerHTML = "";');
  printWindow.document.write('</script>');
  printWindow.document.close();
  printWindow.focus();
  printWindow.close();
 }
 // -->
 </script>
</form>

NC...

0
NC01
10/25/2007 5:44:25 PM

I considered that.  The only issue is that all styling of the DIV will be lost, and that is probably not desired.

Best regards...


Josh Stodola ← Come check out my blog!
0
JoshStodola
10/25/2007 6:37:42 PM

Yeah, I guess it would, but only if he is using a stylesheet. Static styles would still be rendered.

NC...

0
NC01
10/25/2007 7:01:40 PM

You mean inline styles?  Those are the devil.

Best regards...


Josh Stodola ← Come check out my blog!
0
JoshStodola
10/25/2007 7:34:25 PM

Yeah, I know! ;-(

NC...

 

0
NC01
10/26/2007 12:59:52 PM

Hi..

I use your code and it is work well but I have small problem and I don't know how I can solve itCrying

The direction of my page is from rtl because it is an arabic site I do that in the master page, when I use your code the columns of the grid view printed in reverse order I change the direction of master page and the div tag but it doesn't work..

 

What should I do?

Please help as fast as possible..

Thanks.. 

0
manal
12/14/2007 11:09:12 AM

Sorry, I have no idea since I have never tried printing backwards.

NC...

 

0
NC01
12/23/2007 12:20:51 PM

if you are loosing format or styles in the DIV, i would rather recommend setting up the IE option. Goto IE tools ->options > advanced -> print -> print background colors and images

0
sonu123
2/10/2008 7:17:35 AM

Yeah sonu123, but he wants the application to do it and the application has no access to the IE Tools to do that. Each individual user would need to change the settings on each print request.

NC...

0
NC01
2/10/2008 2:56:19 PM
Reply:

Similar Artilces:

Printing the Autosize height column is cutting the contents while printing or in print preview.
Hi , I have a tabular type datawindow report with long type column needed to be printed.This column is in the detail band & I have set the autosize height property on both the column & detail band.But sometimes in the last line half of a character is printed & the remaining half on the next page.For eg the upper part of 'Y' is printed on the last line & the remaining half of the above letter is printed on the first line of the next page.How do I solve this problem. Thanks , Mohan ...

How to use client side printer to print a stringbuilder content?
 Can anyone help me, regard this? Actually my requirement is to print a string builder content in client side default printer. For this i can use javascript "window.print()", but pbm is im developing touch screen application, window.print() will give UI to select printer.  My requirement is, it has to print the automatically into client default printer without any UserInterface. Is there any chance to do like that? Someone gave me MyControl class with ActiveX to achieve this, but i dont know how to use that, i tried it in somany ways but still it is detecting fo...

Print and print preview file on the website without using the File
Hi everyone, Is there any source code or help I can use to print and print preview my file on the IE and print the file using my own command instead of using the IE Print command. Please do reply me. Your help is greatly appreciated. Best regards....

Local Client-side printing using server vb.net code?
Hi,Rather than use the window.print() command which is just a form dump.  I want to use vb.net code to do this as it has all the features necessary.I came across this useful article from developers.com.  http://www.developer.com/net/net/article.php/3102381However, when I run this it throws an exception because there is no default printer attached to the server.  Of course I don't want to print server side - thats no good.  But print client side.  The users would print to whatever print queue on the network they have connected to their own pc.I thought ...

superreview requested: [Bug 126802] Printing while in print preview disabled on Unix : [Attachment 333675] patch to enable printing while in print preview
Leon Sha <leon.sha@sun.com> has asked Robert O'Callahan (:roc) (Mozilla Corporation) <roc@ocallahan.org> for superreview: Bug 126802: Printing while in print preview disabled on Unix https://bugzilla.mozilla.org/show_bug.cgi?id=126802 Attachment 333675: patch to enable printing while in print preview https://bugzilla.mozilla.org/attachment.cgi?id=333675&action=edit ...

superreview granted: [Bug 126802] Printing while in print preview disabled on Unix : [Attachment 333675] patch to enable printing while in print preview
Robert O'Callahan (:roc) (Mozilla Corporation) <roc@ocallahan.org> has granted Leon Sha <leon.sha@sun.com>'s request for superreview: Bug 126802: Printing while in print preview disabled on Unix https://bugzilla.mozilla.org/show_bug.cgi?id=126802 Attachment 333675: patch to enable printing while in print preview https://bugzilla.mozilla.org/attachment.cgi?id=333675&action=edit ...

print & print preview using javascript
Hello,I have a preformatted document in word, Now i want to know if there is some way in asp.net or javascript to print that doc but before printing i want to pick the recipeint names form the web form(say text box in web form) and then a print preview for the client and then get it printed. Its like same document with differnet recipents needs be printed. Thanks Vinod.  This article explains the samehttp://www.alistapart.com/articles/printtopreview  Vikram www.vikramlakhotia.comPlease mark the answer if it helped you...

Printing
Hi all. Can anyone help with the following. (PB 9.0) I have WYSIWYG forms with multi-line edit controls (Arial 10). Once the user has entered text in the mle, when they preview it it look as was entered. On printing, sometimes a word at the end will wrap onto the next line spoiling the WYSIWYG effect. Is this purely a printer driver problem, and is there a work around. Thanks. Mark. ...

print preview and print
Name: gladys reichlen Email: gladysdotreichlenatharrisdotcom Product: Firefox Summary: print preview and print Comments: print preview and print of website current screen just locks up in processing. when I cancel print, it closes firefox altogether. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0 From URL: http://hendrix.mozilla.org/ ...

Print from Print Preview
Name: Mairi Product: Firefox Summary: Print from Print Preview Comments: It would be very convenient if there was a print button in the print preview mode. Browser Details: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.6) Gecko/2009020410 Fedora/3.0.6-1.fc9 Firefox/3.0.6 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

I have a Canon MP980 printer. Everytime I print from an internet page or do a print preview, I can only do this once. When I press print or print preview a second time, Firefox instantly crashes.
Name: Tom Holleman Email: hollemanenglandatyahoodotcom Product: Firefox Summary: I have a Canon MP980 printer. Everytime I print from an internet page or do a print preview, I can only do this once. When I press print or print preview a second time, Firefox instantly crashes. Comments: The summary says it all. This did not occur with my HP printer. Browser Details: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b4) Gecko/20090423 Firefox/3.5b4 GTB5 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedb...

Contents of Textbox control not printing (using normal print button)
  Hi all, It is me again with some qn that I need to seek help on.Currently, in my form, I have a textbox control that is part of a repeater and it draws content from a databse. I have added some style attributes to change its formating. the code looks like this : <asp:Textbox id="txtRep2" Runat = "server" style="overflow:visible" ForeColor="Black" TextMode="MultiLine" BorderColor="#E0E0E0" BackColor="#EEEEEE" BorderStyle="None" text = '<%# DataBinder.Eval(Container, "DataItem.FieldValue")%>'></asp:Textbox>  And when the data that is drawn out is not a l...

Client-side printing w/o print dialog box
good day to all,i'm not sure if this is the right place for the topic, but can someone help/guide/point me to a source... here's what i want to do.. a page will display details about the current transaction, on the page, there will be a print button, once the user clicks the print button, it will print the transaction details on the client-side printer without showing the print dialog box... is it possible? thanks for all the helpJay Jose  To bypass print notification, there is an evil script here -http://groups.google.com/group/macromedia.coldfusion.cfml_general_discussi...

print print
i have data displayed in my datagrid now i want to print data how to do that. i have paging enabled in my grid.i want to pring data in normal a4 page so how much rows i have to display like how to make adjustments  Mark As Answer If my reply helped you. have a print button that changes the number of pages or sets enablePaging = false?  The you might as well use RegisterClientScriptBlock in that method to call window.print method :)David Kiffhttp://DavidKiff.co.uk-- "Mark As Answer" If my reply helped you -- And in conjuction to disabling paging you can apply a print...

Web resources about - Printing DIV Contents using Print Preview - asp.net.client-side

Printing - Wikipedia, the free encyclopedia
This article is about the process of reproducing text and images. For the handwriting method often called printing, see block letters . For other ...

Gelato Group Is Here To Democratize The World of Printing
... winning the Oslo Innovation Award 2015, we sat down with Henrik Müller-Hansen, Founder and CEO of Gelato Group. What Does Democratizing Printing ...

Apple Looks to Bring Multiple Colors to 3-D Printing with Patent Filing
... of an application by Apple ( AAPL ) for a 3-D Printer technology. The application for “systems, computer readable media, and methods for printing ...

3D printing helps give badly burned boy a new nose
After tragic accident, teen getting second chance at normal life thanks to new facial reconstructive surgery technology

How does Jay Leno get parts for his one-of-a-kind concept car? 3D printing, of course
The former talk-show host and massive car geek relies on new manufacturing techniques to provide parts you can't just pick up on Alibaba.

3D printing can recreate your vascular system for pre-op practice
... technology. With that in mind, physicians and researchers in Buffalo have worked with 3D printer maker Stratasys to develop a method of printing ...

3D printing files for guns are illegal in an Australian state
The Australian state of New South Wales has made it illegal to possess the blueprints necessary to make your own projectile weapons. Lawmakers ...

Sketch Life-Sized Objects With Sticky Tape Tubes Using This 3-D Printing Gun
Use the Protopiper to see if that new couch will really fit in your apartment. You won't need measuring tape. Imagine being able to sketch out ...

Is ISIS printing fake Syrian passports?
Is ISIS printing fake Syrian passports?

A Clever 3D Printer Fixes Printing Mistakes Instead of Starting Again From Scratch
The advent of 3D printing completely revolutionized the prototyping stage of designing a new product. But while turnaround times for revisions ...

Resources last updated: 12/12/2015 2:41:58 AM