need help: how to merge multiple DOCX files into one, keep the original page no?

Home Forums Open-Xml-PowerTools need help: how to merge multiple DOCX files into one, keep the original page no?

This topic contains 1 reply, has 2 voices, and was last updated by  Anonymous 4 years, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #8506

    tongchenseattle
    Participant

    Hi, I need your help.

    I am trying to use the PowerTools to combine two DOCX files into 1 DOCX file.

    Both files contain page number in footer section, like, “Page 1 of 10”, “Page 2 of 10″, ….,”Page 10 of 10”.

    When i merged the two DOCX files, the result has 20 pages, which is correct.

    But, in the result DOCX file, it has “Page 1 of 10”, “Page 2 of 10″, ….”Page 10 of 10”, “Page 11 of 10”, …., “Page 20 of 10”.

    How do I keep the original pagination in the result files.

    Thanks!

    my code is like this

    `namespace TestCombineWordDocuments
    {
    class Program
    {
    static void Main(string[] args)
    {
    Console.WriteLine(“Hello World!”);

    string[] fileNames = new string[] { @”D:\TestWordDocuments\NOA_FELONY_1.docx”, @”D:\TestWordDocuments\NOA_FELONY_2.docx” };
    string outputFilePath = @”D:\TestWordDocuments\Result” + Guid.NewGuid() + “.docx”;

    MergeDocuments(fileNames, outputFilePath);
    }

    public static void MergeDocuments(string[] fileNames, string outputFilePath)
    {
    using (var outputFileStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.ReadWrite))
    {
    var sources = new List<Source>();

    foreach (string fileName in fileNames)
    {
    byte[] allBytes = File.ReadAllBytes(fileName);

    var openXmlPowerToolsDocument = new OpenXmlPowerToolsDocument(allBytes);

    var source = new Source(new WmlDocument(openXmlPowerToolsDocument), true);

    sources.Add(source);
    }

    MergeXmlDocuments(outputFileStream, sources);
    }

    }

    public static void MergeXmlDocuments(Stream outStream, List<Source> sources)
    {
    WmlDocument buildDocument = DocumentBuilder.BuildDocument(sources);
    buildDocument.WriteByteArray(outStream);
    }

    }
    }

    #9791

    Anonymous

    If your requirements is to combine multiple word document into a single word document programmatically, then you can try GroupDocs.Merger Cloud. It is a REST API solution to merge and split documents.

    cURL example:

    // First get Access Token
    // Get App Key and App SID from https://dashboard.groupdocs.cloud/
    curl -X POST “https://api.groupdocs.cloud/connect/token”
    -d “grant_type=client_credentials&client_id=[App_SID]&client_secret=[App_Key]”
    -H “Content-Type: application/x-www-form-urlencoded”
    -H “Accept: application/json”

    // Upload soruce document to GrupDocs default Storage
    curl -X PUT “https://api.groupdocs.cloud/v1.0/merger/storage/file/Temp/Test1.docx”
    -H “accept: application/json”
    -H “authorization: Bearer [Access_Token]”
    -H “Content-Type: multipart/form-data”
    -F “File=@C:/Temp/Testv1.docx”

    // Merge Documents from GroupDocs default Storage
    curl -X POST “https://api.groupdocs.cloud/v1.0/merger/join”
    -H “accept: application/json”
    -H “authorization: Bearer [Access_Token]”
    -H “Content-Type: application/json” -d “{ “JoinItems”: [ { “FileInfo”: { “FilePath”: “Temp/Testv1.docx”, } },{ “FileInfo”: { “FilePath”: “Temp/Test2.docx”, } },{ “FileInfo”: { “FilePath”: “Temp/Test3.docx”, } } ], “OutputPath”: “Temp/GroupDocs_Merger.docx”}”

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.