Sign In  Sign Up Live-Chat

Combining documents and maintaining page layout

Last post 05-11-2008, 9:48 AM by cxhouse. 2 replies.
Sort Posts: Previous Next
  •  05-09-2008, 2:26 PM 126292

    Combining documents and maintaining page layout

    Greetings -

    I have an automated mail merge process that appends a series of Word documents together and then executes a mail merge.  The problem I'm running into is that it appears that occaisonally one document will have significant white space on it's last page, so that when the next document in the serries is appended, it doesn't start on a new page.  I need to be able to append these documents together but have each component document start on a new page. 

    Currently the code I'm using to append the documents is like this:

     

    string currentPath = rootPath + component.ComponentPath;

    Trace.WriteLine(string.Format("[CreateClaimsDocument]: Current template path is {0}",currentPath));

    Aspose.Words.Document currentDocument = new Aspose.Words.Document(currentPath);

    for (int i = 0; i < currentDocument.Sections.Count; i++)

    {

    Aspose.Words.Section newSection = (Aspose.Words.Section)wordDocument.ImportNode(currentDocument.Sections[i],true);

    wordDocument.Sections.Add(newSection);

    }

    I've tried a few different things using DocumentBuilder.InsertBreak but that seems to always result in blank pages in the combined document.

    Any suggestions on how I can append all these documents together and preserve the page breaks would be greatly appreciated.

    Thanks,

    Chris

    Filed under: Page break
     
  •  05-09-2008, 4:32 PM 126333 in reply to 126292

    Re: Combining documents and maintaining page layout

    Hi

     

    Thanks for your request. I think that you can set SectionStart = SectionStart.NewPage. For example see the following code:

     

    //Open documents

     Document dstDoc = new Document(@"Test043\in1.doc");

     Document srcDoc = new Document(@"Test043\in2.doc");

     //Loop through all section in source document

     foreach (Section sect in srcDoc.Sections)

     {

         //Import section

         Section newSect = (Section)dstDoc.ImportNode(sect, true, ImportFormatMode.KeepSourceFormatting);

         if (sect.Equals(srcDoc.FirstSection))

         {

             //If section is first one in the source document

             //then set sectiton to start from next page

             newSect.PageSetup.SectionStart = SectionStart.NewPage;

         }

         //Add section to destination document

         dstDoc.Sections.Add(newSect);

     }

     //Save document

     dstDoc.Save(@"Test043\out.doc");

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-11-2008, 9:48 AM 126403 in reply to 126333

    Re: Combining documents and maintaining page layout

    Thanks so much for your reply, that did the trick!  I figured it was something easy like that, just couldn't figure out what it was.
     
View as RSS news feed in XML