Print word file by c#

Asked

Viewed 917 times

3

Hello guys I am trying to print a word.doc file, I am 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 someone help me?

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();
  • Thus it is giving error in the line application.Documents.Open(...)oMissing);

  • @Manufacturing Monealanamendes What a mistake?

  • he doesn’t accept the code

  • Leave only the application.Documents.Open(Path); then

  • @Fabríciosimonealanamendes I made some changes there

2

I used that code.Nousing Microsoft.Office.Interop.Word; My code went 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;

That way it doesn’t open the printer dialog box. Prints dieret

  • Hello, Amigo Blza? You managed to print more than one page this way that Voce posted, I’m trying here, but it only works when you have a page. I’d appreciate it if you could give me a hint.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.