Hello,
We have phpdocx Premium license and I'm trying to see if there is a way to handle when a doc may or may not exist and then add to the array and also in the correct order.The issue is there will always be a body doc that gets created, then there may or may not be a cover doc and there may or may not be a back cover doc. I've been testing a few ways and seem to get errors if I try to set an empty array for the 2 optional docs or even just an empty string as placeholder so it doesn't error. below is some psuedo code.
Essentially, is there a way to do a final output createDocx from an already assembled merged array of docs?
I thought it would be ideal to handle the insertion inside a statement that already does the test for whether or not we need the file/page. i use array_push and tried array_unshift but that just gives an error about zip extraction or similar. then i tried to use if statements to either merge or not merge but the createdocx() just pulls whatever was the last doc created in-stream it seems.
Is there a way to either do the merge selectively and then just create a doc from the already merged array of docs or a way to add docs in a specific order? i looked at mergeDocxAt but that creates an output doc and I only want the output doc at the very end of testing for all needed docs/building the array. If i test for only one or the other and do a ton of if/else i still could potentially not have the correct order/array needed.
Thank you for any help or suggestions!
Renee
if (!empty($ending_doc_file)) {
$docx = new CreateDocxFromTemplate($doc_file);
$last_doc = $docx->createDocx();
array_push($doc_arr, $last_doc); //this way the last doc is already in the array but the problem is now i can't output this merged array as the output doc I guess.
}
if (!empty($first_doc_file)) {
$docx = new CreateDocxFromTemplate($another_file);
$first_doc = $docx->createDocx(); // create file
}
CreateDocx::$returnDocxStructure = false;
$merge = new MultiMerge();
if ( (!empty($first_doc)) || (!empty($last_doc)) ) {
$merge = new MultiMerge();
$merge->mergeDocx($first_doc, $doc_arr, $final_path.$doc_title, array());
} else {
$docx->CreateDocx($final_path.$doc_title); //if I default to this, the potential “last doc†is missing because it’s not in the doc-array above.
}