yii2 导出pdf [ 2.0 版本 ]
使用的是kartik-v/yii2-mpdf
导出的PDF-当某行文字描述很多的时候字体非常小,在html中设置的字体大小是一样,
yyf 补充于 2017-06-26 16:49
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8, // leaner size using standard fonts
'content' => $content,
'filename' => $saveFile,
'destination' => 'F',
'options' => [
'title' => '公司',
'subject' => '公司',
'autoLangToFont' => true,
'autoScriptToLang' => true,
'autoVietnamese' => true,
'autoArabic' => true,
],
'methods' => [
'SetHeader' => [$typeName . '信息||日期: ' . date('Y-m-d', time())],
'SetFooter' => ['|第 {PAGENO} 页,共 {nb} 页|'],
],
]);
$pdf->render();
有不一样吧?
yyf 补充于 2017-10-10 15:22
解决了改问题,是因为当文本比较长的时候,客户端在输入的时候使用了回车换行,所以导出的pdf不使用自动换行,会根据输入的换行符换行,造成字体很小,将文本中的换行符替换掉就可以了。 preg_replace('/\s/', '
', $info);
共 3 个回答
-
use kartik\mpdf\Pdf; public function actionReport() { // get your HTML raw content without any layouts or scripts $content = $this->renderPartial('_reportView'); // setup kartik\mpdf\Pdf component $pdf = new Pdf([ // set to use core fonts only 'mode' => Pdf::MODE_CORE, // A4 paper format 'format' => Pdf::FORMAT_A4, // portrait orientation 'orientation' => Pdf::ORIENT_PORTRAIT, // stream to browser inline 'destination' => Pdf::DEST_BROWSER, // your html content input 'content' => $content, // format content from your own css file if needed or use the // enhanced bootstrap css built by Krajee for mPDF formatting 'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', // any css to be embedded if required 'cssInline' => '.kv-heading-1{font-size:18px}', // set mPDF properties on the fly 'options' => ['title' => 'Krajee Report Title'], // call mPDF methods on the fly 'methods' => [ 'SetHeader'=>['Krajee Report Header'], 'SetFooter'=>['{PAGENO}'], ] ]); // return the pdf output as per the destination setting return $pdf->render(); }
有啥特别的吗
-
我这是源码 git上复制的 我还看了下源码 里面有设置默认字体大小的 还是就是加css样式的
共 1 条回复我设置css样式是在html中设置的-----当文字比较少的时候是没有这种情况的
<?php if (empty($displayColumnValue['data'])): ?> <tr> <td style="word-wrap:break-word;">暂无信息</td> </tr> <?php else: ?> <?php $i = 0; ?> <tr> <?php foreach ($displayColumnValue['data'] as $key2 => $value2): ?> <?php if ($value2['type'] == 1) { continue; } ?> <td style="word-wrap:break-word"><?= $value2['display_name'] ?> : <?= $value2['value']; ?></td> <?php if (($i + 1) % 3 == 0): ?> </tr> <tr> <?php endif; ?> <?php $i++; ?> <?php endforeach; ?> </tr> <?php endif; ?> </table>
-
yyf 上海
注册时间:2016-11-16
最后登录:2021-07-20
在线时长:22小时1分
最后登录:2021-07-20
在线时长:22小时1分
- 粉丝6
- 金钱1215
- 威望50
- 积分1935