本文整理汇总了PHP中PhpOffice\PhpWord\Settings::setPdfRendererName方法的典型用法代码示例。如果您正苦于以下问题:PHP Settings::setPdfRendererName方法的具体用法?PHP Settings::setPdfRendererName怎么用?PHP Settings::setPdfRendererName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpOffice\PhpWord\Settings
的用法示例。
在下文中一共展示了Settings::setPdfRendererName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateDoc
/**
* generate doc
* @var array $params
*/
public function generateDoc($params)
{
Yii::$app->user->identity = \app\models\User::findIdentityByAccessToken($params['template']['key']);
header("Content-Description: File Transfer");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
switch ($params['template']['format']) {
case 'PDF':
$file = Yii::$app->user->id . '_temp.pdf';
$writeFormat = 'PDF';
PhpWordSettings::setPdfRendererPath(dirname(__DIR__) . '/../../../vendor/tecnickcom/tcpdf');
PhpWordSettings::setPdfRendererName('TCPDF');
header('Content-Type: application/pdf');
break;
case 'Word2013':
$file = Yii::$app->user->id . '_temp.docx';
$writeFormat = 'Word2013';
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
break;
default:
$file = Yii::$app->user->id . '_temp.doc';
$writeFormat = 'Word2007';
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
break;
}
header('Content-Disposition: attachment; filename="' . $file . '"');
$document = new TemplateProcessor(dirname(__DIR__) . '/../../../files/' . $this->id . '/' . $this->template_file);
/**
* process the fields, that have been send through the rest interface
*/
foreach ($params['template']['fields'] as $field) {
foreach ($field as $key => $value) {
$document->setValue($key, UTF8encoding::fixUTF8($value));
}
}
/**
* process the tables, that have been send through the rest interface
*/
foreach ($params['template']['tables'] as $tables) {
foreach ($tables as $name => $rows) {
//first we create a clone for the master row
$document->cloneRow($name, count($rows));
//our walking variable for the table
$ii = 1;
foreach ($rows as $row) {
foreach ($row as $cell) {
$document->setValue(key($cell) . '#' . $ii, current($cell));
}
$ii++;
}
}
}
// save as a random file in temp file
$temp_file = tempnam(sys_get_temp_dir(), $file);
$document->saveAs($temp_file);
switch ($params['template']['format']) {
case 'PDF':
$phpWord = IOFactory::load($temp_file);
$xmlWriter = IOFactory::createWriter($phpWord, $writeFormat);
$xmlWriter->save("php://output");
break;
case 'Word2007':
$phpWord = IOFactory::load($temp_file);
$xmlWriter = IOFactory::createWriter($phpWord, $writeFormat);
$xmlWriter->save("php://output");
break;
default:
readfile($temp_file);
break;
}
unlink($temp_file);
$LogEvent = new TemplateEvent();
$LogEvent->aTemplateCreated(Yii::$app->user->identity->username, $this->id);
\Yii::$app->end();
}