Client Side Printing

Posted on 2009-05-24
Medium Priority
Last Modified: 2012-05-07
i have an asp.net website.

i have created multiple reports and now one of the requirements is to print the reports on the client printer. i am able to achieve this using Javascript but all the formating goes out.

Now what other alternative i have to do the same. appreciate if some1 can help me out on this
Appreciate if some can help me solve this issue.
Question by:AsishRaj
  • 5
  • 2
LVL 10

Expert Comment

ID: 24464444
include a css print stylesheet
<link rel="stylesheet" media="print" href="print.css" />

in that css file just hide all the unnecessary elements (like nav bars etc) and set all the widths and styles to fit. in your testing remove media="print" so you can see it on screen but then add it back in to apply it to print only

Author Comment

ID: 24464472
i should have mentioned earlier

i printing crystal report on button click.  Code snippet included

print_content only includes the crystal report and nothing else. i am having issue with Crystal Report Layout.

function Clickheretoprint()
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=650, height=600, left=100, top=25"; 
  var content_vlue = document.getElementById("print_content").innerHTML; 
  var docprint=window.open("","",disp_setting); 
   docprint.document.write('</head><body onLoad="self.print()" style="padding: 0px; margin: 0px"><center>');          
   var hiddenControl = '<%= CR_PrintLetter.ClientID %>';
   document.getElementById(hiddenControl).style.display = 'none' 

Open in new window

LVL 11

Accepted Solution

Muhammad Ousama Ghazali earned 2000 total points
ID: 24464481
If you are using VS-built in Crystal Reports you may acheive what you are trying to do. The solution that CR provides is actually a mix of sever and client side and by default the printing from the CR is in PDF format so whenever you print a report using the button on the CR control in the webpage, it will automatically create a PDF on the server side as per your page selection and will prompt you to either download or open the PDF which actually can later be printed on the local printer but off course the user have to interact in this scenario with first printing the PDF and then later printing the hard copy from the PDF.
However, there is another option in addition to PDF supported by CR but only on Internet Explorer and utilizes ActiveX. You specify the location of printer-ActiveX in the web.config as mentioned in the code snippet below while you can download this ActiveX from the CR site too and if you need it I can upload it for you too. In addition to specifying this in web.config, you need to set the CR viewer control's PrintMode property to ActiveX from Pdf. Remember, if CR detects it's a non-ActiveX supported browser, it'll automatically switch to PDF mode.
Hope this helps.

			<add key="url" value="http://mywebsiteurl/Installers/PrintControl.cab"/>

Open in new window

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 24468360
yeah, i think thats is a nice way out. appreciate if you can upload the activeX here, so that other people looking at this thread can benefit as well.

Author Comment

ID: 24469010

i was trying to get it from CR site but couldnt find it

Author Comment

ID: 24470240
one question

does printcontrol.cab version needs to be same as the CR version installed with the VS 2008
LVL 11

Assisted Solution

by:Muhammad Ousama Ghazali
Muhammad Ousama Ghazali earned 2000 total points
ID: 24470554
The PrintControl is same for VS2005 and VS2008 as we have deployed it in our web applications in both versions.
I tried uploading the PrintControl.cab file but even from within the archive (.zip) EE is not allowing to upload.
Please browse to the following URL and download the .cab file from there:
Just before posting I found a direct link for the cab file and here it is:
Further, see these two links for documentation on printControl:
Hope this helps.

Author Closing Comment

ID: 31584922
Thanks for the help. It took me a while to figure out how to do it. Really helpful Links

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

619 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question