Print word file by C #

3

Hello everyone, I'm trying to print a word.doc file, I'm using the following code.

using Microsoft.Office.Interop.Word;
Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
        string CaminhoContrato ="C:\arquvio.doc";
        Document document = application.Documents.Open(CaminhoContrato);

That way I can open it, but I really need to print the file without it being opened. Can anyone help me?

    
asked by anonymous 04.06.2015 / 00:16

2 answers

3

Have you tried it here?

Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
string caminhoContrato ="C:\arquvio.doc";
Document document = application.Documents.Open(caminhoContrato);
document.Activate();
document.PrintOut();
    
04.06.2015 / 00:42
2

I used this code. Not using Microsoft.Office.Interop.Word; My code looks like this.

string CaminhoArquivo = "C:\arquivo.doc";

 Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
        wordApp.Visible = false;

            Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Add(CaminhoContrato);
            wordApp.ActiveDocument.PrintOut(true, false, Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument,
Item: Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent, Copies: "2", Pages: "1",
PageType: Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages, PrintToFile: false, Collate: true,
ManualDuplexPrint: false);
            doc.Close(SaveChanges: false);
            doc = null;
            ((Microsoft.Office.Interop.Word._Application)wordApp).Quit(SaveChanges: false);
            wordApp = null;

This does not open the printer's dialog box. Print right

    
04.06.2015 / 01:02