mPDF(PHP)中的水印无法正常工作

时间:2014-11-05 20:49:05

标签: php watermark mpdf

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

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

但它工作错误,因为它没有清晰地设置水印(就像我将设置watermarkTextAlpha = 1,重叠在主文本上)。但在其他脚本(有点不同)中它运作良好。

2 个答案:

答案 0 :(得分:7)

这是代码。

试试这段代码:

$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'],


        ]
    ]);

答案 1 :(得分:1)

mPdf Watermark的工作代码

试试这个

$mpdf=new mPDF(); 
$mpdf=new mPDF('win-1252','A4','','',20,15,48,25,10,10); 
$mpdf->useOnlyCoreFonts = true;    // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("Sanros Trading Co. - Invoice");
$mpdf->SetAuthor("Sanros Trading Co.");
$mpdf->SetWatermarkText("Sanros");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');
相关问题