Last post Jan 05, 2012 08:20 AM by cnranasinghe
Jan 02, 2012 06:39 AM|chennuri|LINK
I need help.
I am currently developing a web application to print a crystal report directly to the client's printer. The application works well in my pc but when I post the application to our web server, instead of retrieving
the printer list in client's pc, the application is trying to look for printers that are installed in the server machine.
I developed my application using C# and I am using
System.Drawing.Printing.PrinterSettings.InstalledPrinters to retrieve the printer list I
realised it only trying to retrieve printer installed in the local machine.
Is there any way to get the list of installed printer in the client computer?
Thanks in advance.
Jan 02, 2012 07:39 AM|morefays|LINK
You cannot reterive the printer from client pc .there is only way to create one active-x control register with sn key and then used this active-x when you redirect to report page on that page active-x will download and retervie the printers of client pc
if client allow to run the active-x control otherwise there is no other way.
Jan 02, 2012 08:40 AM|chennuri|LINK
Thanks for your reply. But Active-X controls are not supported by Google Chrome and Firefox. So how can i use Crystalreports.PrintToPrinter method?
works fine when i run the application locally. But after published to web server it is not working because no printer is installed in server. My problem is print should be done on client pc.
Please give me the suggestion on this.
Thanks in advance
Jan 03, 2012 05:41 AM|morefays|LINK
I think you try silverlight control check this link .Second why you need client printer in crystal report by default in crystal report toolbar printer option is there can you explain your requirment may be there is another way.
Jan 03, 2012 06:34 AM|chennuri|LINK
Thanks for your replies.
I have bulk of invoices to print. If i use Print button in crystal reportviewer it may take more time to print as well as i need to click print button everytime when i select bulk of invoices to print. So that i thought to give the print directly to the
printer. Please help me on this. I am struggling alot with this.My requirement is ASP.net with C#.net
I think i explained you clearly. If any questions let me know. Its very urgent for me.
Jan 03, 2012 08:06 AM|cnranasinghe|LINK
Jan 03, 2012 09:27 AM|chennuri|LINK
Thanks for your reply.Can you post some example code to achieve this. So that it will help to me.
Jan 03, 2012 11:29 AM|cnranasinghe|LINK
Following is a code sample for Microsoft report. You have to find the way to export CR to pdf. this will not be hard. i have metioned which line be replaced. Also you need to download ItextSharp.dll. you can find from google.
Add following frame to html markup
<iframe id="frmPrint" name="IframeName" width="500" height="200" runat="server" style="display: none" runat="server"></iframe>
refer following libraries
Add below code in a button click or page load,
//// remove the below line and replace crystal report export pdf funciton, coz following line intended to microsoft report, what is happening here report is render as pdf to byte array
byte bytes = View.ReportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("output.pdf"), FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
//Open exsisting pdf
Document document = new Document(PageSize.LETTER);
PdfReader reader = new PdfReader(HttpContext.Current.Server.MapPath("output.pdf"));
//Getting a instance of new pdf wrtiter
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Server.MapPath("Print.pdf"), FileMode.Create));
PdfContentByte cb = writer.DirectContent;
int i = 0;
int p = 0;
int n = reader.NumberOfPages;
Rectangle psize = reader.GetPageSize(1);
float width = psize.Width;
float height = psize.Height;
//Add Page to new document
while (i < n)
PdfImportedPage page1 = writer.GetImportedPage(reader, i);
cb.AddTemplate(page1, 0, 0);
//Attach pdf to the iframe
Hope this will help.
Jan 04, 2012 09:54 AM|chennuri|LINK
Thanks for your replies. Please find the below code. It is working fine in my local system. But not in web server.
CrystalReport rptinv=new CrystalReport ();
//this will load the data which is going to print to crystal report
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
//get no.of copies,start page and end page of report
ncopies = printDocument.PrinterSettings.Copies;
startpage = printDocument.PrinterSettings.FromPage;
endpage = printDocument.PrinterSettings.ToPage;
//set printer name to the crystal report
if (printDocument.PrinterSettings.PrinterName != "")
rptinv.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
//this command will directly give print to the printer
rptinv.PrintToPrinter(ncopies, true, startpage, endpage);
Please suggest me on this.
Jan 04, 2012 11:22 AM|cnranasinghe|LINK
As to my understanding, your code would work in web server and print job will be sent to the printer which is attached to the web server. You can not use this code to send the print job client printer.
Jan 04, 2012 11:52 AM|chennuri|LINK
Thanks for your valuable reply.Yes exactly. How to send the print job to client printer. Please help me
Jan 05, 2012 04:34 AM|cnranasinghe|LINK
Do you want to send the print job to client pc without asking print dialog box?
Jan 05, 2012 05:10 AM|chennuri|LINK
yes exactly..without asking print dialog box, send the print job to client pc.Please help me on this
Jan 05, 2012 05:36 AM|morefays|LINK
try this code
string value1 = "abc";
string value2= "foo";
ReportDocument rd = new ReportDocument();
rd.PrintOptions.PrinterName = pd.PrinterSettings.PrinterName;
check this link http://aspalliance.com/509_Automatically_Printing_Crystal_Reports_in_ASPNET.2
Jan 05, 2012 05:58 AM|chennuri|LINK
Thanks for your reply. I think "pd" is the object for "System.Drawing.Printing.PrintDocument".
I have tried by keeping "false" in "PrintToPrinter" method. But its not worked for me. I need to print the report in client pc without asking the printdialog. Can you please suggest on this.
Jan 05, 2012 08:20 AM|cnranasinghe|LINK
Above link sends the printer job to default printer. As far as i remember IE prints directly but FireFox prompts the print dialog. You have to alter the script as necessary. Unfortunatly there is less documentation on this.
Hope this would goid u a lil bit.