在一个打印作业队列中打印多个Word文档

时间:2010-09-28 21:29:47

标签: c# printing

如何在一个打印作业队列中打印多个Word文档..无论如何在c#中我可以将所有内容合并为一个并将其发送到打印机?还是我们有任何包装类?

1 个答案:

答案 0 :(得分:0)

我终于将文档附加到一个......这是代码......

public static void AppendDocFree()
        {
            object missing = System.Reflection.Missing.Value;
            bool lblnFirstDoc = false;
            Application oWordApp = new Application();
            Range InsertRange = null;
            Document oWordDoc = null;
            foreach (string fileName in Directory.GetFiles(@"c:\temp\generated"))
            {
                object file = (object)fileName;
                if (!lblnFirstDoc)
                {
                    oWordDoc = oWordApp.Documents.Open(ref file, ref missing, ref missing,
                                                                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                                                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

                    lblnFirstDoc = true;
                }
                else
                {                    
                    //Collapses the range to the ending position.
                    object CollEnd = WdCollapseDirection.wdCollapseEnd;
                    InsertRange.Collapse(ref CollEnd);

                    Document InsertDocument = oWordApp.Documents.Open(ref file, ref missing, ref missing,
                       ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

                    Range range = InsertDocument.Content;
                    range.Copy();
                    InsertRange.Paste();

                    InsertDocument.Close(ref missing, ref missing, ref missing);                    
                }
                object DocumentEnd = oWordDoc.Content.End - 1;
                InsertRange = oWordDoc.Range(ref DocumentEnd, ref DocumentEnd);

                //This is important(if you unstand the above text)
                object wdSectionBreakN = WdBreakType.wdSectionBreakNextPage;
                InsertRange.InsertBreak(ref wdSectionBreakN);
            }

            oWordDoc.SaveAs(@"c:\temp\output.doc");
            oWordDoc.Close(ref missing, ref missing, ref missing);
            oWordApp.Quit(ref missing, ref missing, ref missing);
        }