How to set printer settings in code behind.?

Last post 11-14-2008 4:16 AM by surveera. 10 replies.

Sort Posts:

  • How to set printer settings in code behind.?

    04-22-2008, 5:37 AM
    • Member
      14 point Member
    • bhappy
    • Member since 07-30-2007, 1:10 PM
    • Posts 211

    Hai All,

    I want to set printer settings in code behind like Landscope="true" and page scalling="Fit to page", bcuz im having more columns in my datagrid.

    Thanks,

    Aswath. 

    Filed under:
  • Re: How to set printer settings in code behind.?

    04-22-2008, 6:21 AM
    • All-Star
      45,902 point All-Star
    • jimmy q
    • Member since 11-02-2006, 9:01 AM
    • Australia
    • Posts 3,172
    • Moderator
      TrustedFriends-MVPs

     

    ASP.NET is server side language hence it cannot manipulate the client side machine.

    What you can do is use javascript Print() method to raise the printer dialog where the user can select landscape mode 

  • Re: How to set printer settings in code behind.?

    04-22-2008, 6:28 AM
    • Member
      14 point Member
    • bhappy
    • Member since 07-30-2007, 1:10 PM
    • Posts 211

     Hai

    Thanks for ur replay,

    Currently im using javascript print function only, If user donot select landscape and Fit to Page options then in printout he won't get last columns.........?

    Any other idea plz...........

    Thanks,

    Aswath. 

  • Re: How to set printer settings in code behind.?

    04-22-2008, 6:54 AM
    • Star
      14,224 point Star
    • JeffreyABecker
    • Member since 10-04-2004, 8:27 AM
    • Philadelphia, PA
    • Posts 2,908

     There's no way to change the clients printer settings in a web applicaiton.  as I see it, you have two options

    1) User Education & Training

    2) Output your reports in pdf.

     

     

  • Re: How to set printer settings in code behind.?

    04-22-2008, 7:02 AM
    • Member
      14 point Member
    • bhappy
    • Member since 07-30-2007, 1:10 PM
    • Posts 211

     Hai,

    Thanks for ur response,

    Can u explain me indetail, i donot get what u want to say?plz............

    Thanks,

    Aswath. 

  • Re: How to set printer settings in code behind.?

    04-22-2008, 7:07 AM
    • Contributor
      2,727 point Contributor
    • thirumaran007
    • Member since 03-14-2007, 5:39 AM
    • India
    • Posts 566

    Hi Friend,

    Just use javascript to do that,

     

    <script language="javascript" type="text/javascript">
    function
    PrintDiv()
    {
        var myContentToPrint = document.getElementById("dv01");
        var myWindowToPrint = window.open('','','width=800,height=600,toolbar=0,scrollbars=-1,status=0,resizable=-1,location=0,directories=0');
        myWindowToPrint.document.write(myContentToPrint.innerHTML);
        myWindowToPrint.document.close();
        myWindowToPrint.focus();
        myWindowToPrint.print();

        myWindowToPrint.close();
    }

    </script> 

    With Friendly,
    Thirumaran

    Please remember to click "Mark as Answer" on this post if it helped you
  • Re: How to set printer settings in code behind.?

    04-22-2008, 7:10 AM
    Answer
    • All-Star
      45,902 point All-Star
    • jimmy q
    • Member since 11-02-2006, 9:01 AM
    • Australia
    • Posts 3,172
    • Moderator
      TrustedFriends-MVPs

    bhappy:
    Can u explain me indetail, i donot get what u want to say?plz............
     

    Basically what we are trying to say is that ASP.NET has no way to do what you want which is to configure the end user machine, unless you start delving into activeX, applets.

    You are better off educating your user base to manually set the landscape mode from the printer dialog page.

     

  • Re: How to set printer settings in code behind.?

    04-22-2008, 7:11 AM
    • Contributor
      2,727 point Contributor
    • thirumaran007
    • Member since 03-14-2007, 5:39 AM
    • India
    • Posts 566

    I think we can implement in codebehind..

    just look at the sample code...

    Sub Submit_Click(ByVal sender As Object, ByVal e As EventArgs)


    Try


    Dim pd as New PrintDocument()


    ' Set the printer name.


    pd.PrinterSettings.PrinterName = "\\NS5\hpoffice"


    AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage


    pd.Print()


    Catch ex as Exception


    Response.Write("Error: " & ex.ToString)


    End Try


    End Sub

     

    With Friendly,
    Thirumaran

    Please remember to click "Mark as Answer" on this post if it helped you
  • Re: How to set printer settings in code behind.?

    04-22-2008, 7:14 AM
    • Member
      14 point Member
    • bhappy
    • Member since 07-30-2007, 1:10 PM
    • Posts 211

     Hai,

    Thanks for ur replay,

    I have some queries,

    1) where i need to call this function..??

    2)what is "dv01" ie, var myContentToPrint = document.getElementById("dv01"); ..??

     Thanks,

    Aswath. 

  • Re: How to set printer settings in code behind.?

    04-22-2008, 10:40 AM
    Answer
    • Star
      14,224 point Star
    • JeffreyABecker
    • Member since 10-04-2004, 8:27 AM
    • Philadelphia, PA
    • Posts 2,908

     unfortunately neither of thirumaran007's posts will help you.  The first post is an example of how to open up the print dialog for the user via javascript.  however this wont affect their printer settings.  The second post is an example of changing printer settings but it changes the server's printer settings and not the user's printer settings.  As I said before this type of thing is a matter of user education.  You'll just have to train them to adjust the printer settings properly.  The only other option is for you to provide your reports in pdf rather than html.  Pdf supports much more fine grained control over your printed page layout than html.

  • Re: How to set printer settings in code behind.?

    11-14-2008, 4:16 AM
    • Member
      6 point Member
    • surveera
    • Member since 11-14-2008, 4:01 AM
    • Posts 3

     AddressOf Me.pd_PrintPage

    in these what is pd_PrintPage 

    Filed under:
Page 1 of 1 (11 items)
Microsoft Communities