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. General Programming
  3. C#
  4. Printing Bytes to printer in MVC

Printing Bytes to printer in MVC

Scheduled Pinned Locked Moved C#
asp-netcomjsonarchitecturehelp
13 Posts 5 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.
  • N Offline
    N Offline
    nitin_ion
    wrote on last edited by
    #1

    Below code works well for printing PDF when we have physical file. But when we have bytes[] then it will not work. Is there a way we can print bytes[] to printer without showing the print dialog box.

    private static void PrintPDF(string FileToPrint)
    {
    PrinterSettings setting = new PrinterSettings();
    var printerName = setting.PrinterName;

            ProcessStartInfo info = new ProcessStartInfo(FileToPrint);
            info.Verb = "Print";
            info.CreateNoWindow = true;
            info.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(info);
        }
    

    There is a Microsoft Knowledge base article on this particular problem. Here in the article they send byte[] to the printer using Winspool API of Windows OS. but i don't feel it is optimized for web. http://support.microsoft.com/kb/322091

    Kornfeld Eliyahu PeterK L D 3 Replies Last reply
    0
    • N nitin_ion

      Below code works well for printing PDF when we have physical file. But when we have bytes[] then it will not work. Is there a way we can print bytes[] to printer without showing the print dialog box.

      private static void PrintPDF(string FileToPrint)
      {
      PrinterSettings setting = new PrinterSettings();
      var printerName = setting.PrinterName;

              ProcessStartInfo info = new ProcessStartInfo(FileToPrint);
              info.Verb = "Print";
              info.CreateNoWindow = true;
              info.WindowStyle = ProcessWindowStyle.Hidden;
              Process.Start(info);
          }
      

      There is a Microsoft Knowledge base article on this particular problem. Here in the article they send byte[] to the printer using Winspool API of Windows OS. but i don't feel it is optimized for web. http://support.microsoft.com/kb/322091

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      What all this has with the Web? The code you show us here is part of the server side, means it print on the printer connected to the server? It may looks like working correctly while in debug environment, but will surprise you after publishing? Or do you mean to post out all the printed documents later on the week?

      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      N 1 Reply Last reply
      0
      • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

        What all this has with the Web? The code you show us here is part of the server side, means it print on the printer connected to the server? It may looks like working correctly while in debug environment, but will surprise you after publishing? Or do you mean to post out all the printed documents later on the week?

        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

        N Offline
        N Offline
        nitin_ion
        wrote on last edited by
        #3

        The code given works well with physcial files I meant the KB article that code i dont feel is optimized

        Kornfeld Eliyahu PeterK 1 Reply Last reply
        0
        • N nitin_ion

          The code given works well with physcial files I meant the KB article that code i dont feel is optimized

          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu Peter
          wrote on last edited by
          #4

          It seem that you didn't read or understood what I've wrote... That code - and your code too - can not be, and need not be optimized to the web as it runs on the server!

          I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

          "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

          N 1 Reply Last reply
          0
          • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

            It seem that you didn't read or understood what I've wrote... That code - and your code too - can not be, and need not be optimized to the web as it runs on the server!

            I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

            N Offline
            N Offline
            nitin_ion
            wrote on last edited by
            #5

            Since it runs on server my only concern is when i run it to print too many pdf t slows down when multiple requests are hit. If there a better way of printing bytes[] to printer

            Kornfeld Eliyahu PeterK 1 Reply Last reply
            0
            • N nitin_ion

              Since it runs on server my only concern is when i run it to print too many pdf t slows down when multiple requests are hit. If there a better way of printing bytes[] to printer

              Kornfeld Eliyahu PeterK Offline
              Kornfeld Eliyahu PeterK Offline
              Kornfeld Eliyahu Peter
              wrote on last edited by
              #6

              It is acceptable that printing will slow down with much request (print queue is full), but I have a strong feeling that you do ot know what are you doing here. Let see an example. Code Project has 'Terms of Service' page stuffed with legal do and don't do. Let imagine that you had a print button on this page. What would happened if on every click on that button a copy of that 'Term of Service' was printed in Toronto, Canada? What Code Project staff should do with all that prints? And what the CPian who asked to print will do without that important paper?

              I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

              "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

              N 1 Reply Last reply
              0
              • N nitin_ion

                Below code works well for printing PDF when we have physical file. But when we have bytes[] then it will not work. Is there a way we can print bytes[] to printer without showing the print dialog box.

                private static void PrintPDF(string FileToPrint)
                {
                PrinterSettings setting = new PrinterSettings();
                var printerName = setting.PrinterName;

                        ProcessStartInfo info = new ProcessStartInfo(FileToPrint);
                        info.Verb = "Print";
                        info.CreateNoWindow = true;
                        info.WindowStyle = ProcessWindowStyle.Hidden;
                        Process.Start(info);
                    }
                

                There is a Microsoft Knowledge base article on this particular problem. Here in the article they send byte[] to the printer using Winspool API of Windows OS. but i don't feel it is optimized for web. http://support.microsoft.com/kb/322091

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                nitin_ion wrote:

                but i don't feel it is optimized for web.

                Of course it isn't; it is for use in desktop applications.

                N 1 Reply Last reply
                0
                • Kornfeld Eliyahu PeterK Kornfeld Eliyahu Peter

                  It is acceptable that printing will slow down with much request (print queue is full), but I have a strong feeling that you do ot know what are you doing here. Let see an example. Code Project has 'Terms of Service' page stuffed with legal do and don't do. Let imagine that you had a print button on this page. What would happened if on every click on that button a copy of that 'Term of Service' was printed in Toronto, Canada? What Code Project staff should do with all that prints? And what the CPian who asked to print will do without that important paper?

                  I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                  N Offline
                  N Offline
                  nitin_ion
                  wrote on last edited by
                  #8

                  even though it runs on server but the printer it picks is local to system and not related to server. what i was asking was is there a better way of doing this instead of using interop's

                  Kornfeld Eliyahu PeterK 2 Replies Last reply
                  0
                  • L Lost User

                    nitin_ion wrote:

                    but i don't feel it is optimized for web.

                    Of course it isn't; it is for use in desktop applications.

                    N Offline
                    N Offline
                    nitin_ion
                    wrote on last edited by
                    #9

                    so is there a way of doing it efficiently on web [printing bytes directly to printer]

                    P 1 Reply Last reply
                    0
                    • N nitin_ion

                      even though it runs on server but the printer it picks is local to system and not related to server. what i was asking was is there a better way of doing this instead of using interop's

                      Kornfeld Eliyahu PeterK Offline
                      Kornfeld Eliyahu PeterK Offline
                      Kornfeld Eliyahu Peter
                      wrote on last edited by
                      #10

                      Quote:

                      the printer it picks is local to system

                      You are kidding, right? How on earth the server knows about locally installed printers!!! Imagine that you are browsing a site that hosted on a server in the UK, should that server know anything about your hardware setup and installed rivers in you office in India?! Think about it!

                      I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                      1 Reply Last reply
                      0
                      • N nitin_ion

                        even though it runs on server but the printer it picks is local to system and not related to server. what i was asking was is there a better way of doing this instead of using interop's

                        Kornfeld Eliyahu PeterK Offline
                        Kornfeld Eliyahu PeterK Offline
                        Kornfeld Eliyahu Peter
                        wrote on last edited by
                        #11

                        Quote:

                        the printer it picks is local to system

                        You are kidding, right? How on earth the server knows about locally installed printers!!! Imagine that you are browsing a site that hosted on a server in the UK, should that server know anything about your hardware setup and installed drivers in you office in India?! Think about it!

                        I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)

                        "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

                        1 Reply Last reply
                        0
                        • N nitin_ion

                          so is there a way of doing it efficiently on web [printing bytes directly to printer]

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #12

                          Not directly. What you would have to do is implement an addon for the web browser and control the printing from that (oh, and you'd have to take into account the OS that the website was browsing as well). This isn't a trivial task, and a lot of organisations would bar this control from being installed.

                          1 Reply Last reply
                          0
                          • N nitin_ion

                            Below code works well for printing PDF when we have physical file. But when we have bytes[] then it will not work. Is there a way we can print bytes[] to printer without showing the print dialog box.

                            private static void PrintPDF(string FileToPrint)
                            {
                            PrinterSettings setting = new PrinterSettings();
                            var printerName = setting.PrinterName;

                                    ProcessStartInfo info = new ProcessStartInfo(FileToPrint);
                                    info.Verb = "Print";
                                    info.CreateNoWindow = true;
                                    info.WindowStyle = ProcessWindowStyle.Hidden;
                                    Process.Start(info);
                                }
                            

                            There is a Microsoft Knowledge base article on this particular problem. Here in the article they send byte[] to the printer using Winspool API of Windows OS. but i don't feel it is optimized for web. http://support.microsoft.com/kb/322091

                            D Offline
                            D Offline
                            Dave Kreskowiak
                            wrote on last edited by
                            #13

                            You can't do it using that code. It's that simple. That code is written to launch the application that knows how to edit the file and then tells that application to print the file that is passed to it. This technique will NOT work with an array of bytes because you have no way of getting those bytes to the application that will actually handle the printing operation. You cannot do what you want and most certainly can't do it from ASP.NET code running on the server.

                            A guide to posting questions on CodeProject

                            Click this: Asking questions is a skill. Seriously, do it.
                            Dave Kreskowiak

                            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