Watermark in mPDF(PHP) not working correctly

守給你的承諾、 提交于 2019-12-25 01:23:41

问题


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;
    }

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.


回答1:


Here is the code .

Try this code:

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


        ]
    ]);



回答2:


Working code for mPdf Watermark

Try this

$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');


来源:https://stackoverflow.com/questions/26766814/watermark-in-mpdfphp-not-working-correctly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!