I' using OpenTBS to merge 2 file docx.
include_once('tbszip.php');
$zip = new clsTbsZip();
// Open the first document
$zip->Open('file-1.docx');
$content1 = $zip->FileRead('word/document.xml');
$zip->Close();
// Extract the content of the first document
$p = strpos($content1, '<w:body');
if ($p===false) exit("Tag <w:body> not found in document 1.");
$p = strpos($content1, '>', $p);
$content1 = substr($content1, $p+1);
$p = strpos($content1, '</w:body>');
if ($p===false) exit("Tag </w:body> not found in document 1.");
$content1 = substr($content1, 0, $p);
// Insert into the second document
$zip->Open('file-2.docx');
$content2 = $zip->FileRead('word/document.xml');
$p = strpos($content2, '</w:body>');
if ($p===false) exit("Tag </w:body> not found in document 2.");
$content2 = substr_replace($content2, $content1, $p, 0);
$zip->FileReplace('word/document.xml', $content2, TBSZIP_STRING);
// Save the merge into a third file
$zip->Flush(TBSZIP_DOWNLOAD, 'merge1.docx');
content in file-1.docx include image+text, file-2: only text. But when gen file merge1.docx, can not gen image from file-1.docx Please for me a solution, thanks. P/s: sorry for my english.
when I reversed the order to open the file, file merge1.docx full content. why?
// Open the first document
$zip->Open('file-2.docx');
$content1 = $zip->FileRead('word/document.xml');
$zip->Close();
..........
// Insert into the second document
$zip->Open('file-1.docx');