1

What I'm trying to do is get this to print in landscape mode without showing the dialog box. This is what I have so far:

((mshtml.IHTMLDocument2)Browser.Document.DomDocument).execCommand("Print", true, 0);

I know that the instruction to print in landscape mode needs to be sent through the third argument, but I don't know how to construct the third argument to do this. Can anyone give me some help on how to make this last argument accomplish my goal?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
sooprise
  • 22,657
  • 67
  • 188
  • 276
  • 1
    possible duplicate of http://stackoverflow.com/questions/4970377/printing-in-landscape-mode-from-a-webbrowser-control – froeschli Feb 11 '11 at 23:19
  • @froeschli That does not answer the question at all. It might be a simular or better yet RELATED question but it definitely does NOT answer the question asked. He wants to know what to use for the third param and that question you reference only shows how to use the method itself. The other question only gives you an impression that you need to use a path to a file that is being used as a template and does not give you any ideas as to what you actually need to do for the template itself. – Arvo Bowen Feb 03 '16 at 15:13

2 Answers2

1

I mostly stick to desktop apps and I don't know how to do what you want. But I did take a quick look at the msdn documentation, and it seems the "Print" command (IDM_EXECPRINT) may not be what you're looking for? According to the documentation for the method, the second parameter should be false if you do not want to display a user interface. That sounds fine except that it looks like the IDM_EXECPRINT command always displays a dialog regardless ("User interface: Yes. Set parameter to true or omit").

msdn documentation: IHTMLDocument2::execCommand Method, IDM_EXECPRINT

Someone please correct me if I'm wrong, but I think you may want to look for another command.

Edit: You might have better luck with the IDM_PRINT command from mshtmcid.h, the dialog is optional for this command. Here's a sample application (in C++): http://msdn.microsoft.com/en-us/library/bb250434(VS.85).aspx

matt.dolfin
  • 672
  • 4
  • 9
0

ADDITIONS: This is from Microsoft http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.defaultpagesettings%28v=vs.71%29.aspx

public void Printing()
{
   try
   {
      streamToPrint = new StreamReader (filePath);
      try
      {
         printFont = new Font("Arial", 10);
         PrintDocument pd = new PrintDocument(); 
         pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
         pd.PrinterSettings.PrinterName = printer;
         // Set the page orientation to landscape.
         pd.DefaultPageSettings.Landscape = true;
         pd.Print();
      } 
      finally
      {
         streamToPrint.Close() ;
      }
   } 
   catch(Exception ex)
   { 
      MessageBox.Show(ex.Message);
   }
}

So you would probably just replace pd in the example above with your document.


ORIGINAL ANSWER: Possibly integrate:

DefaultPageSettings.Landscape = true;

So maybe something like this:

((mshtml.IHTMLDocument2)Browser.Document.DomDocument).DefaultPageSettings.Landscape = true;
((mshtml.IHTMLDocument2)Browser.Document.DomDocument).execCommand("Print", true, 0);

Taking a little bit of a stab in the dark since C# is a weak spot but I believe this is how I once did it from an C# application.

Eli
  • 716
  • 1
  • 6
  • 12
  • .DefaultPageSettings is not available. Was there a different way to do this? – sooprise Feb 14 '11 at 13:53
  • That method works for documents, but I'm specifically looking for a way to print in landscape from a browser. It's unbelievable how hard it is to find a solution for this, I do appreciate your answer though :) – sooprise Feb 16 '11 at 15:12
  • Does it allow you to do it if you replace **`pd.`** with **`((mshtml.IHTMLDocument2)Browser.Document.DomDocument).`**? Almost like an on-the-fly webpage to document write and then print...? – Eli Feb 16 '11 at 17:16
  • How would you "just replace pd in the example"? browser.Document is an `object` and doesn't have a `DomDocument` property. – epalm Jan 09 '15 at 16:58