Click here to Skip to main content
14,240,044 members
Rate this:
Please Sign up or sign in to vote.
I am using PrintToPrinter to print crystal report with page range,

It is working fine in my local computer bycause there is printer installed.

But when i am deploying that code on server than it is giving a message that Printer is not installed because there is no installed printer on server.

But i want to print through clients system I mean i want client side printing in crystal report so it will use client's printer not server printer.

Than What should i suppose to do.

Any suggestions will be highly appreciable.

What I have tried:

Dim rpdt As New ReportDocument

Dim query As String = "select * from V_INV_GETINVOICERPTPRINT1 where invoiceid='" + ddlInvoiceNo.SelectedValue + "'"
Dim dsLoad As New DataSet
dsLoad = objService.Exec_Dataset1(query)

Dim InvoiceType As String = element
dsLoad.Tables(0).Rows(0)("COPY") = InvoiceType
CrystalReportViewer1.ReportSource = rpdt

CrystalReportViewer1.Visible = True

rpdt.PrintOptions.PrinterName = GetDefaultPrinter()
rpdt.PrintToPrinter(1, False, 1, 1)

Private Function GetDefaultPrinter() As String
        Dim settings As PrinterSettings = New PrinterSettings()
        For Each printer As String In PrinterSettings.InstalledPrinters
            settings.PrinterName = printer
            If settings.IsDefaultPrinter Then
                Return printer
            End If
        Return String.Empty
    End Function
Updated 9-Jul-19 20:00pm

1 solution

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

Solution 1

All VB code runs on the Server, not the Client: this seemed to work in development because both Server and Client were running on the same machine.

Since your VB code runs on the S, it only has access to Server hardware; it can't use any Client resources such as printers. Think about it: if you could, so could malicious sites - and if you are old enough to remember faxes, you'll know the frustration when you get into the office on Monday morning to find all the fax paper had been used up by 18:00 of the previous Friday by Viagra adverts ... so any work faxes did not get through.

You can't print from the Server, and while you can convert it to a PDF file which you send to the Client, you can't control what happens to it - the user can print it if he wishes, but you can't tell his browser to do that.

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

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