Esempio n. 1
0
        private bool printAfterCursorDonotRemoveHeader(string strPrintName)
        {
            try
            {
                DocProtectManager.unprotectSave(myDoc);
                unprotectControls(myDoc);
                try
                {
                    hideText(myDoc, objPageStart, objEnd);
                }
                catch (Exception) { }
                bool bResult = print(myDoc, strPrintName, (int)objPageStart, (int)objPageStart);
                try
                {
                    showText();
                }
                catch (Exception) { }

                if ((int)objPageStart < iPageCount)
                {
                    print(myDoc, strPrintName, (int)objPageStart + 1, iPageCount);
                }
                DocProtectManager.protectSave(myDoc);
                return(bResult);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                DocProtectManager.protectSave(myDoc);
            }
        }
Esempio n. 2
0
 private bool viewAfterCursorRemoveHeader()
 {
     try
     {
         DocProtectManager.unprotectSave(myDoc);
         unprotectControls(myDoc);
         try
         {
             hideText(myDoc, objPageStart, objEnd);
         }
         catch (Exception) { }
         try
         {
             hideHeader(myDoc, objPageStart);
         }
         catch (Exception) { }
         bool bResult = print(myDoc, strViewPrinterName, (int)objPageStart, (int)objPageStart);
         try
         {
             showHeader();
         }
         catch (Exception) { }
         try
         {
             showText();
         }
         catch (Exception) { }
         if (moveTIF(strBufferDir, strBufferDir2, 1) == false)
         {
             return(false);
         }
         if ((int)objPageStart < iPageCount)
         {
             print(myDoc, strViewPrinterName, (int)objPageStart + 1, iPageCount);
             if (moveTIF(strBufferDir, strBufferDir2, 2) == false)
             {
                 return(false);
             }
         }
         DocProtectManager.protectSave(myDoc);
         return(bResult);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Esempio n. 3
0
        private bool print(Word.Document myDoc, string strPrinterName, int iPageStart, int iPageEnd)
        {
            DocProtectManager.protectSave(myDoc);
            string strOldPrintName = null;

            //当strPrinterName 为空时使用默认打印机
            if (strPrinterName != null)
            {
                strOldPrintName = myDoc.Application.ActivePrinter;
                myDoc.Application.ActivePrinter = strPrinterName;
            }

            /*
             *  PrintOut (
             *      [OptionalAttribute] ref Object Background,
             *      [OptionalAttribute] ref Object Append,
             *      [OptionalAttribute] ref Object Range,
             *      [OptionalAttribute] ref Object OutputFileName,
             *      [OptionalAttribute] ref Object From,
             *      [OptionalAttribute] ref Object To,
             *      [OptionalAttribute] ref Object Item,
             *      [OptionalAttribute] ref Object Copies,
             *      [OptionalAttribute] ref Object Pages,
             *      [OptionalAttribute] ref Object PageType,
             *      [OptionalAttribute] ref Object PrintToFile,
             *      [OptionalAttribute] ref Object Collate,
             *      [OptionalAttribute] ref Object ActivePrinterMacGX,
             *      [OptionalAttribute] ref Object ManualDuplexPrint,
             *      [OptionalAttribute] ref Object PrintZoomColumn,
             *      [OptionalAttribute] ref Object PrintZoomRow,
             *      [OptionalAttribute] ref Object PrintZoomPaperWidth,
             *      [OptionalAttribute] ref Object PrintZoomPaperHeight
             * )
             */
            try
            {
                object missing            = System.Reflection.Missing.Value;
                object Background         = true;
                object Range              = Word.WdPrintOutRange.wdPrintRangeOfPages;
                object Copies             = 1;
                object PageType           = Word.WdPrintOutPages.wdPrintAllPages;
                object PrintToFile        = false;
                object Collate            = false;
                object ActivePrinterMacGX = missing;
                object ManualDuplexPrint  = false;
                object PrintZoomColumn    = 1;
                object PrintZoomRow       = 1;
                object objPage            = iPageStart.ToString() + "-" + iPageEnd.ToString();
                myDoc.PrintOut(ref Background, ref missing, ref Range, ref missing,
                               ref missing, ref missing, ref missing, ref Copies,
                               ref objPage, ref PageType, ref PrintToFile, ref Collate,
                               ref missing, ref ManualDuplexPrint, ref PrintZoomColumn,
                               ref PrintZoomRow, ref missing, ref missing);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
            finally
            {
                DocProtectManager.unprotectSave(myDoc);
                if (strOldPrintName != null)
                {
                    myDoc.Application.ActivePrinter = strOldPrintName;
                }
            }
        }