Open cyberformed opened 5 years ago
Resolved the issue by myself.
```
// store in database $press_word_db_path = './uploads/press_part_wise_merge_doc/' . time() . '.docx'; $press_word_path = FCPATH . $press_word_db_path;
// Assign the template file to the file array
$file_items = array($template_file);
foreach ($word_files as $individual_file) {
$file_items[] = FCPATH . $individual_file;
}
// Merge Multiple Documents From Departments
$dm = new DocxMerge();
$dm->merge($file_items, $press_word_path);
// load from template processor using PhpWord
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($press_word_path);
// setting the PHPWord processor to escape characters
PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
// set dynamic values provided by Govt. Press
$templateProcessor->setValue('sl_no', $data['sl_no']);
$templateProcessor->setValue('issue_date', $data['issue_date']);
$templateProcessor->setValue('sakabda_date', $data['sakabda_date']);
$templateProcessor->setValue('part_name', $data['part_name']);
$templateProcessor->setValue('section_name', $data['section_name']);
// SAVE the udpated Word file
$templateProcessor->saveAs($press_word_path);
// Convert to PDF using MS Word using PHP COM Object
$word = new COM("word.application") or die("Could not initialise MS Word object.");
$word->Documents->Open($press_word_path);
// PDF file path
$pdf_file_db_path = './uploads/press_part_wise_merge_pdf/' . time() . '.pdf';
$pdf_file_path = FCPATH . $pdf_file_db_path;
// SAVE As PDF file
$word->ActiveDocument->ExportAsFixedFormat($pdf_file_path, 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);
$word->Quit();
$word = null;
$data_pdf_array = array(
'word_file_path' => $press_word_db_path,
'pdf_file_path' => $pdf_file_db_path,
);
// INSERT/UPDATE into database
$this->weekly_model->insert_update_approved_part_wise_pdf($data_pdf_array);
return $pdf_file_db_path;
I am facing issues while passing array of word documents using loop.