开发者

Print Multiple Word Document in One Print Job Queue

How do i Print Multiple Word Documents in One Print Job Queue..开发者_JAVA百科 is there anyway in c# that i can combine everything into one and send it to printer? or do we have any wrapper classes?


i finally ended up with appending the document into one... here is the code for that..

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);
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜