How To Merge Word Files Without Page Break in PHP With Aspose.Words REST API

Using the PHP api how can I merge the pages from one document into another without creating a page break?

To put it another way: I would like the inserted pages to flow after the last paragraph of the destination document - not after the last page:

E.g.
Doc1.docx:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Doc2.docx:

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

I need this:

--------------- START OF DOCUMENT -------------
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
--------------- END OF DOCUMENT -------------

Not this:

--------------- START OF DOCUMENT -------------
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
------------------ PAGE BREAK ---------------------
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
--------------- END OF DOCUMENT -------------

@FFSPUD

To make the source document appear straight after the destination documents content, you can set the first section start of the source document to continuous and then append to the destination document. Please check the following PHP unit test example for reference. Hopefully, it will help you to accomplish the task.

Update Section Page Setup

Append Word Documents

Thanks for the response.

I coped the code directly from the testUpdateSectionPageSetupOnline example and made a few changes :

    global $wordsApi;
    $requestDocument = __DIR__."/test_multi_pages.docx";
    $requestPageSetup = new PageSetup(array(
        "rtl_gutter" => true,
        "left_margin" => 10,
        "orientation" => "Landscape",
        "paper_size" => "A5",
    ));
    $request = new UpdateSectionPageSetupOnlineRequest(
        $requestDocument,
        0,
        $requestPageSetup,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL
    );

    $result = $wordsApi->updateSectionPageSetupOnline($request);

But I get this error:
PHP Warning: Undefined array key “Content-Type” in /workspace/aspose/vendor/aspose-cloud/aspose-words-cloud/src/Aspose/Words/ObjectSerializer.php on line 112

I couldn’t get the …Online($request) form of the API to work without generating an error, so I tried this:

        global $wordsApi;

        $remoteDataFolder = "aspose_append";
        $localFile = __DIR__."/report-template.docx";
        $remoteFileName = "continuous-first-section.docx";               

        $uploadRequest = new Aspose\Words\Model\Requests\UploadFileRequest($localFile,$remoteDataFolder."/".$remoteFileName,null);
        $wordsApi->uploadFile($uploadRequest);

        $requestPageSetup = new PageSetup(array(
            "SectionStart" => 'Continuous'
        ));

        $request = new UpdateSectionPageSetupRequest(
            $remoteFileName,
            0,
            $requestPageSetup,
            $remoteDataFolder,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
        );

        $result = $wordsApi->updateSectionPageSetup($request);

        //upload destination
        $localFile = __DIR__."/test_multi_pages.docx";
        $remoteFileName1 = "destination.docx";
        $outputFileName = "result.docx";               

        $uploadRequest = new Aspose\Words\Model\Requests\UploadFileRequest($localFile,$remoteDataFolder."/".$remoteFileName1,null);

        $wordsApi->uploadFile($uploadRequest);
        $requestDocumentListDocumentEntries0 = new Aspose\Words\Model\DocumentEntry(array(
            "href" => $remoteDataFolder . "/" . $remoteFileName,
            "import_format_mode" => "UseDestinationStyles", 
        ));

        $requestDocumentListDocumentEntries = [
            $requestDocumentListDocumentEntries0,
        ];

        $requestDocumentList = new Aspose\Words\Model\DocumentEntryList(array(
            "document_entries" => $requestDocumentListDocumentEntries,
        ));

        $request = new Aspose\Words\Model\Requests\AppendDocumentRequest(
            $remoteFileName1,
            $requestDocumentList,
            $remoteDataFolder,
            NULL,
            NULL,
            NULL,
            NULL,
            $remoteDataFolder . "/" . $outputFileName,
            NULL,
            NULL
        );

        $result = $wordsApi->appendDocument($request);

        ##Download file
        $request = new Aspose\Words\Model\Requests\DownloadFileRequest($remoteDataFolder."/".$outputFileName,NULL,NULL);

        $result = $wordsApi->downloadFile($request);
        copy($result->getPathName(), __DIR__."/appended-no-page-break.docx");

But this doesn’t work. It executes without error but the continuous-first-section.docx is still apended to destination.docx with a page break.

@FFSPUD

Please share your input documents with us. We will investigate the issue and will share our findings with you.

@FFSPUD

We have noticed the reported message and investigating it. We will share our findings with you soon.

Here are the files:

test_multi_pages.docx (61.0 KB)
report-template.docx (16.7 KB)

@FFSPUD

Please note to merge Word files without page break in PHP with Aspose.Words REST API, you need to set Section start property section_start to Continuous as following. I have tested your shared code after changing the property name and it is working as expected. Please find the sample output for reference.

appended-no-page-break.docx (63.4 KB)

Combine Word Documents in PHP

<?php

require_once('D:\xampp\htdocs\aspose-words-cloud-php-master\vendor\autoload.php');

//TODO: Get your ClientId and ClientSecret at https://dashboard.aspose.cloud (free registration is required).

$ClientId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx";
$ClientSecret="xxxxxxxxxxxxxxxxxxxxxxxxxx";

$wordsApi = new Aspose\Words\WordsApi($ClientId,$ClientSecret);


try {

	$remoteDataFolder = "Temp";
        $localFile ="data/report-template.docx";
        $remoteFileName = "continuous-first-section.docx";               
        //upload Soruce document
        $uploadRequest = new Aspose\Words\Model\Requests\UploadFileRequest($localFile,$remoteDataFolder."/".$remoteFileName,null);
        $wordsApi->uploadFile($uploadRequest);
	
	//Change Section Start Property to merge at the end of Distination document
        $requestPageSetup = new Aspose\Words\Model\PageSetup(array(
            "section_start" => "Continuous"
        ));

        $request = new Aspose\Words\Model\Requests\UpdateSectionPageSetupRequest(
            $remoteFileName,
            0,
            $requestPageSetup,
            $remoteDataFolder,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
        );

        $result = $wordsApi->updateSectionPageSetup($request);

        //upload Destination document
        $localFile = "data/test_multi_pages.docx";
        $remoteFileName1 = "destination.docx";
        $outputFileName = "result.docx";               

        $uploadRequest = new Aspose\Words\Model\Requests\UploadFileRequest($localFile,$remoteDataFolder."/".$remoteFileName1,null);

        $wordsApi->uploadFile($uploadRequest);
        $requestDocumentListDocumentEntries0 = new Aspose\Words\Model\DocumentEntry(array(
            "href" => $remoteDataFolder . "/" . $remoteFileName,
            "import_format_mode" => "UseDestinationStyles", 
        ));
        
	//Merge Word documents
        $requestDocumentListDocumentEntries = [
            $requestDocumentListDocumentEntries0,
        ];

        $requestDocumentList = new Aspose\Words\Model\DocumentEntryList(array(
            "document_entries" => $requestDocumentListDocumentEntries,
        ));

        $request = new Aspose\Words\Model\Requests\AppendDocumentRequest(
            $remoteFileName1,
            $requestDocumentList,
            $remoteDataFolder,
            NULL,
            NULL,
            NULL,
            NULL,
            $remoteDataFolder . "/" . $outputFileName,
            NULL,
            NULL
        );

        $result = $wordsApi->appendDocument($request);

        ##Download file
        $request = new Aspose\Words\Model\Requests\DownloadFileRequest($remoteDataFolder."/".$outputFileName,NULL,NULL);

        $result = $wordsApi->downloadFile($request);
        copy($result->getPathName(), "data/appended-no-page-break.docx");		
		
    
} catch (Exception $e) {
    echo  "Something went wrong: ",  $e->getMessage(), "\n";
    PHP_EOL;
}

?>