Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to Set Printer Settings Programatically?

How to Set Printer Settings Programatically?

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    D4ever
    wrote on last edited by
    #1

    Hi, I am using window.print() to print the current window from Asp.net(VB) but now i want to set page size,printer name ,Orientation etc Programatically Please help me.

    Darshana Pathak

    A N 2 Replies Last reply
    0
    • D D4ever

      Hi, I am using window.print() to print the current window from Asp.net(VB) but now i want to set page size,printer name ,Orientation etc Programatically Please help me.

      Darshana Pathak

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      u can set printer settings from the dialog box that comes when window.print is invoked... Check Properties... You cant change the default settings of the PRint dialog box from code. Its because of security issue.. But there is a way for IE users to call WScript.Shell. try out the code:

      var shell;
      function SetPrintProperties() {
      try {
      shell = new ActiveXObject("WScript.Shell");
      shell.SendKeys("%fu");
      window.setTimeout("javascript:SetPaperSize();", 400);
      } catch (e) {
      alert('Please verify that your print settings have a Landscape orientation and minimum margins.');
      }
      }

      function SetPaperSize() {
      shell.sendKeys("%a{TAB}.2{TAB}0{TAB}0{TAB}0{ENTER}");
      }

      But I dont recommend this as its browser specific and not a good practice to change settings without users consent.... :rose: Abhishek Sur

      D 1 Reply Last reply
      0
      • D D4ever

        Hi, I am using window.print() to print the current window from Asp.net(VB) but now i want to set page size,printer name ,Orientation etc Programatically Please help me.

        Darshana Pathak

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        JS can't do this. Might be some activex controls can do.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        1 Reply Last reply
        0
        • A Abhishek Sur

          u can set printer settings from the dialog box that comes when window.print is invoked... Check Properties... You cant change the default settings of the PRint dialog box from code. Its because of security issue.. But there is a way for IE users to call WScript.Shell. try out the code:

          var shell;
          function SetPrintProperties() {
          try {
          shell = new ActiveXObject("WScript.Shell");
          shell.SendKeys("%fu");
          window.setTimeout("javascript:SetPaperSize();", 400);
          } catch (e) {
          alert('Please verify that your print settings have a Landscape orientation and minimum margins.');
          }
          }

          function SetPaperSize() {
          shell.sendKeys("%a{TAB}.2{TAB}0{TAB}0{TAB}0{ENTER}");
          }

          But I dont recommend this as its browser specific and not a good practice to change settings without users consent.... :rose: Abhishek Sur

          D Offline
          D Offline
          D4ever
          wrote on last edited by
          #4

          i tried it but its not working

          Darshana Pathak

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups