PrintOut from Microsoft.Office.Interop.word.dll only performs document printing with 1 page

0

Good morning everyone. I am using lib Microsof.Office.Interop.Word.dll to print a word document. When the document has only one page, printing works normally. The problem is when you have more than one page, it does not work. No error or anything, just does not come out in the printer. I'm using these parameters:

word.ActiveDocument.PrintOut(
                   true,
                   false, 
                   Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument,
                   Item: Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent,
                   Copies: "1", 
                   //Pages: "1,2",
                   PageType: Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages,
                   PrintToFile: false, 
                   Collate: true,
                   ManualDuplexPrint: false);

I already put Pages: "1,2", Pages: "1-2" and nothing, I already did without passing the arguments too, and nothing

    
asked by anonymous 31.01.2017 / 12:39

1 answer

0

I managed to resolve. The problem was that I was closing the document right after PrintOut so I changed the code to wait for the print to finish and then close the document:

 Log.LoggerAPI.LogInfo("Aguarando término da impressão");
                while (word.BackgroundPrintingStatus == 1) { }



                if (word.BackgroundPrintingStatus == 0)
                {
                    Log.LoggerAPI.LogInfo("Fechando documento sem salvar as alterações");
                    doc.Close(SaveChanges: false);

                    doc = null;
                    ((Microsoft.Office.Interop.Word._Application)word).Quit(SaveChanges: false);
                    word = null;
                }
    
31.01.2017 / 14:44