打印到手动进纸MS Interop Word

时间:2013-01-18 18:12:27

标签: c# .net wpf office-interop

我正在尝试从手动输入打印MS Word文档(以便打印到信封) 我发现Envelope.PrintOut方法有一个FeedSource属性,可以帮助定义它, http://msdn.microsoft.com/en-us/library/office/ff197594.aspx

但是我很难用它...... 这是我用来打印一个有效的文档的函数,如果fromFeed是假的(常规打印)但是如果它是真的... 当然我尝试了不同类型的WdPaperTray值...

    public void PrintDocument(bool fromFeed)
    {
        this.doc = this.ap.Documents.Open(this.pathToNewFile, ReadOnly: false, Visible: false);
        //if (fromFeed)
       //     this.doc.Envelope.FeedSource = WdPaperTray.wdPrinterManualFeed;
        object copies = "1";
        object pages = "";
        object range = WdPrintOutRange.wdPrintAllDocument;
        object items = WdPrintOutItem.wdPrintDocumentContent;
        object pageType = WdPrintOutPages.wdPrintAllPages;
        object oTrue = true;
        object oFalse = false;
        object missing = System.Type.Missing;
        this.doc.Activate();
        if (fromFeed)
            this.doc.Envelope.PrintOut(missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, WdPaperTray.wdPrinterManualFeed, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
        else
            this.doc.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);
        this.ap.Documents.Close(SaveChanges: false, OriginalFormat: false, RouteDocument: false);
    }

比我发现这个: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.envelope.feedsource(v=office.11).aspx

它说: “如果在将信封添加到文档之前使用此属性,则会发生错误”

所以也许我只需要在文档中添加一个信封?但MS Word文档中的信封是什么?

顺便说一句,我正在开发它作为WPF。 此时代码抛出此异常:对​​象值超出范围异常

欢迎任何帮助。

0 个答案:

没有答案