locked
need to take printout using crystal report in asp.net RRS feed

  • Question

  • User486388719 posted

    need to take printout using crystal report in asp.net.

    i have text box if i enter date i need to show take printout for the particular date .without show the crystal report directly print.

    Monday, July 27, 2015 1:10 AM

All replies

  • User1724605321 posted

    Hi rajam,

    rajam

    have text box if i enter date i need to show take printout for the particular date .without show the crystal report directly print.

    Please use PrintToPrinter method to directly print crystal report:

    private void PrintReport(string printerName)
    {
       PageMargins margins;
    
       // Get the PageMargins structure and set the 
       // margins for the report.
       margins = Report.PrintOptions.PageMargins;
       margins.bottomMargin = 350;
       margins.leftMargin = 350;
       margins.rightMargin = 350;
       margins.topMargin = 350;
       // Apply the page margins.
       Report.PrintOptions.ApplyPageMargins(margins);
    
       // Select the printer.
       Report.PrintOptions.PrinterName = printerName;
    
       // Print the report. Set the startPageN and endPageN
       // parameters to 0 to print all pages.
       Report.PrintToPrinter(1, false,0,0);
    } 

    please refer to link below for more information:

    http://msdn.microsoft.com/en-us/library/aa691452%28VS.71%29.aspx

    Best Regards,

    Nan Yu

    Thursday, August 6, 2015 4:56 AM
  • User-271186128 posted

    Hi rajam,

    have text box if i enter date i need to show take printout for the particular date .without show the crystal report directly print.

    As for this issue, I suppose you need to use a timer to compare the particular date and the current time. If the current time is larger than the particular time, you could call the Print function to print crystal report.

    You could try to use Window setInterval() Method to create a timer, like this:

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
        <script type="text/javascript">
            $(document).ready(function () {
                var date = "";
                var timer;
                $("#btnPrint").click(function () {
                    //Get the particular date 
                    date = $("#txtDate").val();
                    timer = setInterval(function () { checkDate() }, 300);
                    return false;
                });
    
                function checkDate() {
                    //Compare current date time and the particular date 
                    if (Date.now() >= new Date(date)) {
                        
                        alert("Print");
    
                        //call print funcation to print crystal report 
    
                        clearInterval(timer);
                    }
                }
            });
        </script>
        <div>
            <asp:TextBox ID="txtDate" runat="server" Text=""></asp:TextBox>
            <asp:Button ID="btnPrint" runat="server" Text="Print at the particular date" />
        </div>

    The code in print function:

    <script type="text/javascript">
    function Print() {
        var dvReport = document.getElementById("dvReport");
        var frame1 = dvReport.getElementsByTagName("iframe")[0];
       if (navigator.appName.indexOf("Internet Explorer") != -1) {
            frame1.name = frame1.id;
            window.frames[frame1.id].focus();
            window.frames[frame1.id].print();
        }
        else {
            var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
            frameDoc.print();
        }
    }
    </script>

    For more details about the print function, please refer to the following link:

    http://www.aspsnippets.com/Articles/Print-Crystal-Report-on-Client-Side-on-Button-Click-using-JavaScript-in-ASPNet.aspx

    Best Regards,
    Dillion

    Thursday, August 6, 2015 5:04 AM