Printout from Microsoft.Office.Interop.word.dll only performs 1-page document printing

Asked

Viewed 70 times

0

Good morning guys. I’m using the lib Microsof.Office.Interop.Word.dll to carry out the printing of a word document. When the document has only one page, the printing works normally. The problem is when there is more than one page, it doesn’t work. It doesn’t show error or anything, it just doesn’t come out on 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’ve done without passing the arguments too, and nothing

1 answer

0

I managed to solve. The problem was that I was closing the document right after Printout then I changed the code to wait for the end of the print 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;
                }

Browser other questions tagged

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