none
Using Document.PrintOut doesn't print correct page numbers in footers RRS feed

  • Question

  • We have an ActiveX controller written in C++ that leverages COM to print Word and Excel documents behind the scenes from a Web page.  We were retrofitting the code to work with Word 2010 and we've encountered an issue where for some documents, the page number in the footers print out as "Page 1 of 1"  Page 2 of 2", etc - where the total number of pages in the document is not being updated.  Does anyone have an idea about the "magic" sequence of calls that might get the document to print out correctly or any idea what other things to try?

     

    The methods we are using in the code are:

    oDoc = oDocs.Open() - [using all 16 args]

    oDoc.PrintOut() - [using all 18 args]

    oDoc.Close()

    oDoc= NULL;

    • Moved by Jie BaoModerator Thursday, April 21, 2011 3:04 AM (From:Application Compatibility for Windows Development)
    Tuesday, April 19, 2011 5:58 PM

Answers

  • Hi Janeen

    A further thought...

    Some older versions of Word had this problem with the field codes Rich mentions - they did not update properly under some circumstances (Word 97 and 2000, as I recall). It might help if you can determine in which version of Word these documents were created. Possibly, it's a "glitch" in the (old) file format.


    Cindy Meister, VSTO/Word MVP
    Saturday, April 23, 2011 6:00 AM
    Moderator

All replies

  • Hi Janeen A,

    Is it an Office related development issue? Since this forum is for Windows software development on the compatibility issues. Could you please elaborate the scenario, such as the Windows version, the more code and how to do you to work with Word 2010?

    I will help you to move it to the Word for Developers forum first, and hope that forum can help you on this issue. Thanks.

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 21, 2011 3:04 AM
    Moderator
  • Hi Janeen,

    Since you indicate that this problem does not exist on all documents I recommend that you take a look at the page number field codes in these particular documents. In the "Page X of Y" page numbering scenario the "Y" field should be a NUMPAGES command. You can inspect the fields codes by placing your cursor on the field and clicking Alt + F9 to toggle it. Alternatively right click the field and select the Toggle option.

    Hope this helps


    Regards
    Thursday, April 21, 2011 3:44 AM
  • Hi Bob,

     

    So we are seeing this happen on the following OS: XP (service pack 3) and Windows 7.  Like I mentioned, it doesn't happen for all documents, so I will investigate Rich Michaels suggestion below.

     

    here's the background.  We have an application that stores content files.  We have a requirement to be able to print those content files without users seeing the files and being able to manipulate them, so that people feel confident that the printouts are unaltered.   A user clicks a click which passes a URL to the content file to an intermediate HTML page that contains an ActiveX controller.  The URL is passed to the ActiveX controller which does the following, which downloads to the a temporary location on the hard drive, depending on the file type *.doc, *.xls *.pdf - open up the corresponding application (Word, Excel, Adobe Reader).

    Unfortunately this code was inherited from something developed years ago and we are just trying to get it to work now that we are going to Office 2010.

    ------

    // Word14_Document and Word14_Application classes were created by using the C++ class wizard from the MSWORD.OLB

     

       Word14_Application oApp;
       Word14_Document oDoc;

        oApp.CreateDispatch("Word.Application");

     

      /* Snippet from the LoadFile method() */

       //For optional arguments
        COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR);
        COleVariant fOpt(filename);
        COleVariant bfOpt((short)0, VT_BOOL);
        COleVariant btOpt((short)1, VT_BOOL);

        // open the required file
        Word14_Documents oDocs;
        oDocs = oApp.GetDocuments ();

        oDoc = oDocs.Open(fOpt, //filename of the downloaded file to print
            bfOpt,//confirmconversions
            btOpt, // readonly
            bfOpt, //addtoRecentFuiles
            vOpt, //password document
            vOpt, //password template
            bfOpt, //revert
            vOpt, //writepassworddocument
            vOpt,//writepsswordtemplate
            vOpt, //format
            vOpt, //encoding
            btOpt, //visible
            bfOpt, //openandrepair
            vOpt, //documentdirection
            btOpt, //noEncodingdialog
            vOpt); //XMLTransform

     

     /* snippet from the Print() method */

        COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR);
        COleVariant rOpt((short)wdPrintAllDocument, VT_I2);
        COleVariant pOpt((short)wdPrintAllPages, VT_I2);
        COleVariant iOpt((short)wdPrintDocumentContent, VT_I2);
        COleVariant cOpt((short)1, VT_I2);
        COleVariant zOpt((short)0, VT_I2);
        COleVariant fOpt("");
        COleVariant bfOpt((short)0, VT_BOOL);
        COleVariant btOpt((short)1, VT_BOOL);

        try {
            oDoc.PrintOut(    bfOpt/*Background*/, 
                            bfOpt/*Append*/,
                            rOpt /*Range*/,      
                            fOpt /*OutputFileName*/,
                            vOpt /*From*/,       
                            vOpt /*To*/,
                            iOpt /*Item*/,          
                            cOpt /*Copies*/,  
                            vOpt /*Pages*/,      
                            pOpt /*PageType*/,   
                            bfOpt/*PrintToFile*/,
                            bfOpt/*Collate*/,
                            vOpt/*ActivePrinterMacGX*/, 
                            bfOpt/*ManualDuplexPrint*/,
                            zOpt/*PrintZoomColumn*/,     
                            zOpt /*PrintZoomRow*/,
                            zOpt/*PrintZoomPaperWidth*/,
                            zOpt /*PrintZoomPaperHeight*/);

     

    /* Snippet from CloseFile method */

        //For optional arguments
        COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR);
        COleVariant bfOpt((short)0, VT_BOOL);

        oDoc.Close(bfOpt,vOpt,vOpt);
        oDoc = NULL;

     

     

    Friday, April 22, 2011 9:04 PM
  • Hi Janeen

    A further thought...

    Some older versions of Word had this problem with the field codes Rich mentions - they did not update properly under some circumstances (Word 97 and 2000, as I recall). It might help if you can determine in which version of Word these documents were created. Possibly, it's a "glitch" in the (old) file format.


    Cindy Meister, VSTO/Word MVP
    Saturday, April 23, 2011 6:00 AM
    Moderator