/** * @param array $pages * @param string $fileName * @param array|int $format */ public static function html2doc($pages, $fileName, $format = array()) { if (is_array($format)) { // PDF Page Format parameters passed in - merge with defaults $format += CRM_Core_BAO_PdfFormat::getDefaultValues(); } else { // PDF Page Format ID passed in $format = CRM_Core_BAO_PdfFormat::getById($format); } $paperSize = CRM_Core_BAO_PaperSize::getByName($format['paper_size']); $metric = CRM_Core_BAO_PdfFormat::getValue('metric', $format); $pageStyle = array('orientation' => CRM_Core_BAO_PdfFormat::getValue('orientation', $format), 'pageSizeW' => self::toTwip($paperSize['width'], $paperSize['metric']), 'pageSizeH' => self::toTwip($paperSize['height'], $paperSize['metric']), 'marginTop' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_top', $format), $metric), 'marginRight' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_right', $format), $metric), 'marginBottom' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_bottom', $format), $metric), 'marginLeft' => self::toTwip(CRM_Core_BAO_PdfFormat::getValue('margin_left', $format), $metric)); $ext = pathinfo($fileName, PATHINFO_EXTENSION); $phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->getDocInfo()->setCreator(CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_Contact', CRM_Core_Session::getLoggedInContactID(), 'display_name')); foreach ((array) $pages as $page => $html) { $section = $phpWord->addSection($pageStyle + array('breakType' => 'nextPage')); \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html); } self::printDoc($phpWord, $ext, $fileName); }