tags:

views:

16

answers:

1

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

A: 

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);
        }
Jeeva S