3

I have HTML document as byte[] retrieved from SSRS and i want to print it in C5 paper format in landscape representation. I use IE for printing, but i don't know how to tell him to print my document in landscape C5 mode. Suggestions?

var envelope = proxy.Render(
                    Format, DevInfo, out extension, out mimeType, out encoding, out warnings, out streamIDs);

                using (FileStream fStream = File.Create(string.Format(@"printtmp\envelope_{0}.html", i)))
                {
                    fStream.Write(envelope, 0, envelope.Length);
                }
                var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"printtmp\envelope_{0}.html", i));

                var ie = new InternetExplorer();
                ie.PrintTemplateTeardown += disp =>
                    {
                        File.Delete(path);
                        ie.Quit();
                    };
                ie.DocumentComplete += (object disp, ref object url) =>
                {
                    ie.ExecWB(OLECMDID.OLECMDID_PRINT, OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, Type.Missing, Type.Missing);
                };

                ie.Navigate(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
noseratio
  • 59,932
  • 34
  • 208
  • 486
Dzmitry Martavoi
  • 6,867
  • 6
  • 38
  • 59

2 Answers2

1

You'd need to create a print template and provide your own DEVMODE, configured for specific printer, paper size and orientation. It's tricky but do-able, use the information from this excellent blog post by Marc Durdin. You could also find some more information about print templates in my answer to your related question about paper orientation, which I saw first.

Community
  • 1
  • 1
noseratio
  • 59,932
  • 34
  • 208
  • 486
0

As far as I know you cannot set or modify browser (client side) properties from server side, for that kind of interactivity you should try an ActiveX, Java or Silverlight solution.

One applet for that is jZebra, I haven't used it but you can find some info in jZebra Tutorial

Another recommendation is that you show a popup with the instructions about "How to change paper size, and make it default" before you print.

Carlos487
  • 1,459
  • 13
  • 17
  • but how can i change default settings for IE printing (C5, landscape)? – Dzmitry Martavoi Sep 30 '13 at 15:20
  • Maybe jZebra will provide some kind of API, if not I think is not posible, for security reason web browser can't give access to that kind of configurations. In cases as yours the configuration should be done manually on PC and set to default, or maybe search/develop a browser plugin or extension – Carlos487 Sep 30 '13 at 18:52
  • 'WebBrowser' - it is a win forms control :) see http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.aspx – Dzmitry Martavoi Sep 30 '13 at 18:59
  • Correct me if I'm wrong but if you are inside a WinForms Application wouldn't be better to user the native report viewer control [link](http://technet.microsoft.com/en-us/library/aa337089.aspx). – Carlos487 Oct 01 '13 at 16:15