• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

Printing a Word Document using a Process

Hi,

I have an application that will create a word document in a Rich Text Box, save it away and then I want it to print it to the default printer.  I am currently using this:

        Dim p As New System.Diagnostics.ProcessStartInfo()
        p.Verb = "print"
        p.WindowStyle = ProcessWindowStyle.Hidden
        p.FileName = "C:\Test.doc"
        p.UseShellExecute = True
        System.Diagnostics.Process.Start(p)

but it shows a window of Word briefly... Is there a way of hiding this, I would have thought the "p.WindowStyle = ProcessWindowStyle.Hidden" should have done this??
0
fvcctv
Asked:
fvcctv
  • 5
  • 3
1 Solution
 
DhaestCommented:
I don't think you can catch this. It's normal behaviour. When you want to print a word-document, it's opened in word (normally hidden, but when loading it can be visible).
0
 
fvcctvAuthor Commented:
Is there another method for this that doesn't display Word, or do I have to just put up with it?
0
 
DhaestCommented:
If you want to print a Word document without Word actually appearing in a window, you'll want to use Office Automation instead. Microsoft makes Office Automation assemblies available (I think they are installed with Office by default.) Here is an article (http://www.codeproject.com/KB/printing/WordPrinting.aspx) on how to do that. I haven't actually tried the code but I've done some automation and it looks good from a quick read.

Here is an article from Microsoft on Office Automation.
http://support.microsoft.com/kb/304661

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DhaestCommented:
Printing a Word Document using Word Automation
http://www.codeproject.com/KB/office/WordPrint.aspx

0
 
fvcctvAuthor Commented:
Thanks for your comments, but the examples on those pages still display Word briefly before printing...
0
 
DhaestCommented:
If you declare your word-object through automatisation, you need to set the following also:
Dim oWordApp As Word.Application

Set oWordApp = New Word.Application
oWordApp.Visible = False

For more info: http://word.mvps.org/faqs/interdev/MakeAppInvisible.htm
0
 
fvcctvAuthor Commented:
It still displays : (

I must be missing something:

        Clipboard.SetDataObject(PotTestBMP)        ' Get the format for the object type.
        Dim MyFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.Bitmap)

        Dim Doc As Microsoft.Office.Interop.Word.Document
        Dim WordApp As New Microsoft.Office.Interop.Word.Application

        WordApp.DisplayAlerts = Microsoft.Office.Interop.Word.WdAlertLevel.wdAlertsNone
        WordApp.Visible = False

        Doc = WordApp.Documents.Open("C:\Test.doc")
        WordApp.PrintOut()
        WordApp.Documents.Close()
        WordApp.Quit()
        WordApp = Nothing
0
 
DhaestCommented:
Hmmm... if the .visible = false  is also showing up the winword for a second, than I think that there is no solution for it !
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now