none
How to use automation to print to both sides of the page

    Question

  • This question has been asked a lot, but every answer I've found has broken links or incorrect advice. I am using Microsoft.Office.Interop.Word to automate printing 100 copies of a collated report.

    The source code is below. I've tried setting the ManualDuplexPrint option both ways. The printer is already set up for duplex printing, so we don't want to do it manually anyway.

    I found an extensive bit of source code written in VB at https://social.msdn.microsoft.com/Forums/en-US/79348557-a1f4-4d29-8e5e-752e6072e847/how-to-print-a-document-in-both-sides-in-worddocumentprintout-method?forum=worddev. However, the article points to source code in CSharp, but the link is dead.

    using Microsoft.Office.Interop.Word;
    
    public static void PrintDocx(string docxFileName)
    {
        try
        {
            wordApplication = new Microsoft.Office.Interop.Word.Application
            {
                Visible = false
            };
            Object filename = (Object)docxFileName;
            doc = wordApplication.Documents.Open(
                ref filename,       // Filename
                ref oMissing,       // ConfirmConversions,
                ref oTrue,          // ReadOnly,
                ref oFalse,         // AddToRecentFiles,
                ref oMissing,       // PasswordDocument,
                ref oMissing,       // PasswordTemplate,
                ref oMissing,       // Revert,
                ref oMissing,       // WritePasswordDocument,
                ref oMissing,       // WritePasswordTemplate,
                ref oMissing,       // Format,
                ref oMissing,       // Encoding,
                ref oTrue,          // Visible,
                ref oMissing,       // OpenAndRepair,
                ref oMissing,       // DocumentDirection,
                ref oMissing,       // NoEncodingDialog,
                ref oMissing);      // XMLTransform);
            doc.Activate();
            object copies = "1";
            object pages = "10";
            object range = Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument;
            object items = Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent;
            object pageType = Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages;
            doc.PrintOut(
                ref oTrue, ref oFalse, ref range, ref oMissing, ref oMissing, ref oMissing,
                ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
                ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
        }
        catch (Exception e)
        {
            Debug.WriteLine("Open exception: " + e.Message);
            MessageBox.Show(e.Message);
        }
    

    Brad Thompson

    Friday, April 5, 2019 8:11 PM