3

I'm trying to print from silverlight without a print dialog and for that I'm using System.Runtime.InteropServices.Automation;

Right now I'm creating a temporary txt file that contain the text to send to printer.

using (dynamic fso = AutomationFactory.CreateObject(@"Scripting.FileSystemObject"))
{
   dynamic file = fso.CreateTextFile(cFileName, true);
   file.Write(printText);
   file.Close();
}

After that I'm using shell.Aplication to print that document.

 dynamic shell = AutomationFactory.CreateObject("Shell.Application");
 shell.ShellExecute(cFileName, "", "", "print", 1);

The question is, how can a print directly to printer without a temporary txt file?

Don't forget that I'm using Silverlight 4 out of browser and with elevated trust.

jaapaurelio
  • 274
  • 4
  • 16
  • You can't. No process is powerful enough to reach inside your process, knows its way around and obtain the string. Don't sweat the small stuff, a file is not a problem. – Hans Passant Aug 08 '11 at 19:18
  • @Hans Passant, isn't possible to print directly without using notepad? Besides using a temporary text file wich are the possible solutions to print the screen content? – Diogo Cardoso Aug 22 '11 at 15:26

1 Answers1

0

You should be able to start notepad and send your content although this is no fun solution:

Read: Silverlight 4 - send text to Notepad and: http://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.85).aspx

So basicly, 1. you start an instance of notepad. 2. Wait some time. 3. Send your text to notepad 4. Send {PRTSC} for printing 5. Ofcourse, close the instance ;)

Good luck!

Community
  • 1
  • 1
Polity
  • 14,734
  • 2
  • 40
  • 40
  • Isn't possible to print directly without using notepad? Besides using a temporary text file wich are the possible solutions to print the screen content? – Diogo Cardoso Aug 22 '11 at 15:16