none
Printing word document “Docx” with incorrect order C# RRS feed

  • Question

  • I created and merged multi PDF documents together in on document then i converted this document into word document and after that i sent this document to the printer to print it in Duplex Mode, everything works well but it prints document pages not in the correct order. I tried to use multi solutions such as not to convert it and just print it as PDF, it works well but it's too slow by printing. I tried also to use Raw Print but it doesn't support duplex printing, finally i used the code below: It works fine and fast but it prints all pages in incorrect order, otherwise i sent the document direct to printer and deactivated the spooler but it doesn't worked also...

    using Microsoft.Office.Interop.Word;
    
    
    private static void PrintDoc(this string filePath, string printerName, int noOfCopies = 1)
        {
            try
            {
                object missing = Missing.Value;
                object path = filePath;
                var word = new Application();
                var doc = word.Documents.Add(ref path, ref missing, ref missing, ref missing);
                word.ActivePrinter = printerName;
                object background = false;
                object copies = noOfCopies;
                object printToFile = false;
                object collate = false;
                doc.PrintOut(
                    ref background,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref copies,
                    ref missing,
                    ref missing,
                    ref printToFile,
                    ref collate,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing,
                    ref missing);
                doc.Close(ref missing, ref missing, ref missing);
                word.Quit(ref missing, ref missing, ref missing);
            }
            catch (Exception ex)
            {
                ErrorHandler.Error(ex.Message, nameof(PrintDoc));
            }
        }

    can you please provide a solution to incorrect page orders by printing?

    Thank you in advance.

    • Moved by CoolDadTx Monday, December 2, 2019 6:39 PM Office related
    Sunday, December 1, 2019 12:39 PM

Answers

All replies

  • Hi Mahmoud-Fakhoury,

    Thank you for posting here.

    According to your description, you want to print a word file on both sides in the correct order.

    Based on my search, the following link may be helpful to you.

    Cannot print Duplex using MS Word programatically

    How to set duplex printing for Microsoft Word Automation clients in C#, VB.Net

    Best Regards,

    Timon



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 2, 2019 8:46 AM
  • Hi Timon

    - The first link is using spire and that what i don't want.
    - The second one i have already used and it does the Duplex Printing.

    I found today the problem, it was actually not in the method for PrintOut() but it was in the Converting from PDF to Word document.

    i tried alot of solution to avoid using third party and the best one to print word document is the one above. I found also Raw Printing so good and it use direct the printer driver but it doesn't support Duplex Printing

    Thank you for your search, your answer and your time
    Best Regards
    Mahmoud
    Monday, December 2, 2019 10:30 PM
  • Solved .. The Problem was in Converting from PDF into Word. The Method above works fine.
    Monday, December 2, 2019 10:32 PM