mPDF(PHP)中的水印无法正常工作 [英] Watermark in mPDF(PHP) not working correctly

查看:383
本文介绍了mPDF(PHP)中的水印无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用mPDF的php脚本有一个奇怪的问题.我从HTML生成PDF文件,我想在每个页面上设置水印.因此,我正在尝试使用手册中的方法:

I have a strange problem with my php script using mPDF. I generate PDF file from HTML and I want to set watermark on each page. So I'm trying like in the manual:

  if($_REQUEST['WATERMARK']==1){
        $mpdf->SetWatermarkText('draft');
        $mpdf->showWatermarkText = true;
        $mpdf->watermarkTextAlpha= 0.4;
    }

,但是它工作不正确,因为它使我无法清楚地设置水印(例如我将watermarkTextAlpha = 1设置为与主文本重叠).但是在其他脚本中(略有不同),效果很好.

but it's working wrong because it set me watermark without clarity (like I will set watermarkTextAlpha= 1, overlaps on main text). But in other script (a little different) it works good.

推荐答案

下面是代码.

尝试此代码:

$pdf = new Pdf([
        // set to use core fonts only
        'mode' => Pdf::MODE_UTF8, 
        // A4 paper format
        'format' => Pdf::FORMAT_A4, 
        // portrait orientation
        'orientation' => Pdf::ORIENT_LANDSCAPE, 
        // stream to browser inline
        'destination' => $destination,
        'filename'=>  'Sales_invoice/'.$model->invoice_no.'_'.$copy_text.'.pdf',
        // 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' => 'Company-Profile',

                     'showWatermarkText'=>true,
            ],

         // call mPDF methods on the fly
        'methods' => [ 
            'SetHeader'=>['<div class=col-md-12 >'
                .'<div class=col-md-6  style=margin-top:-30px>'

                .'</div><div class=col-md-6  style=margin-top:-15px><p></p></div>'], 
            'SetFooter'=>['{PAGENO}'],
            'SetWatermarkText'=>['Draft'],


        ]
    ]);

这篇关于mPDF(PHP)中的水印无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆