Поделиться через


Практическое руководство. Программная печать документов

Печать документа Microsoft Office Word может производиться как полностью, так и частично.

Применение. Сведения этого раздела применяются к проектам уровня документа и уровня приложения для Word 2013 и Word 2010. Дополнительные сведения см. в разделе Доступность функций по типам приложений Office и проектов.

Печать документа, являющегося частью настройки уровня документа

Печать всего документа

  • Чтобы напечатать весь документ, вызовите метод PrintOut класса ThisDocument своего проекта.Чтобы воспользоваться этим примером, запустите его из класса ThisDocument.

    Me.PrintOut()
    
    object copies = "1";
    object pages = "";
    object range = Word.WdPrintOutRange.wdPrintAllDocument;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    object oTrue = true;
    object oFalse = false;
    
    this.PrintOut(ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, 
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

Печать текущей страницы документа

  • Вызовите метод PrintOut класса ThisDocument своего проекта, указав, что необходимо напечатать одну копию текущей страницы.Чтобы воспользоваться этим примером, запустите его из класса ThisDocument.

    Me.PrintOut( _
        Background:=True, _
        Append:=False, _
        Range:=Word.WdPrintOutRange.wdPrintCurrentPage, _
        Item:=Word.WdPrintOutItem.wdPrintDocumentContent, _
        Copies:="1", _
        Pages:="1", _
        PageType:=Word.WdPrintOutPages.wdPrintAllPages, _
        PrintToFile:=False, _
        Collate:=True, _
        ManualDuplexPrint:=False)
    
    object copies = "1"; 
    object pages = "1"; 
    object range = Word.WdPrintOutRange.wdPrintCurrentPage; 
    object items = Word.WdPrintOutItem.wdPrintDocumentContent; 
    object pageType = Word.WdPrintOutPages.wdPrintAllPages; 
    object oTrue = true; 
    object oFalse = false; 
    
    this.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, 
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

Печать документа при помощи надстройки уровня приложения

Печать всего документа

  • Следует вызвать метод PrintOut объекта Microsoft.Office.Interop.Word.Document, который необходимо напечатать.В приведенном ниже примере кода производится печать активного документа.Чтобы воспользоваться этим примером, запустите его из класса ThisAddIn своего проекта.

    Me.Application.ActiveDocument.PrintOut()
    
    this.Application.ActiveDocument.PrintOut(true, false, Word.WdPrintOutRange.wdPrintAllDocument,
        Item: Word.WdPrintOutItem.wdPrintDocumentContent, Copies:"1", Pages:"", 
        PageType:Word.WdPrintOutPages.wdPrintAllPages, PrintToFile:false, Collate:true,
        ManualDuplexPrint:false);
    

Печать текущей страницы документа

  • Следует вызвать метод PrintOut объекта Microsoft.Office.Interop.Word.Document, часть которого нужно напечатать, указав, что необходимо напечатать одну копию текущей страницы.В приведенном ниже примере кода производится печать активного документа.Чтобы воспользоваться этим примером, запустите его из класса ThisAddIn своего проекта.

    Me.Application.ActiveDocument.PrintOut( _
        Background:=True, _
        Append:=False, _
        Range:=Word.WdPrintOutRange.wdPrintCurrentPage, _
        Item:=Word.WdPrintOutItem.wdPrintDocumentContent, _
        Copies:="1", _
        Pages:="1", _
        PageType:=Word.WdPrintOutPages.wdPrintAllPages, _
        PrintToFile:=False, _
        Collate:=True, _
        ManualDuplexPrint:=False)
    
    object copies = "1";
    object pages = "1";
    object range = Word.WdPrintOutRange.wdPrintCurrentPage;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    object oTrue = true;
    object oFalse = false;
    Word.Document document = this.Application.ActiveDocument;
    
    document.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

См. также

Основные понятия

Необязательные параметры в решениях Office