use PhpOffice\PhpWord\Settings; date_default_timezone_set('UTC'); error_reporting(E_ALL); define('CLI', PHP_SAPI == 'cli' ? true : false); define('EOL', CLI ? PHP_EOL : '<br />'); define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php')); define('IS_INDEX', SCRIPT_FILENAME == 'index'); Settings::loadConfig(); // Set writers $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf'); // Set PDF renderer if (null === Settings::getPdfRendererPath()) { $writers['PDF'] = null; } // Turn output escaping on Settings::setOutputEscapingEnabled(true); // Return to the caller script when runs by CLI if (CLI) { return; } // Set titles and names $pageHeading = str_replace('_', ' ', SCRIPT_FILENAME); $pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - "; $pageTitle .= 'PHPWord'; $pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>"; // Populate samples $files = ''; if ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if (preg_match('/^Sample_\\d+_/', $file)) { $name = str_replace('_', ' ', preg_replace('/(Sample_|\\.php)/', '', $file));
$phpWord = new \PhpOffice\PhpWord\PhpWord(); $TAITAN = 'https://taitan.datasektionen.se'; $ME_URL = $_ENV['APP_URL'] . "?path="; $json = file_get_contents($TAITAN . $_GET['path']); //$json = mb_convert_encoding($json , 'HTML-ENTITIES', "UTF-8"); $obj = json_decode($json); $file = $obj->title . '.docx'; header("Content-Description: File Transfer"); header('Content-Disposition: inline; filename="' . $file . '"'); header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document'); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Expires: 0'); #$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); #$xmlWriter->save("php://output"); \PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true); // New Word document // New section $section = $phpWord->addSection(); // Define styles $phpWord->addTitleStyle(1, array('size' => 35, 'bold' => true, 'color' => '#e83d84')); // Adding Text element with font customized using named font style... $pStyle = 'p'; $phpWord->addFontStyle($pStyle, array('name' => 'Arial', 'size' => 16, 'color' => '757575', 'bold' => false)); // Arc $section->addTitle($obj->title, 1); //$section->addText(htmlspecialchars_decode(strip_tags($obj->body)), $pStyle); WaffleHtml::addHtml($section, $obj->body); if ($obj->sidebar) { $sidebar = $phpWord->addSection(); $sidebar->addTitle("Sidebar", 1);